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.

💄 style(goal): tidy the exploration map header and keep edges under cards (#19955)

Arvin Xu00f643400376
diff --git a/src/features/AgentGoals/ProcessControl/Graph/index.tsx b/src/features/AgentGoals/ProcessControl/Graph/index.tsx
index 364c2714130..933971c4ac8 100644
--- a/src/features/AgentGoals/ProcessControl/Graph/index.tsx
+++ b/src/features/AgentGoals/ProcessControl/Graph/index.tsx
@@ -44,6 +44,7 @@ import { type MeasuredSizes, mergeMeasuredSizes } from './measuredSizes';
import { revealCenter } from './revealNode';
import { useExplorationNavigation } from './useExplorationNavigation';
import { useFitViewOnResize } from './useFitViewOnResize';
+import { type GraphViewMode, isStageWholeMap, stageNodeIds } from './viewMode';
/**
* The exploration map. Two views: 当前阶段 (what got the goal here plus what the
@@ -180,8 +181,6 @@ const styles = createStaticStyles(({ css }) => ({
`,
}));
-type GraphViewMode = 'stage' | 'all';
-
interface GraphProps {
/** Header actions after the legend — e.g. a host without fullscreen links out to the goal page. */
extra?: ReactNode;
@@ -200,19 +199,6 @@ interface GraphProps {
selectedId?: string;
}
-/** The nodes worth showing before the user asks for the whole map. */
-const stageNodeIds = (graph: GoalGraphView): Set<string> => {
- const active = new Set<string>();
- for (const view of graph.nodes)
- if (view.node.status !== 'proposed' || ['experiment', 'problem'].includes(view.node.kind))
- active.add(view.node.id);
- for (const item of graph.frontier) active.add(item.view.node.id);
- const visible = new Set(active);
- for (const view of graph.blocked)
- if (view.blockers.every((blocker) => active.has(blocker.id))) visible.add(view.node.id);
- return visible;
-};
-
const useSubtitle = () => {
const { t } = useTranslation('chat');
return useCallback(
@@ -533,7 +519,6 @@ const Canvas = memo<
hot && 'goal-hot',
),
id: edge.id,
- zIndex: 2,
label:
'projected' in edge && edge.projected === true
? t('goalExperiment.projectedRelation', {
@@ -712,7 +697,9 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
}
: props.graph;
const openNode = useChatStore((s) => s.openGoalNode);
- const [view, setView] = useState<GraphViewMode>('stage');
+ const [preferredView, setView] = useState<GraphViewMode>('stage');
+ const stageIsWholeMap = isStageWholeMap(props.graph);
+ const view: GraphViewMode = stageIsWholeMap ? 'all' : preferredView;
const experiments = props.graph.nodes.filter((item) => item.node.kind === 'experiment');
const [hiddenKinds, setHiddenKinds] = useState<ReadonlySet<GoalGraphNodeKind>>(() => new Set());
const showPortal = useChatStore(chatPortalSelectors.showPortal);
@@ -780,12 +767,23 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
))}
</Flexbox>
);
+ const toggle = onFullscreenChange && (
+ <ActionIcon
+ icon={fullscreen ? X : Maximize2}
+ size={'small'}
+ title={fullscreen ? t('goalProcess.graph.exitFullscreen') : t('goalProcess.graph.fullscreen')}
+ aria-label={
+ fullscreen ? t('goalProcess.graph.exitFullscreen') : t('goalProcess.graph.fullscreen')
+ }
+ onClick={() => onFullscreenChange(!fullscreen)}
+ />
+ );
const titleAndViews = (
<>
<Text fontSize={16} weight={600}>
{t('goalProcess.graph.title')}
</Text>
- {experiments.length === 0 && (
+ {experiments.length === 0 && !stageIsWholeMap && (
<Segmented
size={'small'}
value={view}
@@ -796,6 +794,9 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
onChange={(value) => setView(value as GraphViewMode)}
/>
)}
+ {/* Inline, the expand button sits with the view switch; fullscreen keeps
+ its exit in the top-right corner card. */}
+ {!fullscreen && toggle}
</>
);
const legend = (
@@ -838,18 +839,6 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
})}
</Flexbox>
);
- const toggle = onFullscreenChange && (
- <ActionIcon
- icon={fullscreen ? X : Maximize2}
- size={'small'}
- title={fullscreen ? t('goalProcess.graph.exitFullscreen') : t('goalProcess.graph.fullscreen')}
- aria-label={
- fullscreen ? t('goalProcess.graph.exitFullscreen') : t('goalProcess.graph.fullscreen')
- }
- onClick={() => onFullscreenChange(!fullscreen)}
- />
- );
-
if (fullscreen)
return (
<div className={styles.overlay}>
@@ -916,7 +905,6 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
<Flexbox horizontal align={'center'} gap={12}>
{legend}
{extra}
- {toggle}
</Flexbox>
</Flexbox>
<ReactFlowProvider>
diff --git a/src/features/AgentGoals/ProcessControl/Graph/viewMode.test.ts b/src/features/AgentGoals/ProcessControl/Graph/viewMode.test.ts
new file mode 100644
index 00000000000..5deb8065d25
--- /dev/null
+++ b/src/features/AgentGoals/ProcessControl/Graph/viewMode.test.ts
@@ -0,0 +1,95 @@
+import type { GoalGraphEdge, GoalGraphNode, GoalItem, GoalStatus } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import { buildGoalGraphView } from '../goalGraphViewModel';
+import { isStageWholeMap, stageNodeIds } from './viewMode';
+
+const T0 = new Date('2026-08-01T00:00:00Z');
+
+const goal = (status: GoalStatus): GoalItem => ({
+ agentId: 'agt',
+ completedAt: null,
+ config: {},
+ createdAt: T0,
+ id: 'goal-1',
+ maxRounds: null,
+ maxTotalCost: null,
+ projectId: null,
+ requirement: 'ship it',
+ startedAt: T0,
+ status,
+ subjectId: null,
+ subjectType: 'standalone',
+ title: 'Goal',
+ updatedAt: T0,
+ userId: 'user-1',
+ workspaceId: null,
+});
+
+const node = (id: string, status: GoalGraphNode['status']): GoalGraphNode => ({
+ confidence: null,
+ createdAt: T0,
+ createdByAgentId: null,
+ createdByUserId: null,
+ description: null,
+ goalId: 'goal-1',
+ id,
+ kind: 'task',
+ priority: 0,
+ resolvedAt: null,
+ status,
+ taskId: null,
+ title: id,
+ updatedAt: T0,
+});
+
+const dependsOn = (source: string, target: string): GoalGraphEdge => ({
+ createdAt: T0,
+ goalId: 'goal-1',
+ id: `${source}-${target}`,
+ kind: 'depends_on',
+ sourceNodeId: source,
+ targetNodeId: target,
+});
+
+/** w3 waits on w2, which waits on w1 — the stage view stops at w2. */
+const graph = (status: GoalStatus, nodeStatus: GoalGraphNode['status']) =>
+ buildGoalGraphView(
+ {
+ decisions: [],
+ edges: [dependsOn('w2', 'w1'), dependsOn('w3', 'w2')],
+ events: [],
+ goal: goal(status),
+ nodes: [node('w1', nodeStatus), node('w2', 'proposed'), node('w3', 'proposed')],
+ workVersions: [],
+ },
+ T0.getTime(),
+ );
+
+describe('isStageWholeMap', () => {
+ it('keeps the switch while the stage view hides part of a live goal', () => {
+ const view = graph('running', 'proposed');
+ expect(stageNodeIds(view).size).toBeLessThan(view.nodes.length);
+ expect(isStageWholeMap(view)).toBe(false);
+ });
+
+ it('drops the switch once the goal has finished', () => {
+ for (const status of ['achieved', 'failed', 'canceled'] as const)
+ expect(isStageWholeMap(graph(status, 'proposed'))).toBe(true);
+ });
+
+ it('drops the switch when every node is already in the stage', () => {
+ const view = buildGoalGraphView(
+ {
+ decisions: [],
+ edges: [],
+ events: [],
+ goal: goal('paused'),
+ nodes: [node('w1', 'resolved'), node('w2', 'resolved')],
+ workVersions: [],
+ },
+ T0.getTime(),
+ );
+ expect(isStageWholeMap(view)).toBe(true);
+ });
+});
diff --git a/src/features/AgentGoals/ProcessControl/Graph/viewMode.ts b/src/features/AgentGoals/ProcessControl/Graph/viewMode.ts
new file mode 100644
index 00000000000..548db8d2692
--- /dev/null
+++ b/src/features/AgentGoals/ProcessControl/Graph/viewMode.ts
@@ -0,0 +1,28 @@
+import type { GoalStatus } from '@lobechat/types';
+
+import type { GoalGraphView } from '../goalGraphViewModel';
+
+export type GraphViewMode = 'stage' | 'all';
+
+const TERMINAL_GOAL_STATUSES = new Set<GoalStatus>(['achieved', 'failed', 'canceled']);
+
+/** The nodes worth showing before the user asks for the whole map. */
+export const stageNodeIds = (graph: GoalGraphView): Set<string> => {
+ const active = new Set<string>();
+ for (const view of graph.nodes)
+ if (view.node.status !== 'proposed' || ['experiment', 'problem'].includes(view.node.kind))
+ active.add(view.node.id);
+ for (const item of graph.frontier) active.add(item.view.node.id);
+ const visible = new Set(active);
+ for (const view of graph.blocked)
+ if (view.blockers.every((blocker) => active.has(blocker.id))) visible.add(view.node.id);
+ return visible;
+};
+
+/**
+ * Whether the stage/all switch has nothing to switch: a finished goal has no
+ * "current stage" left, and once every node is in the stage the two views
+ * render the same map.
+ */
+export const isStageWholeMap = (graph: GoalGraphView): boolean =>
+ TERMINAL_GOAL_STATUSES.has(graph.goal.status) || stageNodeIds(graph).size >= graph.nodes.length;