fix: address graph editor UX feedback

- Hide input handle on User Input nodes and output handle on User Output
  nodes (separate userInputNode/userOutputNode node types)
- Enable edge deletion in handoff mode only (Delete key or React Flow UI);
  only agent-to-agent edges are deletable, structural edges are protected
- Block all edge mutations (add/delete) in concurrent and group chat modes
- Add agent as disconnected node without auto-rebuilding the graph
- Add sequential reorder controls (↑↓) in the inspector panel with
  position/order swap and automatic edge rebuilding
- Replace circular group chat layout with vertical column to prevent
  bidirectional edge crossings
- Tighten handoff layout spacing so edges between triage and specialists
  don't overlap nodes
- Use smoothstep edge type for cleaner edge routing across all modes
- Add 6 new tests covering reorder, disconnected add, edge deletion rules,
  and node type assertions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David KayaandCopilot committed 2026-03-24 23:09:21 +01:00
1 parent 7d078faada
commit c6c8e79e9f
7 files changed
+392 -55

No files matched your search

+130 -6
View File
@@ -45,11 +45,16 @@ function resolveNodeLabel(node: PatternGraphNode, agents: PatternAgentDefinition
}
function resolveNodeType(kind: PatternGraphNodeKind): string {
if (kind === 'agent') {
return 'agentNode';
switch (kind) {
case 'user-input':
return 'userInputNode';
case 'user-output':
return 'userOutputNode';
case 'agent':
return 'agentNode';
default:
return 'systemNode';
}
return 'systemNode';
}
export function toCanvasNodes(graph: PatternGraph, agents: PatternAgentDefinition[]): Node<GraphNodeData>[] {
@@ -70,14 +75,28 @@ export function toCanvasNodes(graph: PatternGraph, agents: PatternAgentDefinitio
}));
}
/** Determines whether user-created edges can be deleted in this mode. */
function isEdgeDeletable(edge: PatternGraphEdge, mode: OrchestrationMode, graph: PatternGraph): boolean {
if (mode !== 'handoff') {
return false;
}
const sourceNode = graph.nodes.find((n) => n.id === edge.source);
const targetNode = graph.nodes.find((n) => n.id === edge.target);
// Only agent↔agent edges in handoff mode are user-deletable;
// system edges (user-input → triage, agent → user-output) are structural.
return sourceNode?.kind === 'agent' && targetNode?.kind === 'agent';
}
export function toCanvasEdges(graph: PatternGraph, mode: OrchestrationMode): Edge[] {
return graph.edges.map((edge) => ({
id: edge.id,
source: edge.source,
target: edge.target,
type: 'default',
type: 'smoothstep',
animated: mode === 'handoff',
deletable: false,
deletable: isEdgeDeletable(edge, mode, graph),
}));
}
@@ -134,6 +153,11 @@ export function isConnectionAllowed(
}
}
/** Whether edges can be deleted by the user in this mode. */
export function isEdgeDeletionAllowed(mode: OrchestrationMode): boolean {
return mode === 'handoff';
}
/* ── Graph mutation helpers ─────────────────────────────────── */
function edgeId(source: string, target: string): string {
@@ -158,6 +182,106 @@ export function removeEdge(graph: PatternGraph, removeEdgeId: string): PatternGr
return { ...graph, edges: graph.edges.filter((e) => e.id !== removeEdgeId) };
}
/* ── Add disconnected agent node ───────────────────────────── */
export function addAgentNodeToGraph(
graph: PatternGraph,
agent: PatternAgentDefinition,
): PatternGraph {
const existingAgentNodes = graph.nodes.filter((n) => n.kind === 'agent');
const nextOrder = existingAgentNodes.length;
// Place new node below existing agent nodes
const maxY = existingAgentNodes.reduce((max, n) => Math.max(max, n.position.y), 0);
const avgX = existingAgentNodes.length > 0
? Math.round(existingAgentNodes.reduce((sum, n) => sum + n.position.x, 0) / existingAgentNodes.length)
: 400;
const newNode: PatternGraphNode = {
id: `agent-node-${agent.id}`,
kind: 'agent',
agentId: agent.id,
order: nextOrder,
position: { x: avgX, y: maxY + 120 },
};
return { ...graph, nodes: [...graph.nodes, newNode] };
}
/* ── Sequential reorder ────────────────────────────────────── */
export function swapSequentialOrder(
graph: PatternGraph,
agentNodeId: string,
direction: 'up' | 'down',
): PatternGraph {
const agentNodes = graph.nodes
.filter((n) => n.kind === 'agent')
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
const currentIndex = agentNodes.findIndex((n) => n.id === agentNodeId);
if (currentIndex < 0) {
return graph;
}
const swapIndex = direction === 'up' ? currentIndex - 1 : currentIndex + 1;
if (swapIndex < 0 || swapIndex >= agentNodes.length) {
return graph;
}
const currentNode = agentNodes[currentIndex]!;
const swapNode = agentNodes[swapIndex]!;
// Swap order values
const updatedNodes = graph.nodes.map((n) => {
if (n.id === currentNode.id) {
return { ...n, order: swapNode.order, position: { ...swapNode.position } };
}
if (n.id === swapNode.id) {
return { ...n, order: currentNode.order, position: { ...currentNode.position } };
}
return n;
});
// Rebuild linear edges: input → agent₁ → agent₂ → ... → output
const inputNode = graph.nodes.find((n) => n.kind === 'user-input');
const outputNode = graph.nodes.find((n) => n.kind === 'user-output');
const sortedAgents = updatedNodes
.filter((n) => n.kind === 'agent')
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
const path = [
...(inputNode ? [inputNode.id] : []),
...sortedAgents.map((n) => n.id),
...(outputNode ? [outputNode.id] : []),
];
const newEdges: PatternGraphEdge[] = [];
for (let i = 0; i < path.length - 1; i += 1) {
newEdges.push({ id: edgeId(path[i]!, path[i + 1]!), source: path[i]!, target: path[i + 1]! });
}
return { nodes: updatedNodes, edges: newEdges };
}
/** Check if an agent node can be moved up or down in sequential order. */
export function canMoveSequential(
graph: PatternGraph,
agentNodeId: string,
direction: 'up' | 'down',
): boolean {
const agentNodes = graph.nodes
.filter((n) => n.kind === 'agent')
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
const index = agentNodes.findIndex((n) => n.id === agentNodeId);
if (index < 0) {
return false;
}
return direction === 'up' ? index > 0 : index < agentNodes.length - 1;
}
/* ── Agent node for selected inspector ─────────────────────── */
export function findAgentForNode(