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(goal): continue the goal conversation from the result page (#20388)

Arvin Xu4c48701750cd
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 87a9b38de07..be7f6a176a8 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -866,6 +866,8 @@
"goalProcess.result.deliverables.titleWithCount": "Deliverables · {{count}}",
"goalProcess.result.deliverables.uncited": "Not cited by acceptance evidence",
"goalProcess.result.deliverables.viewAll": "Review all {{count}}",
+ "goalProcess.result.followUp.placeholder": "Ask about this result, or what to do next…",
+ "goalProcess.result.followUp.send": "Send to the goal conversation",
"goalProcess.result.gate.error": "Could not save the decision. Try again.",
"goalProcess.result.gate.prompt": "Check which criteria were not met below, then retry or end the Goal.",
"goalProcess.result.gate.revising": "You chose to retry. The Agent is revising the result; it will be accepted again when done.",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 712f55e90dc..9dc3da6c2eb 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -866,6 +866,8 @@
"goalProcess.result.deliverables.titleWithCount": "交付物 · {{count}}",
"goalProcess.result.deliverables.uncited": "未被验收证据引用",
"goalProcess.result.deliverables.viewAll": "逐一查看全部 {{count}} 项",
+ "goalProcess.result.followUp.placeholder": "就这个结果追问,或说说下一步想做什么…",
+ "goalProcess.result.followUp.send": "发送到目标对话",
"goalProcess.result.gate.error": "决定没有保存成功,请重试。",
"goalProcess.result.gate.prompt": "先看下方哪些标准没有达成,再决定重试还是结束目标。",
"goalProcess.result.gate.revising": "你选择了重试,Agent 正在修改,改完后会重新验收。",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index 151814fd446..f128edeee71 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -2115,6 +2115,8 @@ export default {
'goalProcess.planning.title': 'Planning the exploration',
'goalProcess.planning.description':
'The coordinator is breaking the goal into executable tasks — they will appear here shortly.',
+ 'goalProcess.result.followUp.placeholder': 'Ask about this result, or what to do next…',
+ 'goalProcess.result.followUp.send': 'Send to the goal conversation',
'goalProcess.tag.needsDecision': 'Needs your decision',
'goalProcess.acceptance.repairing': 'Repairing',
'goalProcess.acceptance.verifying': 'Verifying',
diff --git a/src/features/AgentGoals/GoalChat/GoalConversationInput.test.tsx b/src/features/AgentGoals/GoalChat/GoalConversationInput.test.tsx
new file mode 100644
index 00000000000..541cdd5410a
--- /dev/null
+++ b/src/features/AgentGoals/GoalChat/GoalConversationInput.test.tsx
@@ -0,0 +1,119 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import { act, render, screen } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import GoalConversationInput from './GoalConversationInput';
+
+const state = vi.hoisted(() => ({
+ configLoading: false,
+ fillInputMessage: vi.fn(),
+ heterogeneous: false,
+ sendMessage: vi.fn(),
+}));
+
+const conversation = vi.hoisted(() => ({ store: undefined as any }));
+
+vi.mock('@/features/Conversation', async () => {
+ const { create } = await import('zustand');
+ conversation.store = create(() => ({
+ editor: null as unknown,
+ fillInputMessage: state.fillInputMessage,
+ messagesInit: false,
+ sendMessage: state.sendMessage,
+ }));
+ return {
+ ChatInput: () => <div data-testid="chat-input" />,
+ conversationSelectors: {
+ agentId: () => 'agt_1',
+ messagesInit: (s: { messagesInit: boolean }) => s.messagesInit,
+ },
+ useConversationStore: conversation.store,
+ };
+});
+
+vi.mock('@/routes/(main)/agent/features/Conversation/HeterogeneousChatInput', () => ({
+ default: () => <div data-testid="hetero-input" />,
+}));
+
+vi.mock('@/store/agent', () => ({
+ useAgentStore: (selector: (s: unknown) => unknown) => selector({}),
+}));
+
+vi.mock('@/store/agent/selectors', () => ({
+ agentByIdSelectors: {
+ isAgentConfigLoadingById: () => () => state.configLoading,
+ isAgentHeterogeneousById: () => () => state.heterogeneous,
+ },
+}));
+
+beforeEach(() => {
+ state.configLoading = false;
+ state.heterogeneous = false;
+ state.fillInputMessage.mockReset();
+ state.sendMessage.mockReset();
+ conversation.store.setState({ editor: null, messagesInit: false });
+});
+
+describe('GoalConversationInput', () => {
+ // A Claude Code / Codex goal agent needs its runtime and device controls, so
+ // the panel uses the same heterogeneous composer as the agent's own chat.
+ it('renders the heterogeneous composer for a heterogeneous agent', () => {
+ state.heterogeneous = true;
+ render(<GoalConversationInput />);
+
+ expect(screen.getByTestId('hetero-input')).toBeTruthy();
+ expect(screen.queryByTestId('chat-input')).toBeNull();
+ });
+
+ it('sends the handed-off message once, only after the history has loaded', () => {
+ const onSent = vi.fn();
+ render(
+ <GoalConversationInput initialMessage={'what next?'} onInitialMessageConsumed={onSent} />,
+ );
+ expect(state.sendMessage).not.toHaveBeenCalled();
+
+ act(() => conversation.store.setState({ messagesInit: true }));
+ act(() => conversation.store.setState({ messagesInit: false }));
+ act(() => conversation.store.setState({ messagesInit: true }));
+
+ expect(state.sendMessage).toHaveBeenCalledTimes(1);
+ expect(state.sendMessage).toHaveBeenCalledWith({ message: 'what next?' });
+ // The host is told, so a later remount of the panel gets no message to resend.
+ expect(onSent).toHaveBeenCalledTimes(1);
+ expect(screen.getByTestId('chat-input')).toBeTruthy();
+ });
+
+ // The heterogeneous composer gates sending on API binding, execution target
+ // and device state; the hand-off must go through it rather than around it.
+ it('fills a heterogeneous agent’s composer instead of sending around its guards', () => {
+ state.heterogeneous = true;
+ const onConsumed = vi.fn();
+ render(
+ <GoalConversationInput initialMessage={'what next?'} onInitialMessageConsumed={onConsumed} />,
+ );
+
+ act(() => conversation.store.setState({ messagesInit: true }));
+ expect(state.fillInputMessage).not.toHaveBeenCalled();
+
+ act(() => conversation.store.setState({ editor: {} }));
+
+ expect(state.fillInputMessage).toHaveBeenCalledWith('what next?');
+ expect(state.sendMessage).not.toHaveBeenCalled();
+ expect(onConsumed).toHaveBeenCalledTimes(1);
+ });
+
+ it('waits for the agent config before choosing how to hand off', () => {
+ state.configLoading = true;
+ conversation.store.setState({ messagesInit: true });
+ const { rerender } = render(<GoalConversationInput initialMessage={'what next?'} />);
+ expect(state.sendMessage).not.toHaveBeenCalled();
+
+ state.configLoading = false;
+ rerender(
+ <GoalConversationInput initialMessage={'what next?'} onInitialMessageConsumed={vi.fn()} />,
+ );
+ expect(state.sendMessage).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/src/features/AgentGoals/GoalChat/GoalConversationInput.tsx b/src/features/AgentGoals/GoalChat/GoalConversationInput.tsx
new file mode 100644
index 00000000000..99a9697eb62
--- /dev/null
+++ b/src/features/AgentGoals/GoalChat/GoalConversationInput.tsx
@@ -0,0 +1,93 @@
+'use client';
+
+import { memo, useEffect, useRef } from 'react';
+
+import { type ActionKeys } from '@/features/ChatInput';
+import { ChatInput, conversationSelectors, useConversationStore } from '@/features/Conversation';
+import HeterogeneousChatInput from '@/routes/(main)/agent/features/Conversation/HeterogeneousChatInput';
+import { useAgentStore } from '@/store/agent';
+import { agentByIdSelectors } from '@/store/agent/selectors';
+
+const LEFT_ACTIONS: ActionKeys[] = ['plus', 'voiceDictation'];
+const RIGHT_ACTIONS: ActionKeys[] = ['model', 'contextWindow'];
+
+interface GoalConversationInputProps {
+ /**
+ * Handed over once the conversation is ready — the result page's composer
+ * passes its text to the panel this way. A standard agent sends it right
+ * away; a heterogeneous one gets it filled into its composer instead.
+ */
+ initialMessage?: string;
+ /** Called once the handed-off message is sent or filled in, so the host can drop it. */
+ onInitialMessageConsumed?: () => void;
+}
+
+/**
+ * The composer under both goal-page conversations, the supervision record and
+ * the side chat. It is the agent's own full input, not a trimmed strip: the goal
+ * agent is often a heterogeneous one (Claude Code, Codex), whose runtime,
+ * device and working directory controls live in this bar — the same choice the
+ * side-by-side topic portal makes.
+ */
+const GoalConversationInput = memo<GoalConversationInputProps>(
+ ({ initialMessage, onInitialMessageConsumed }) => {
+ const agentId = useConversationStore(conversationSelectors.agentId);
+ const isHeterogeneous = useAgentStore(agentByIdSelectors.isAgentHeterogeneousById(agentId));
+ const isConfigLoading = useAgentStore(agentByIdSelectors.isAgentConfigLoadingById(agentId));
+ const messagesInit = useConversationStore(conversationSelectors.messagesInit);
+ const sendMessage = useConversationStore((s) => s.sendMessage);
+ const fillInputMessage = useConversationStore((s) => s.fillInputMessage);
+ const editor = useConversationStore((s) => s.editor);
+
+ // Waiting for the history keeps the hand-off from racing the first fetch: a
+ // send while the list is still loading would go out without the record it
+ // continues. Waiting for the agent config keeps a heterogeneous agent from
+ // being mistaken for a standard one while it hydrates.
+ //
+ // A heterogeneous agent's composer gates sending on readiness it alone
+ // knows — API binding, execution target, device online — so the message is
+ // filled in for it to send rather than dispatched around those guards.
+ //
+ // The ref covers StrictMode's replayed effect within one mount; across
+ // remounts the host has already dropped the message via the callback.
+ const handedOffRef = useRef(false);
+ useEffect(() => {
+ if (!initialMessage || !messagesInit || isConfigLoading || handedOffRef.current) return;
+ if (isHeterogeneous) {
+ if (!editor) return;
+ handedOffRef.current = true;
+ onInitialMessageConsumed?.();
+ fillInputMessage(initialMessage);
+ return;
+ }
+ handedOffRef.current = true;
+ onInitialMessageConsumed?.();
+ void sendMessage({ message: initialMessage });
+ }, [
+ editor,
+ fillInputMessage,
+ initialMessage,
+ isConfigLoading,
+ isHeterogeneous,
+ messagesInit,
+ onInitialMessageConsumed,
+ sendMessage,
+ ]);
+
+ if (isHeterogeneous) return <HeterogeneousChatInput />;
+
+ return (
+ <ChatInput
+ skipScrollMarginWithList
+ isConfigLoading={isConfigLoading}
+ leftActions={LEFT_ACTIONS}
+ rightActions={RIGHT_ACTIONS}
+ sendButtonProps={{ shape: 'round' }}
+ />
+ );
+ },
+);
+
+GoalConversationInput.displayName = 'GoalConversationInput';
+
+export default GoalConversationInput;
diff --git a/src/features/AgentGoals/GoalChat/index.tsx b/src/features/AgentGoals/GoalChat/index.tsx
index 7d6bab26d46..9d598ec9a9f 100644
--- a/src/features/AgentGoals/GoalChat/index.tsx
+++ b/src/features/AgentGoals/GoalChat/index.tsx
@@ -6,24 +6,14 @@ import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import DragUploadZone, { useUploadFiles } from '@/components/DragUploadZone';
-import {
- COMPACT_ACTION_BAR_STYLE,
- COMPACT_SEND_BUTTON_PROPS,
-} from '@/features/ChatInput/compactPreset';
-import {
- ChatInput,
- ChatList,
- conversationSelectors,
- useConversationStore,
-} from '@/features/Conversation';
+import { ChatList, conversationSelectors, useConversationStore } from '@/features/Conversation';
import { useAgentStore } from '@/store/agent';
import { agentByIdSelectors } from '@/store/agent/selectors';
import { GoalChatProvider } from './GoalChatProvider';
+import GoalConversationInput from './GoalConversationInput';
import Toolbar from './Toolbar';
-const EMPTY_LEFT_ACTIONS: [] = [];
-
const Welcome = memo(() => {
const { t } = useTranslation('chat');
return (
@@ -37,44 +27,52 @@ const Welcome = memo(() => {
Welcome.displayName = 'GoalChatWelcome';
-const Conversation = memo<{ onCollapse: () => void }>(({ onCollapse }) => {
- const useFetchAgentConfig = useAgentStore((s) => s.useFetchAgentConfig);
- const currentAgentId = useConversationStore(conversationSelectors.agentId);
+interface ConversationProps {
+ initialMessage?: string;
+ onCollapse: () => void;
+ onInitialMessageConsumed?: () => void;
+}
- useFetchAgentConfig(true, currentAgentId);
+const Conversation = memo<ConversationProps>(
+ ({ initialMessage, onCollapse, onInitialMessageConsumed }) => {
+ const useFetchAgentConfig = useAgentStore((s) => s.useFetchAgentConfig);
+ const currentAgentId = useConversationStore(conversationSelectors.agentId);
- const model = useAgentStore((s) => agentByIdSelectors.getAgentModelById(currentAgentId)(s));
- const provider = useAgentStore((s) =>
- agentByIdSelectors.getAgentModelProviderById(currentAgentId)(s),
- );
- const { handleUploadFiles } = useUploadFiles({ agentId: currentAgentId, model, provider });
+ useFetchAgentConfig(true, currentAgentId);
- return (
- <DragUploadZone style={{ flex: 1, height: '100%' }} onUploadFiles={handleUploadFiles}>
- <Flexbox flex={1} height={'100%'} style={{ overflow: 'hidden' }}>
- <Toolbar onCollapse={onCollapse} />
- <Flexbox flex={1} style={{ overflow: 'hidden' }}>
- <ChatList welcome={<Welcome />} />
+ const model = useAgentStore((s) => agentByIdSelectors.getAgentModelById(currentAgentId)(s));
+ const provider = useAgentStore((s) =>
+ agentByIdSelectors.getAgentModelProviderById(currentAgentId)(s),
+ );
+ const { handleUploadFiles } = useUploadFiles({ agentId: currentAgentId, model, provider });
+
+ return (
+ <DragUploadZone style={{ flex: 1, height: '100%' }} onUploadFiles={handleUploadFiles}>
+ <Flexbox flex={1} height={'100%'} style={{ overflow: 'hidden' }}>
+ <Toolbar onCollapse={onCollapse} />
+ <Flexbox flex={1} style={{ overflow: 'hidden' }}>
+ <ChatList welcome={<Welcome />} />
+ </Flexbox>
+ <GoalConversationInput
+ initialMessage={initialMessage}
+ onInitialMessageConsumed={onInitialMessageConsumed}
+ />
</Flexbox>
- <ChatInput
- actionBarStyle={COMPACT_ACTION_BAR_STYLE}
- allowExpand={false}
- leftActions={EMPTY_LEFT_ACTIONS}
- sendButtonProps={COMPACT_SEND_BUTTON_PROPS}
- showControlBar={false}
- />
- </Flexbox>
- </DragUploadZone>
- );
-});
+ </DragUploadZone>
+ );
+ },
+);
Conversation.displayName = 'GoalChatConversation';
interface GoalChatProps {
agentId: string;
goalId: string;
+ /** Sent on mount — the result page's composer hands its text over this way. */
+ initialMessage?: string;
initialTopicId?: string;
onCollapse: () => void;
+ onInitialMessageConsumed?: () => void;
}
/**
@@ -82,11 +80,17 @@ interface GoalChatProps {
* provider tags the context with `viewedGoal`, so every question is answered
* with the current goal overview injected — "how is this going?" just works.
*/
-const GoalChat = memo<GoalChatProps>(({ agentId, goalId, initialTopicId, onCollapse }) => (
- <GoalChatProvider agentId={agentId} goalId={goalId} initialTopicId={initialTopicId}>
- <Conversation onCollapse={onCollapse} />
- </GoalChatProvider>
-));
+const GoalChat = memo<GoalChatProps>(
+ ({ agentId, goalId, initialMessage, initialTopicId, onCollapse, onInitialMessageConsumed }) => (
+ <GoalChatProvider agentId={agentId} goalId={goalId} initialTopicId={initialTopicId}>
+ <Conversation
+ initialMessage={initialMessage}
+ onCollapse={onCollapse}
+ onInitialMessageConsumed={onInitialMessageConsumed}
+ />
+ </GoalChatProvider>
+ ),
+);
GoalChat.displayName = 'GoalChat';
diff --git a/src/features/AgentGoals/GoalDetailPage.test.tsx b/src/features/AgentGoals/GoalDetailPage.test.tsx
index 5dc1f9c2536..8d69619e47f 100644
--- a/src/features/AgentGoals/GoalDetailPage.test.tsx
+++ b/src/features/AgentGoals/GoalDetailPage.test.tsx
@@ -9,7 +9,7 @@ import { WorkspaceSidePanelProvider } from '@/features/RightPanel/WorkspaceSideP
import GoalDetailPage from './GoalDetailPage';
-const mocks = vi.hoisted(() => ({ hasSupervision: true, showPortal: false }));
+const mocks = vi.hoisted(() => ({ canEdit: true, hasSupervision: true, showPortal: false }));
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
@@ -57,7 +57,7 @@ vi.mock('@/store/global/selectors', () => ({
systemStatusSelectors: { showLeftPanel: () => false },
}));
-vi.mock('@/hooks/usePermission', () => ({ usePermission: () => ({ allowed: true }) }));
+vi.mock('@/hooks/usePermission', () => ({ usePermission: () => ({ allowed: mocks.canEdit }) }));
vi.mock('@/features/Portal/usePortalPanelWidth', () => ({
usePortalPanelWidth: () => ({ maxWidth: 800, minWidth: 300, updateWidth: vi.fn(), width: 400 }),
@@ -100,18 +100,35 @@ vi.mock('@/features/WideScreenContainer', () => ({
default: ({ children }: { children: ReactNode }) => <div>{children}</div>,
}));
vi.mock('./GoalChat', () => ({
- default: ({ agentId }: { agentId: string }) => (
- <div data-agent-id={agentId} data-testid="goal-chat" />
+ default: ({ agentId, initialMessage }: { agentId: string; initialMessage?: string }) => (
+ <div data-agent-id={agentId} data-initial-message={initialMessage} data-testid="goal-chat" />
),
}));
vi.mock('./GoalDetailActions', () => ({ default: () => null }));
vi.mock('./GoalHeaderMetrics', () => ({ default: () => null }));
vi.mock('./GoalRequirement', () => ({ default: () => null }));
vi.mock('./NorthStarMetrics', () => ({ default: () => null }));
-vi.mock('./ProcessControl', () => ({ default: () => null }));
+// The result page's composer lives inside ProcessControl; the page owns where
+// its message goes, so the stub only exposes the hand-off.
+vi.mock('./ProcessControl', () => ({
+ default: ({ onFollowUp }: { onFollowUp?: (message: string) => void }) =>
+ onFollowUp ? (
+ <button data-testid="goal-follow-up" onClick={() => onFollowUp('what next?')}>
+ follow up
+ </button>
+ ) : null,
+}));
vi.mock('./GoalSupervision', () => ({
- GoalSupervision: ({ onOpenChat, topicId }: { onOpenChat?: () => void; topicId: string }) => (
- <div data-testid="goal-supervision">
+ GoalSupervision: ({
+ initialMessage,
+ onOpenChat,
+ topicId,
+ }: {
+ initialMessage?: string;
+ onOpenChat?: () => void;
+ topicId: string;
+ }) => (
+ <div data-initial-message={initialMessage} data-testid="goal-supervision">
{topicId}
{onOpenChat && (
<button data-testid="goal-supervision-open-chat" onClick={onOpenChat}>
@@ -124,6 +141,7 @@ vi.mock('./GoalSupervision', () => ({
describe('GoalDetailPage', () => {
beforeEach(() => {
+ mocks.canEdit = true;
mocks.hasSupervision = true;
mocks.showPortal = false;
});
@@ -161,9 +179,40 @@ describe('GoalDetailPage', () => {
expect(screen.getByTestId('goal-right-panel')).toHaveAttribute('data-expand', 'true');
});
- // The record is read-only, so a goal that has one must keep a route back to the
- // editable conversation — otherwise consolidating the header's two controls
- // would have removed the only way to ask the goal's agent anything.
+ // The result page's composer talks to the same conversation the header opens:
+ // the supervision record when the goal has one, the side chat otherwise.
+ it('sends a result follow-up into the supervision record when the goal has one', () => {
+ render(<GoalDetailPage agentId={'agt_manager'} goalId={'goal_1'} />);
+
+ fireEvent.click(screen.getByTestId('goal-follow-up'));
+
+ expect(screen.getByTestId('goal-supervision')).toHaveAttribute(
+ 'data-initial-message',
+ 'what next?',
+ );
+ expect(screen.getByTestId('goal-right-panel')).toHaveAttribute('data-expand', 'true');
+ });
+
+ it('sends a result follow-up into the side chat when the goal has no record', () => {
+ mocks.hasSupervision = false;
+ render(<GoalDetailPage agentId={'agt_manager'} goalId={'goal_1'} />);
+
+ fireEvent.click(screen.getByTestId('goal-follow-up'));
+
+ expect(screen.getByTestId('goal-chat')).toHaveAttribute('data-initial-message', 'what next?');
+ });
+
+ // A viewer can read the result but the backend would reject their turn, so
+ // the page offers no composer rather than one that fails on send.
+ it('offers no result follow-up to someone who cannot create content', () => {
+ mocks.canEdit = false;
+ render(<GoalDetailPage agentId={'agt_manager'} goalId={'goal_1'} />);
+
+ expect(screen.queryByTestId('goal-follow-up')).not.toBeInTheDocument();
+ });
+
+ // The side chat stays one menu item away, for a question that should not land
+ // in the manager's own record.
it('hands a managed goal back to its editable conversation from the record', () => {
render(<GoalDetailPage agentId={'agt_manager'} goalId={'goal_1'} />);
diff --git a/src/features/AgentGoals/GoalDetailPage.tsx b/src/features/AgentGoals/GoalDetailPage.tsx
index a3d401514f8..74c20f45db7 100644
--- a/src/features/AgentGoals/GoalDetailPage.tsx
+++ b/src/features/AgentGoals/GoalDetailPage.tsx
@@ -161,11 +161,15 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {
* Re-targeting only when the destination is not already the open one keeps a
* reopen from bumping the request and remounting the panel.
*/
+ const panelTarget = managerConversation
+ ? { agentId: managerConversation.agentId, topicId: managerConversation.topicId }
+ : supervisingAgentId
+ ? { agentId: supervisingAgentId, topicId: undefined }
+ : undefined;
+
const openPanel = () => {
- if (!supervisingAgentId) return;
- const target = managerConversation
- ? { agentId: managerConversation.agentId, topicId: managerConversation.topicId }
- : { agentId: supervisingAgentId, topicId: undefined };
+ const target = panelTarget;
+ if (!target) return;
if (chat.topicId !== target.topicId) {
clearPortalStack();
chat.openConversation(target);
@@ -264,6 +268,18 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {
goalId={goal.id}
graphFullscreen={graphFullscreen}
onGraphFullscreenChange={setGraphFullscreen}
+ onFollowUp={
+ // Viewers can read the result but not talk to its agent; the
+ // backend would reject the turn, so they get no composer.
+ canEdit && panelTarget
+ ? (message) => {
+ // Same destination as the header entry — the supervision record
+ // when there is one — and it replaces any open drill-down.
+ clearPortalStack();
+ chat.openConversation({ ...panelTarget, initialMessage: message });
+ }
+ : undefined
+ }
/>
</WideScreenContainer>
</Flexbox>
@@ -299,20 +315,23 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {
<GoalSupervision
agentId={supervisingAgentId}
goalId={goalId}
+ initialMessage={chat.initialMessage}
key={`${goalId}:${supervisingAgentId}:${chat.request}`}
topicId={chat.topicId}
onCollapse={() => chat.setOpen(false)}
- // The record is read-only and the avatar is the panel's only entry, so
- // this is how a goal with a record gets back to an editable chat.
+ onInitialMessageConsumed={chat.consumeInitialMessage}
+ // A question that should not land in the manager's own record.
onOpenChat={() => chat.openConversation({ agentId: supervisingAgentId })}
/>
) : supervisingAgentId ? (
<GoalChat
agentId={supervisingAgentId}
goalId={goalId}
+ initialMessage={chat.initialMessage}
initialTopicId={chat.topicId}
key={`${goalId}:${supervisingAgentId}:${chat.request}`}
onCollapse={() => chat.setOpen(false)}
+ onInitialMessageConsumed={chat.consumeInitialMessage}
/>
) : null}
</RightPanel>
diff --git a/src/features/AgentGoals/GoalSupervision.tsx b/src/features/AgentGoals/GoalSupervision.tsx
index d1fc26df063..de65f55f598 100644
--- a/src/features/AgentGoals/GoalSupervision.tsx
+++ b/src/features/AgentGoals/GoalSupervision.tsx
@@ -21,11 +21,15 @@ import { useAgentStore } from '@/store/agent';
import { agentSelectors } from '@/store/agent/selectors';
import { GoalChatProvider } from './GoalChat/GoalChatProvider';
+import GoalConversationInput from './GoalChat/GoalConversationInput';
interface GoalSupervisionProps {
agentId: string;
goalId: string;
+ /** Sent into the record once it loads — the result page's composer hands off this way. */
+ initialMessage?: string;
onCollapse: () => void;
+ onInitialMessageConsumed?: () => void;
/** Hand the panel back to the agent's editable side conversation. */
onOpenChat?: () => void;
topicId: string;
@@ -48,11 +52,18 @@ const WaitingForFirstRun = memo(() => {
WaitingForFirstRun.displayName = 'GoalSupervisionWaiting';
-/** The manager's ongoing record is inspectable without sending or editing messages. */
+/**
+ * The manager's ongoing record, and the place to talk to it. Past turns stay
+ * read-only — editing one would rewrite what the manager acted on — but the
+ * conversation itself continues here, so the reader never has to leave the goal
+ * to answer a question the manager asked in it.
+ */
export const GoalSupervision = ({
agentId,
goalId,
+ initialMessage,
onCollapse,
+ onInitialMessageConsumed,
onOpenChat,
topicId,
}: GoalSupervisionProps) => {
@@ -62,21 +73,19 @@ export const GoalSupervision = ({
const agentTitle = useAgentStore((s) =>
agentDisplayName(agentSelectors.getAgentMetaById(agentId)(s)),
);
- // Stable renderer for the virtualized history; disable message editing too,
- // rather than only removing the composer below the list.
+ // Stable renderer for the virtualized history; past turns are not editable.
const itemContent = useCallback(
(index: number, id: string) => <MessageItem disableEditing id={id} index={index} />,
[],
);
const navigate = useWorkspaceAwareNavigate();
- // This panel is a read-only view of the manager's conversation. Opening it in
- // the agent's own chat is how you continue it; the id is one click away for
- // referencing it elsewhere (`lh topic view`, a bug report), like a task run's.
+ // Opening the record in the agent's own chat gives it the full page; the id is
+ // one click away for referencing it elsewhere (`lh topic view`, a bug report),
+ // like a task run's.
const menuItems = useMemo<DropdownItem[]>(
() => [
- // The record is read-only and the avatar is the panel's only entry, so the
- // way back to an editable conversation has to live here — otherwise a goal
- // with a record would have no route to asking its agent anything.
+ // A fresh side conversation, for a question that should not land in the
+ // manager's own record.
...(onOpenChat
? [
{
@@ -131,6 +140,10 @@ export const GoalSupervision = ({
<Flexbox flex={1} style={{ minHeight: 0, overflow: 'hidden' }}>
<ChatList disableActionsBar itemContent={itemContent} welcome={<WaitingForFirstRun />} />
</Flexbox>
+ <GoalConversationInput
+ initialMessage={initialMessage}
+ onInitialMessageConsumed={onInitialMessageConsumed}
+ />
</Flexbox>
</GoalChatProvider>
);
diff --git a/src/features/AgentGoals/ProcessControl/GoalFollowUpComposer.tsx b/src/features/AgentGoals/ProcessControl/GoalFollowUpComposer.tsx
new file mode 100644
index 00000000000..714022ec95e
--- /dev/null
+++ b/src/features/AgentGoals/ProcessControl/GoalFollowUpComposer.tsx
@@ -0,0 +1,106 @@
+'use client';
+
+import { ChatInput, ChatInputActionBar, SendButton, useEditor } from '@lobehub/editor/react';
+import { createStaticStyles, cssVar } from 'antd-style';
+import { $getRoot } from 'lexical';
+import { memo, useCallback, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { EditorCanvas } from '@/features/EditorCanvas';
+import { useEnterToSend } from '@/hooks/useEnterToSend';
+
+/**
+ * The result page's closing move: ask the goal's agent about what was just
+ * delivered without hunting for the panel toggle. It owns no conversation of
+ * its own — the text is handed to the host, which opens the goal conversation
+ * beside the page and sends it there, so the reply lands where every other
+ * question about this goal already lives.
+ */
+
+const styles = createStaticStyles(({ css }) => ({
+ // Pinned to the bottom of the page's scroll area, over a fade so the result
+ // text scrolling underneath never collides with the box.
+ dock: css`
+ position: sticky;
+ z-index: 1;
+ inset-block-end: 0;
+
+ padding-block: 24px 16px;
+
+ background: linear-gradient(to bottom, transparent, ${cssVar.colorBgLayout} 24px);
+ `,
+}));
+
+interface GoalFollowUpComposerProps {
+ /** Hidden rather than unmounted, so the draft outlives a tab switch. */
+ hidden?: boolean;
+ onSend: (message: string) => void;
+}
+
+const GoalFollowUpComposer = memo<GoalFollowUpComposerProps>(({ hidden, onSend }) => {
+ const { t } = useTranslation('chat');
+ const editor = useEditor();
+ const [hasContent, setHasContent] = useState(false);
+ const shouldSendOnEnter = useEnterToSend();
+
+ const handleContentChange = useCallback(() => {
+ editor
+ ?.getLexicalEditor?.()
+ ?.getEditorState()
+ .read(() => setHasContent($getRoot().getTextContent().trim().length > 0));
+ }, [editor]);
+
+ const handleSubmit = useCallback(() => {
+ const message = String(editor?.getDocument?.('markdown') ?? '').trim();
+ if (!message) return;
+ editor?.cleanDocument?.();
+ setHasContent(false);
+ onSend(message);
+ }, [editor, onSend]);
+
+ return (
+ // The dock itself carries `hidden`: a wrapper would become the sticky
+ // element's containing block and unpin it from the page bottom.
+ <div className={styles.dock} hidden={hidden}>
+ <ChatInput
+ maxHeight={200}
+ minHeight={48}
+ footer={
+ <ChatInputActionBar
+ // The bar spreads `left` and `right` apart; without a left slot the
+ // send button would sit on the left edge.
+ left={<span />}
+ style={{ paddingInline: 8 }}
+ right={
+ <SendButton
+ disabled={!hasContent}
+ shape={'round'}
+ title={t('goalProcess.result.followUp.send')}
+ type={'primary'}
+ onClick={handleSubmit}
+ />
+ }
+ />
+ }
+ >
+ <EditorCanvas
+ editor={editor}
+ floatingToolbar={false}
+ placeholder={t('goalProcess.result.followUp.placeholder')}
+ style={{ paddingBlock: 0 }}
+ onContentChange={handleContentChange}
+ onPressEnter={({ event }) => {
+ if (shouldSendOnEnter(event)) {
+ handleSubmit();
+ return true;
+ }
+ }}
+ />
+ </ChatInput>
+ </div>
+ );
+});
+
+GoalFollowUpComposer.displayName = 'GoalFollowUpComposer';
+
+export default GoalFollowUpComposer;
diff --git a/src/features/AgentGoals/ProcessControl/GoalResultTabs.tsx b/src/features/AgentGoals/ProcessControl/GoalResultTabs.tsx
index 82b5f716a7a..753bdcaace3 100644
--- a/src/features/AgentGoals/ProcessControl/GoalResultTabs.tsx
+++ b/src/features/AgentGoals/ProcessControl/GoalResultTabs.tsx
@@ -6,6 +6,7 @@ import type { ReactNode } from 'react';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
+import GoalFollowUpComposer from './GoalFollowUpComposer';
import type { GoalGraphView } from './goalGraphViewModel';
import GoalResult from './GoalResult';
import { hasGoalResult } from './goalResultState';
@@ -22,12 +23,14 @@ type GoalTab = 'process' | 'result';
interface GoalResultTabsProps {
graph: GoalGraphView;
+ /** Hands a question about the result to the goal's conversation; absent hides the composer. */
+ onFollowUp?: (message: string) => void;
onSelect: (nodeId: string) => void;
/** The 执行过程 content — the whole process view the host already renders. */
process: ReactNode;
}
-const GoalResultTabs = ({ graph, onSelect, process }: GoalResultTabsProps) => {
+const GoalResultTabs = ({ graph, onFollowUp, onSelect, process }: GoalResultTabsProps) => {
const { t } = useTranslation('chat');
const [tab, setTab] = useState<GoalTab>('result');
@@ -48,6 +51,9 @@ const GoalResultTabs = ({ graph, onSelect, process }: GoalResultTabsProps) => {
{/* Only the active tab mounts: the exploration map measures its box on
mount and would lay out against a hidden panel. */}
{tab === 'result' ? <GoalResult graph={graph} onSelect={onSelect} /> : process}
+ {/* Kept mounted across tabs so a half-written follow-up survives a look
+ at the process; it only shows under the result. */}
+ {onFollowUp && <GoalFollowUpComposer hidden={tab !== 'result'} onSend={onFollowUp} />}
</Flexbox>
);
};
diff --git a/src/features/AgentGoals/ProcessControl/ResultTrail.test.tsx b/src/features/AgentGoals/ProcessControl/ResultTrail.test.tsx
index 2edea68681b..36a3aad97c2 100644
--- a/src/features/AgentGoals/ProcessControl/ResultTrail.test.tsx
+++ b/src/features/AgentGoals/ProcessControl/ResultTrail.test.tsx
@@ -165,6 +165,24 @@ describe('ResultTrail', () => {
expect(chatState.openGoalReportChapter).toHaveBeenCalledWith('goal-1', 0);
});
+ // A conclusion opens beside the page instead of unfolding into the trail, in
+ // both the storyline and the derived trail.
+ it('opens a finding in the side panel instead of expanding it inline', () => {
+ const finding = { ...graph().byId['Sources agree'] };
+ (finding.node as { description?: string }).description = 'Three sources agree on the date.';
+
+ for (const snapshot of [graph({ latest, status: 'completed' }), graph()]) {
+ const onSelect = vi.fn();
+ const { unmount } = render(<ResultTrail graph={snapshot} onSelect={onSelect} />);
+
+ fireEvent.click(screen.getByRole('button', { name: /Sources agree/ }));
+
+ expect(onSelect).toHaveBeenCalledWith('Sources agree');
+ expect(screen.queryByText('Three sources agree on the date.')).toBeNull();
+ unmount();
+ }
+ });
+
it('opens the full report beside the page', () => {
render(<ResultTrail graph={graph({ latest, status: 'completed' })} onSelect={vi.fn()} />);
diff --git a/src/features/AgentGoals/ProcessControl/ResultTrail.tsx b/src/features/AgentGoals/ProcessControl/ResultTrail.tsx
index 87fca49b8b4..5a3efed3190 100644
--- a/src/features/AgentGoals/ProcessControl/ResultTrail.tsx
+++ b/src/features/AgentGoals/ProcessControl/ResultTrail.tsx
@@ -12,7 +12,7 @@ import {
GitBranch,
type LucideIcon,
} from 'lucide-react';
-import { type ReactNode, useState } from 'react';
+import { type ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import { useEntityMarkdown } from '@/features/EntityLink';
@@ -38,7 +38,7 @@ import { KIND_COLOR, KIND_ICON } from './shared';
*
* Read top-down, one layer at a time: the document above is the answer; each
* stage here is a piece of the way there with the conclusions it reached and
- * the files it wrote; a conclusion expands into its evidence.
+ * the files it wrote; a conclusion opens its evidence beside the page.
*
* Once the wrap-up agent has written the Goal report, the stages are its
* chapters — titled, narrated, and honest about the detours taken, each of
@@ -51,15 +51,6 @@ const styles = createStaticStyles(({ css }) => ({
arrow: css`
flex: none;
color: ${cssVar.colorTextQuaternary};
- transition: transform 0.2s;
- `,
- arrowOpen: css`
- transform: rotate(90deg);
- `,
- /** Aligned with the item title: tile (32) + gap (12) + row padding (12). */
- evidence: css`
- padding-block: 0 12px;
- padding-inline: 56px 12px;
`,
/** One stage's outputs, framed as a single list like the frontier's. */
list: css`
@@ -251,46 +242,32 @@ const TrailItem = ({
</Flexbox>
);
-const TrailFinding = ({ view }: { view: GoalNodeView }) => {
+/**
+ * A conclusion opens beside the page, like every other drill-down here: read
+ * inline, a long finding pushed the rest of the trail off screen and left the
+ * reader scrolling back to find the stage it belonged to.
+ */
+const TrailFinding = ({
+ onOpen,
+ view,
+}: {
+ onOpen: (nodeId: string) => void;
+ view: GoalNodeView;
+}) => {
const { t } = useTranslation('chat');
- const [open, setOpen] = useState(false);
- const markdownProps = useEntityMarkdown();
- const description = view.node.description;
- const summary = summaryOf(description);
+ const summary = summaryOf(view.node.description);
return (
- <div>
- <TrailItem
- icon={KIND_ICON.finding}
- title={view.node.title}
- tone={KIND_COLOR.finding}
- // Expanded, the evidence below already says what the summary said.
- subtitle={
- open
- ? undefined
- : summary
- ? `${t('goalProcess.kind.finding')} · ${summary}`
- : t('goalProcess.kind.finding')
- }
- trailing={
- description ? (
- <Icon
- className={cx(styles.arrow, open && styles.arrowOpen)}
- icon={ChevronRight}
- size={14}
- />
- ) : undefined
- }
- onClick={description ? () => setOpen(!open) : undefined}
- />
- {open && description && (
- <div className={styles.evidence}>
- <Markdown fontSize={13} variant={'chat'} {...markdownProps}>
- {description}
- </Markdown>
- </div>
- )}
- </div>
+ <TrailItem
+ icon={KIND_ICON.finding}
+ title={view.node.title}
+ tone={KIND_COLOR.finding}
+ trailing={<Icon className={styles.arrow} icon={ChevronRight} size={14} />}
+ subtitle={
+ summary ? `${t('goalProcess.kind.finding')} · ${summary}` : t('goalProcess.kind.finding')
+ }
+ onClick={() => onOpen(view.node.id)}
+ />
);
};
@@ -429,7 +406,7 @@ const TrailStep = ({
>
<div className={styles.list}>
{step.findings.map((finding) => (
- <TrailFinding key={finding.node.id} view={finding} />
+ <TrailFinding key={finding.node.id} view={finding} onOpen={onSelect} />
))}
{step.artifacts.map((artifact) => (
<TrailArtifact
@@ -483,12 +460,14 @@ const StoryChapter = ({
goalId,
last,
onOpenArtifact,
+ onSelect,
view,
}: {
documentId?: string;
goalId: string;
last: boolean;
onOpenArtifact: (artifact: GoalArtifactView) => void;
+ onSelect: (nodeId: string) => void;
view: StoryChapterView;
}) => {
const openChapter = useChatStore((s) => s.openGoalReportChapter);
@@ -517,7 +496,7 @@ const StoryChapter = ({
{hasItems && (
<div className={styles.list}>
{view.findings.map((finding) => (
- <TrailFinding key={finding.node.id} view={finding} />
+ <TrailFinding key={finding.node.id} view={finding} onOpen={onSelect} />
))}
{view.artifacts.map((artifact) => (
<TrailArtifact
@@ -622,6 +601,7 @@ const ResultTrail = ({ documentId, graph, onSelect }: ResultTrailProps) => {
last={index === chapters.length - 1}
view={chapter}
onOpenArtifact={openArtifact}
+ onSelect={onSelect}
/>
))}
</Flexbox>
diff --git a/src/features/AgentGoals/ProcessControl/index.tsx b/src/features/AgentGoals/ProcessControl/index.tsx
index 2c0d40e5643..0fee5e6e83b 100644
--- a/src/features/AgentGoals/ProcessControl/index.tsx
+++ b/src/features/AgentGoals/ProcessControl/index.tsx
@@ -39,11 +39,13 @@ interface ProcessControlProps {
goalId: string;
/** Owned by the page so it can swap its portal panel for the overlay's. */
graphFullscreen: boolean;
+ /** Sends a question about the delivered result into the goal's conversation. */
+ onFollowUp?: (message: string) => void;
onGraphFullscreenChange: (fullscreen: boolean) => void;
}
const ProcessControl = memo<ProcessControlProps>(
- ({ goalId, graphFullscreen, onGraphFullscreenChange }) => {
+ ({ goalId, graphFullscreen, onFollowUp, onGraphFullscreenChange }) => {
const { t } = useTranslation('chat');
const { allowed: canEdit } = usePermission('create_content');
const [lastSelectedId, setSelectedId] = useState<string>();
@@ -186,7 +188,15 @@ const ProcessControl = memo<ProcessControlProps>(
</Flexbox>
);
- return <GoalResultTabs graph={graph} key={goalId} process={process} onSelect={select} />;
+ return (
+ <GoalResultTabs
+ graph={graph}
+ key={goalId}
+ process={process}
+ onFollowUp={onFollowUp}
+ onSelect={select}
+ />
+ );
},
);
diff --git a/src/features/AgentGoals/useGoalChatPanel.test.ts b/src/features/AgentGoals/useGoalChatPanel.test.ts
index 2cb7cb2c0b2..e240cff851b 100644
--- a/src/features/AgentGoals/useGoalChatPanel.test.ts
+++ b/src/features/AgentGoals/useGoalChatPanel.test.ts
@@ -34,6 +34,37 @@ describe('useGoalChatPanel', () => {
expect(result.current.topicId).toBeUndefined();
});
+ // The result page's composer hands its text to the panel; a later reopen must
+ // not replay it, so the message rides only the request that carried it.
+ // Folding the panel before the history loads must not lose a message the
+ // result composer has already cleared from its own editor.
+ it('keeps a pending message across folding the panel until it is consumed', () => {
+ const { result } = renderHook(() => useGoalChatPanel('goal-a', 'worker'));
+
+ act(() => result.current.openConversation({ agentId: 'worker', initialMessage: 'next?' }));
+ expect(result.current).toMatchObject({ initialMessage: 'next?', open: true });
+
+ act(() => result.current.setOpen(false));
+ act(() => result.current.setOpen(true));
+ expect(result.current.initialMessage).toBe('next?');
+
+ act(() => result.current.consumeInitialMessage());
+ expect(result.current.initialMessage).toBeUndefined();
+ });
+
+ // The panel remounts whenever a drill-down replaces it; once the message has
+ // gone out, the host must stop handing it over, or the return trip resends it.
+ it('drops a dispatched message without remounting the panel', () => {
+ const { result } = renderHook(() => useGoalChatPanel('goal-a', 'worker'));
+
+ act(() => result.current.openConversation({ agentId: 'worker', initialMessage: 'next?' }));
+ const request = result.current.request;
+ act(() => result.current.consumeInitialMessage());
+
+ expect(result.current.initialMessage).toBeUndefined();
+ expect(result.current).toMatchObject({ agentId: 'worker', open: true, request });
+ });
+
it('never carries another goal’s open panel or creator into the next goal', () => {
const { result, rerender } = renderHook(({ id, agent }) => useGoalChatPanel(id, agent), {
initialProps: { id: 'goal-a', agent: 'worker-a' },
diff --git a/src/features/AgentGoals/useGoalChatPanel.ts b/src/features/AgentGoals/useGoalChatPanel.ts
index ca7f24bdcd9..29f75cf12c2 100644
--- a/src/features/AgentGoals/useGoalChatPanel.ts
+++ b/src/features/AgentGoals/useGoalChatPanel.ts
@@ -2,6 +2,8 @@ import { useState } from 'react';
interface ConversationTarget {
agentId: string;
+ /** Sent once into the conversation as soon as the panel mounts on it. */
+ initialMessage?: string;
/** Absent opens the agent's side conversation rather than a specific topic. */
topicId?: string;
}
@@ -22,6 +24,16 @@ export const useGoalChatPanel = (goalId: string, responsibleAgentId?: string) =>
return {
agentId: current.target?.agentId ?? responsibleAgentId,
+ initialMessage: current.target?.initialMessage,
+ /**
+ * Acknowledge the handed-off message once the panel has sent or filled it in. The panel
+ * remounts whenever a drill-down replaces it, so a component-local "sent"
+ * flag would resend the message on the way back.
+ */
+ consumeInitialMessage: () => {
+ if (current.target?.initialMessage === undefined) return;
+ setState({ ...current, target: { ...current.target, initialMessage: undefined } });
+ },
open: current.open,
/**
* Send the panel to one destination: the supervision record when the target
@@ -32,6 +44,8 @@ export const useGoalChatPanel = (goalId: string, responsibleAgentId?: string) =>
setState({ goalId, open: true, request: current.request + 1, target });
},
request: current.request,
+ // A pending message survives folding the panel; only `consumeInitialMessage`
+ // drops it, once the panel has actually handed it off.
setOpen: (open: boolean) => setState({ ...current, open }),
topicId: current.target?.topicId,
};