Implement Phase 2: Next.js + React Flow frontend MVP

- Scaffold Next.js 15 app with TypeScript, Tailwind, App Router
- Install @xyflow/react, Zustand, Lucide icons, nanoid
- Define council types (AgentNodeData, CouncilBlueprint, WSMessage, etc.)
- Implement Zustand store for canvas and run state
- Build custom AgentNode component (label, system prompt, model badge, tool chips, active pulse)
- Build ConditionalEdge component (dashed indigo line with condition label)
- Build NodeSidebar (drag-and-drop + click to add agents)
- Build NodeSettingsPanel (name, system prompt, model selector, tool toggles)
- Build ArchitectCanvas (React Flow canvas with drop zone, minimap, controls)
- Build blueprint parser (React Flow JSON ↔ CouncilBlueprint JSON)
- Build API client for FastAPI backend (CRUD + run endpoints)
- Build useCouncilWebSocket hook for live agent status via WebSocket
- Build Tab A: Rat-Architekt (canvas builder with save/export toolbar)
- Build Tab B: Konferenzzimmer (execution view with live diagram + result panel)
- Add NavTabs navigation with CouncilOS branding
- All TypeScript checks passing

https://claude.ai/code/session_01EkbecUVn7esdxLCXxVVRDX
This commit is contained in:
Claude 2026-02-20 17:03:32 +00:00
parent 06aec41a8a
commit 216fdd9589
No known key found for this signature in database
30 changed files with 8237 additions and 0 deletions

View file

@ -0,0 +1,87 @@
"use client";
import { useCallback } from "react";
import {
ReactFlow,
Background,
Controls,
MiniMap,
BackgroundVariant,
useReactFlow,
} from "@xyflow/react";
import "@xyflow/react/dist/style.css";
import { AgentNode } from "@/app/components/nodes/AgentNode";
import { ConditionalEdge } from "@/app/components/edges/ConditionalEdge";
import { useCouncilStore } from "@/app/store/council-store";
import { AgentNodeData } from "@/app/types/council";
const NODE_TYPES = { agentNode: AgentNode };
const EDGE_TYPES = { conditionalEdge: ConditionalEdge };
// Main React Flow canvas — lives inside a ReactFlowProvider
export function ArchitectCanvas() {
const nodes = useCouncilStore((s) => s.nodes);
const edges = useCouncilStore((s) => s.edges);
const onNodesChange = useCouncilStore((s) => s.onNodesChange);
const onEdgesChange = useCouncilStore((s) => s.onEdgesChange);
const onConnect = useCouncilStore((s) => s.onConnect);
const addAgentNode = useCouncilStore((s) => s.addAgentNode);
const selectNode = useCouncilStore((s) => s.selectNode);
const { screenToFlowPosition } = useReactFlow();
const onDragOver = useCallback((event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault();
event.dataTransfer.dropEffect = "move";
}, []);
const onDrop = useCallback(
(event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault();
const type = event.dataTransfer.getData("application/reactflow");
if (type !== "agentNode") return;
const position = screenToFlowPosition({
x: event.clientX,
y: event.clientY,
});
addAgentNode(position);
},
[screenToFlowPosition, addAgentNode]
);
const onPaneClick = useCallback(() => {
selectNode(null);
}, [selectNode]);
return (
<div className="flex-1 h-full">
<ReactFlow
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
onDrop={onDrop}
onDragOver={onDragOver}
onPaneClick={onPaneClick}
nodeTypes={NODE_TYPES}
edgeTypes={EDGE_TYPES}
fitView
deleteKeyCode="Delete"
className="bg-slate-50"
>
<Background variant={BackgroundVariant.Dots} gap={20} size={1} color="#cbd5e1" />
<Controls />
<MiniMap
nodeColor={(n) => {
const d = n.data as AgentNodeData;
return d?.isActive ? "#6366f1" : "#94a3b8";
}}
className="!bg-white !border-slate-200"
/>
</ReactFlow>
</div>
);
}

View file

@ -0,0 +1,38 @@
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Network, MessagesSquare } from "lucide-react";
const TABS = [
{ href: "/rat-architekt", label: "Rat-Architekt", icon: Network },
{ href: "/konferenzzimmer", label: "Konferenzzimmer", icon: MessagesSquare },
];
export function NavTabs() {
const pathname = usePathname();
return (
<nav className="flex items-center gap-1 px-4 py-2 bg-white border-b border-slate-200 flex-shrink-0">
<span className="font-bold text-indigo-700 text-sm mr-4">CouncilOS</span>
{TABS.map(({ href, label, icon: Icon }) => {
const active = pathname.startsWith(href);
return (
<Link
key={href}
href={href}
className={[
"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-colors",
active
? "bg-indigo-50 text-indigo-700"
: "text-slate-500 hover:text-slate-700 hover:bg-slate-50",
].join(" ")}
>
<Icon size={14} />
{label}
</Link>
);
})}
</nav>
);
}

View file

@ -0,0 +1,61 @@
"use client";
import { memo } from "react";
import {
EdgeProps,
BaseEdge,
EdgeLabelRenderer,
getSmoothStepPath,
} from "@xyflow/react";
export const ConditionalEdge = memo(function ConditionalEdge({
id,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
data,
markerEnd,
}: EdgeProps) {
const [edgePath, labelX, labelY] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
});
const condition = data?.condition as string | undefined;
return (
<>
<BaseEdge
id={id}
path={edgePath}
markerEnd={markerEnd}
style={{
strokeDasharray: "6 3",
stroke: "#6366f1",
strokeWidth: 2,
}}
/>
{condition && (
<EdgeLabelRenderer>
<div
style={{
position: "absolute",
transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`,
pointerEvents: "all",
}}
className="bg-indigo-600 text-white text-xs px-2 py-0.5 rounded-full font-medium shadow nodrag nopan"
>
{condition}
</div>
</EdgeLabelRenderer>
)}
</>
);
});

View file

@ -0,0 +1,113 @@
"use client";
import { memo } from "react";
import { Handle, Position, NodeProps } from "@xyflow/react";
import { Bot, Globe, FileText } from "lucide-react";
import { AgentNodeData } from "@/app/types/council";
import { useCouncilStore } from "@/app/store/council-store";
const MODEL_LABELS: Record<string, string> = {
"claude-3-5-sonnet": "Claude 3.5",
"gpt-4o": "GPT-4o",
local: "Lokal",
};
const MODEL_COLORS: Record<string, string> = {
"claude-3-5-sonnet": "bg-orange-100 text-orange-700 border-orange-300",
"gpt-4o": "bg-green-100 text-green-700 border-green-300",
local: "bg-gray-100 text-gray-700 border-gray-300",
};
export const AgentNode = memo(function AgentNode({
id,
data,
selected,
}: NodeProps) {
const nodeData = data as AgentNodeData;
const selectNode = useCouncilStore((s) => s.selectNode);
const isActive = nodeData.isActive;
return (
<div
onClick={() => selectNode(id)}
className={[
"w-52 rounded-xl border-2 bg-white shadow-md transition-all duration-300 cursor-pointer",
isActive
? "border-indigo-500 shadow-indigo-200 shadow-lg animate-pulse"
: selected
? "border-indigo-400 shadow-indigo-100"
: "border-slate-200 hover:border-slate-400",
].join(" ")}
>
{/* Header */}
<div
className={[
"flex items-center gap-2 rounded-t-xl px-3 py-2",
isActive ? "bg-indigo-50" : "bg-slate-50",
].join(" ")}
>
<Bot
size={16}
className={isActive ? "text-indigo-600" : "text-slate-500"}
/>
<span className="font-semibold text-sm text-slate-800 truncate flex-1">
{nodeData.label}
</span>
{isActive && (
<span className="text-xs text-indigo-600 font-medium">aktiv</span>
)}
</div>
{/* Body */}
<div className="px-3 py-2 space-y-2">
{/* System prompt preview */}
<p className="text-xs text-slate-500 line-clamp-2 min-h-[2rem]">
{nodeData.systemPrompt || (
<span className="italic text-slate-300">Kein System-Prompt</span>
)}
</p>
{/* Model badge */}
<span
className={[
"inline-block text-xs px-2 py-0.5 rounded-full border font-medium",
MODEL_COLORS[nodeData.model] ?? MODEL_COLORS["local"],
].join(" ")}
>
{MODEL_LABELS[nodeData.model] ?? nodeData.model}
</span>
{/* Tool toggles */}
{(nodeData.tools.webSearch || nodeData.tools.pdfReader) && (
<div className="flex gap-2">
{nodeData.tools.webSearch && (
<span className="flex items-center gap-1 text-xs text-blue-600 bg-blue-50 px-2 py-0.5 rounded-full">
<Globe size={10} />
Web
</span>
)}
{nodeData.tools.pdfReader && (
<span className="flex items-center gap-1 text-xs text-purple-600 bg-purple-50 px-2 py-0.5 rounded-full">
<FileText size={10} />
PDF
</span>
)}
</div>
)}
</div>
{/* Handles */}
<Handle
type="target"
position={Position.Left}
className="!w-3 !h-3 !bg-slate-400 !border-white !border-2"
/>
<Handle
type="source"
position={Position.Right}
className="!w-3 !h-3 !bg-indigo-500 !border-white !border-2"
/>
</div>
);
});

View file

@ -0,0 +1,135 @@
"use client";
import { useEffect, useState } from "react";
import { X, Bot } from "lucide-react";
import { AgentNodeData, LLMModel } from "@/app/types/council";
import { useCouncilStore } from "@/app/store/council-store";
const MODELS: { value: LLMModel; label: string }[] = [
{ value: "claude-3-5-sonnet", label: "Claude 3.5 Sonnet" },
{ value: "gpt-4o", label: "GPT-4o" },
{ value: "local", label: "Lokal" },
];
// Right-side panel shown when an AgentNode is selected
export function NodeSettingsPanel() {
const selectedNodeId = useCouncilStore((s) => s.selectedNodeId);
const nodes = useCouncilStore((s) => s.nodes);
const updateNodeData = useCouncilStore((s) => s.updateNodeData);
const selectNode = useCouncilStore((s) => s.selectNode);
const node = nodes.find((n) => n.id === selectedNodeId);
const data = node?.data as AgentNodeData | undefined;
// Local draft to avoid re-renders on every keystroke
const [draft, setDraft] = useState<AgentNodeData | null>(null);
useEffect(() => {
setDraft(data ?? null);
}, [selectedNodeId, data]);
if (!selectedNodeId || !draft) return null;
const commit = (partial: Partial<AgentNodeData>) => {
const updated = { ...draft, ...partial };
setDraft(updated);
updateNodeData(selectedNodeId, partial);
};
return (
<aside className="w-72 flex-shrink-0 bg-white border-l border-slate-200 p-4 flex flex-col gap-4 overflow-y-auto">
{/* Header */}
<div className="flex items-center gap-2">
<Bot size={16} className="text-indigo-600" />
<h2 className="font-semibold text-slate-800 text-sm flex-1">
Agent-Einstellungen
</h2>
<button
onClick={() => selectNode(null)}
className="text-slate-400 hover:text-slate-600"
>
<X size={16} />
</button>
</div>
{/* Name */}
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-slate-500">Name</label>
<input
type="text"
value={draft.label}
onChange={(e) => commit({ label: e.target.value })}
className="rounded-lg border border-slate-200 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-300"
/>
</div>
{/* System Prompt */}
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-slate-500">
System-Prompt
</label>
<textarea
value={draft.systemPrompt}
onChange={(e) => commit({ systemPrompt: e.target.value })}
rows={6}
placeholder="Beschreibe die Rolle und das Verhalten dieses Agenten..."
className="rounded-lg border border-slate-200 px-3 py-2 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-indigo-300"
/>
</div>
{/* Model */}
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-slate-500">Modell</label>
<select
value={draft.model}
onChange={(e) => commit({ model: e.target.value as LLMModel })}
className="rounded-lg border border-slate-200 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-300"
>
{MODELS.map((m) => (
<option key={m.value} value={m.value}>
{m.label}
</option>
))}
</select>
</div>
{/* Tools */}
<div className="flex flex-col gap-2">
<label className="text-xs font-medium text-slate-500">Tools</label>
<label className="flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={draft.tools.webSearch}
onChange={(e) =>
commit({ tools: { ...draft.tools, webSearch: e.target.checked } })
}
className="h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-300"
/>
<span className="text-sm text-slate-700">Web-Suche (Tavily)</span>
</label>
<label className="flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={draft.tools.pdfReader}
onChange={(e) =>
commit({ tools: { ...draft.tools, pdfReader: e.target.checked } })
}
className="h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-300"
/>
<span className="text-sm text-slate-700">PDF-Leser</span>
</label>
</div>
{/* Edge type info */}
<div className="mt-auto rounded-lg bg-slate-50 p-3 text-xs text-slate-500 leading-relaxed">
<strong className="text-slate-600">Tipp:</strong> Verbinde zwei Agenten
mit einer Kante. Klicke danach auf die Kante, um sie als{" "}
<em>bedingt</em> zu markieren und einen Routing-Wert einzugeben (z. B.{" "}
<code className="bg-slate-200 px-1 rounded">rework</code> oder{" "}
<code className="bg-slate-200 px-1 rounded">approve</code>).
</div>
</aside>
);
}

View file

@ -0,0 +1,62 @@
"use client";
import { useCallback } from "react";
import { Bot, Plus } from "lucide-react";
import { useCouncilStore } from "@/app/store/council-store";
// Sidebar panel — drag or click to add agent nodes to the canvas
export function NodeSidebar() {
const addAgentNode = useCouncilStore((s) => s.addAgentNode);
const onDragStart = useCallback(
(event: React.DragEvent<HTMLDivElement>) => {
event.dataTransfer.setData("application/reactflow", "agentNode");
event.dataTransfer.effectAllowed = "move";
},
[]
);
const handleAddClick = useCallback(() => {
// Add node at a reasonable default position near the center
addAgentNode({ x: 200 + Math.random() * 200, y: 100 + Math.random() * 200 });
}, [addAgentNode]);
return (
<aside className="w-52 flex-shrink-0 bg-white border-r border-slate-200 p-4 flex flex-col gap-4">
<h2 className="text-xs font-semibold text-slate-400 uppercase tracking-wider">
Komponenten
</h2>
{/* Draggable node template */}
<div
draggable
onDragStart={onDragStart}
onClick={handleAddClick}
className="flex items-center gap-2 rounded-lg border-2 border-dashed border-indigo-300 bg-indigo-50 px-3 py-3 cursor-grab active:cursor-grabbing hover:border-indigo-500 hover:bg-indigo-100 transition-colors select-none"
title="Auf Canvas ziehen oder klicken"
>
<Bot size={18} className="text-indigo-600" />
<span className="text-sm font-medium text-indigo-700">Agent</span>
<Plus size={14} className="text-indigo-400 ml-auto" />
</div>
<p className="text-xs text-slate-400 leading-snug">
Ziehe einen Agent auf die Zeichenfläche oder klicke, um ihn hinzuzufügen.
</p>
<div className="mt-auto space-y-1">
<p className="text-xs font-semibold text-slate-400 uppercase tracking-wider">
Kanten
</p>
<div className="flex items-center gap-2 text-xs text-slate-500">
<span className="block w-6 border-t-2 border-slate-400" />
Linear
</div>
<div className="flex items-center gap-2 text-xs text-slate-500">
<span className="block w-6 border-t-2 border-dashed border-indigo-500" />
Bedingt
</div>
</div>
</aside>
);
}