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:
parent
06aec41a8a
commit
216fdd9589
30 changed files with 8237 additions and 0 deletions
87
frontend/app/components/ArchitectCanvas.tsx
Normal file
87
frontend/app/components/ArchitectCanvas.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
38
frontend/app/components/NavTabs.tsx
Normal file
38
frontend/app/components/NavTabs.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
61
frontend/app/components/edges/ConditionalEdge.tsx
Normal file
61
frontend/app/components/edges/ConditionalEdge.tsx
Normal 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>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
});
|
||||
113
frontend/app/components/nodes/AgentNode.tsx
Normal file
113
frontend/app/components/nodes/AgentNode.tsx
Normal 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>
|
||||
);
|
||||
});
|
||||
135
frontend/app/components/panels/NodeSettingsPanel.tsx
Normal file
135
frontend/app/components/panels/NodeSettingsPanel.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
62
frontend/app/components/panels/NodeSidebar.tsx
Normal file
62
frontend/app/components/panels/NodeSidebar.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
BIN
frontend/app/favicon.ico
Normal file
BIN
frontend/app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
26
frontend/app/globals.css
Normal file
26
frontend/app/globals.css
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
74
frontend/app/hooks/useCouncilWebSocket.ts
Normal file
74
frontend/app/hooks/useCouncilWebSocket.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useRef, useCallback } from "react";
|
||||
import { WSMessage } from "@/app/types/council";
|
||||
import { wsUrl } from "@/app/utils/api-client";
|
||||
import { useCouncilStore } from "@/app/store/council-store";
|
||||
|
||||
interface Options {
|
||||
run_id: string | null;
|
||||
onComplete?: (result: string) => void;
|
||||
onError?: (error: string) => void;
|
||||
}
|
||||
|
||||
// WebSocket hook for live agent status updates during a council run
|
||||
export function useCouncilWebSocket({ run_id, onComplete, onError }: Options) {
|
||||
const ws = useRef<WebSocket | null>(null);
|
||||
const markNodeActive = useCouncilStore((s) => s.markNodeActive);
|
||||
const clearActiveNode = useCouncilStore((s) => s.clearActiveNode);
|
||||
const setActiveRun = useCouncilStore((s) => s.setActiveRun);
|
||||
|
||||
const disconnect = useCallback(() => {
|
||||
if (ws.current) {
|
||||
ws.current.close();
|
||||
ws.current = null;
|
||||
}
|
||||
clearActiveNode();
|
||||
}, [clearActiveNode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!run_id) return;
|
||||
|
||||
const socket = new WebSocket(wsUrl(run_id));
|
||||
ws.current = socket;
|
||||
|
||||
socket.onmessage = (event: MessageEvent<string>) => {
|
||||
let msg: WSMessage;
|
||||
try {
|
||||
msg = JSON.parse(event.data) as WSMessage;
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg.type) {
|
||||
case "node_enter":
|
||||
if (msg.node_name) markNodeActive(msg.node_name);
|
||||
break;
|
||||
case "node_exit":
|
||||
clearActiveNode();
|
||||
break;
|
||||
case "run_complete":
|
||||
clearActiveNode();
|
||||
setActiveRun(null);
|
||||
if (msg.result) onComplete?.(msg.result);
|
||||
disconnect();
|
||||
break;
|
||||
case "run_error":
|
||||
clearActiveNode();
|
||||
setActiveRun(null);
|
||||
if (msg.error) onError?.(msg.error);
|
||||
disconnect();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
socket.onerror = () => {
|
||||
onError?.("WebSocket-Verbindungsfehler");
|
||||
disconnect();
|
||||
};
|
||||
|
||||
return () => disconnect();
|
||||
}, [run_id]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
return { disconnect };
|
||||
}
|
||||
143
frontend/app/konferenzzimmer/page.tsx
Normal file
143
frontend/app/konferenzzimmer/page.tsx
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
"use client";
|
||||
|
||||
import { useState, useCallback } from "react";
|
||||
import { ReactFlowProvider } from "@xyflow/react";
|
||||
import { Play, Square, Upload } from "lucide-react";
|
||||
import { ArchitectCanvas } from "@/app/components/ArchitectCanvas";
|
||||
import { useCouncilWebSocket } from "@/app/hooks/useCouncilWebSocket";
|
||||
import { useCouncilStore } from "@/app/store/council-store";
|
||||
import { runApi } from "@/app/utils/api-client";
|
||||
|
||||
export default function KonferenzzimmerPage() {
|
||||
const [topic, setTopic] = useState("");
|
||||
const [runId, setRunId] = useState<string | null>(null);
|
||||
const [result, setResult] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isRunning, setIsRunning] = useState(false);
|
||||
|
||||
const setActiveRun = useCouncilStore((s) => s.setActiveRun);
|
||||
const clearActiveNode = useCouncilStore((s) => s.clearActiveNode);
|
||||
|
||||
const onComplete = useCallback((res: string) => {
|
||||
setResult(res);
|
||||
setIsRunning(false);
|
||||
setRunId(null);
|
||||
}, []);
|
||||
|
||||
const onError = useCallback((err: string) => {
|
||||
setError(err);
|
||||
setIsRunning(false);
|
||||
setRunId(null);
|
||||
}, []);
|
||||
|
||||
useCouncilWebSocket({ run_id: runId, onComplete, onError });
|
||||
|
||||
const handleStart = async () => {
|
||||
if (!topic.trim()) return;
|
||||
setResult(null);
|
||||
setError(null);
|
||||
setIsRunning(true);
|
||||
clearActiveNode();
|
||||
try {
|
||||
const run = await runApi.start(topic);
|
||||
setActiveRun(run);
|
||||
setRunId(run.run_id);
|
||||
} catch (e) {
|
||||
setError("Fehler beim Starten: " + (e as Error).message);
|
||||
setIsRunning(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleStop = () => {
|
||||
setRunId(null);
|
||||
setIsRunning(false);
|
||||
clearActiveNode();
|
||||
setActiveRun(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
{/* Control bar */}
|
||||
<header className="flex items-center gap-3 px-4 py-2 border-b border-slate-200 bg-white flex-shrink-0">
|
||||
<textarea
|
||||
value={topic}
|
||||
onChange={(e) => setTopic(e.target.value)}
|
||||
placeholder="Thema oder Aufgabe eingeben..."
|
||||
rows={1}
|
||||
className="flex-1 rounded-lg border border-slate-200 px-3 py-1.5 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-indigo-300"
|
||||
/>
|
||||
<button className="flex items-center gap-1.5 text-sm text-slate-600 border border-slate-200 px-3 py-1.5 rounded-lg hover:bg-slate-50 transition-colors">
|
||||
<Upload size={14} />
|
||||
PDF
|
||||
</button>
|
||||
{!isRunning ? (
|
||||
<button
|
||||
onClick={handleStart}
|
||||
disabled={!topic.trim()}
|
||||
className="flex items-center gap-1.5 text-sm text-white bg-indigo-600 px-3 py-1.5 rounded-lg hover:bg-indigo-700 transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
>
|
||||
<Play size={14} />
|
||||
Start
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={handleStop}
|
||||
className="flex items-center gap-1.5 text-sm text-white bg-red-500 px-3 py-1.5 rounded-lg hover:bg-red-600 transition-colors"
|
||||
>
|
||||
<Square size={14} />
|
||||
Stopp
|
||||
</button>
|
||||
)}
|
||||
</header>
|
||||
|
||||
{/* Canvas (read-only, agent nodes pulse when active) */}
|
||||
<div className="flex flex-1 overflow-hidden">
|
||||
<ReactFlowProvider>
|
||||
<div className="flex-1 h-full relative">
|
||||
<ArchitectCanvas />
|
||||
{isRunning && (
|
||||
<div className="absolute top-3 left-1/2 -translate-x-1/2 bg-indigo-600 text-white text-xs px-4 py-1.5 rounded-full shadow-lg animate-pulse pointer-events-none">
|
||||
Rat läuft…
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ReactFlowProvider>
|
||||
|
||||
{/* Output panel */}
|
||||
<aside className="w-80 flex-shrink-0 border-l border-slate-200 bg-white flex flex-col">
|
||||
<div className="px-4 py-3 border-b border-slate-100">
|
||||
<h2 className="text-sm font-semibold text-slate-700">Ergebnis</h2>
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto p-4">
|
||||
{error && (
|
||||
<div className="rounded-lg bg-red-50 border border-red-200 p-3 text-sm text-red-700">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{result && (
|
||||
<div className="rounded-lg bg-slate-50 border border-slate-200 p-3 text-sm text-slate-700 whitespace-pre-wrap leading-relaxed">
|
||||
{result}
|
||||
</div>
|
||||
)}
|
||||
{!result && !error && !isRunning && (
|
||||
<p className="text-sm text-slate-400 italic">
|
||||
Noch kein Ergebnis. Starte den Rat mit einem Thema.
|
||||
</p>
|
||||
)}
|
||||
{isRunning && !result && (
|
||||
<div className="space-y-2">
|
||||
{[1, 2, 3].map((i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="h-3 bg-slate-100 rounded animate-pulse"
|
||||
style={{ width: `${70 + i * 10}%` }}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
22
frontend/app/layout.tsx
Normal file
22
frontend/app/layout.tsx
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import type { Metadata } from "next";
|
||||
import { Geist } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import { NavTabs } from "@/app/components/NavTabs";
|
||||
|
||||
const geist = Geist({ variable: "--font-geist-sans", subsets: ["latin"] });
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "CouncilOS — KI-Rat Baukasten",
|
||||
description: "Visueller No-Code-Builder für Multi-Agent-KI-Pipelines",
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="de">
|
||||
<body className={`${geist.variable} antialiased bg-slate-50 h-screen flex flex-col`}>
|
||||
<NavTabs />
|
||||
<main className="flex-1 overflow-hidden">{children}</main>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
5
frontend/app/page.tsx
Normal file
5
frontend/app/page.tsx
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function Home() {
|
||||
redirect("/rat-architekt");
|
||||
}
|
||||
81
frontend/app/rat-architekt/page.tsx
Normal file
81
frontend/app/rat-architekt/page.tsx
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
"use client";
|
||||
|
||||
import { ReactFlowProvider } from "@xyflow/react";
|
||||
import { Save, Download } from "lucide-react";
|
||||
import { ArchitectCanvas } from "@/app/components/ArchitectCanvas";
|
||||
import { NodeSidebar } from "@/app/components/panels/NodeSidebar";
|
||||
import { NodeSettingsPanel } from "@/app/components/panels/NodeSettingsPanel";
|
||||
import { useCouncilStore } from "@/app/store/council-store";
|
||||
import { parseGraphToBlueprint } from "@/app/utils/blueprint-parser";
|
||||
import { councilApi } from "@/app/utils/api-client";
|
||||
|
||||
export default function RatArchitektPage() {
|
||||
const nodes = useCouncilStore((s) => s.nodes);
|
||||
const edges = useCouncilStore((s) => s.edges);
|
||||
const councilName = useCouncilStore((s) => s.councilName);
|
||||
const setCouncilName = useCouncilStore((s) => s.setCouncilName);
|
||||
|
||||
const handleSave = async () => {
|
||||
const blueprint = parseGraphToBlueprint(nodes, edges, councilName);
|
||||
try {
|
||||
await councilApi.create(blueprint);
|
||||
alert("Rat gespeichert!");
|
||||
} catch (e) {
|
||||
alert("Fehler beim Speichern: " + (e as Error).message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleExport = () => {
|
||||
const blueprint = parseGraphToBlueprint(nodes, edges, councilName);
|
||||
const blob = new Blob([JSON.stringify(blueprint, null, 2)], {
|
||||
type: "application/json",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = `${councilName.replace(/\s+/g, "-")}-blueprint.json`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
{/* Toolbar */}
|
||||
<header className="flex items-center gap-3 px-4 py-2 border-b border-slate-200 bg-white flex-shrink-0">
|
||||
<input
|
||||
type="text"
|
||||
value={councilName}
|
||||
onChange={(e) => setCouncilName(e.target.value)}
|
||||
className="font-semibold text-slate-800 bg-transparent border-none focus:outline-none focus:ring-2 focus:ring-indigo-300 rounded px-1"
|
||||
/>
|
||||
<span className="text-slate-300">|</span>
|
||||
<span className="text-xs text-slate-400">{nodes.length} Agenten · {edges.length} Kanten</span>
|
||||
<div className="ml-auto flex gap-2">
|
||||
<button
|
||||
onClick={handleExport}
|
||||
className="flex items-center gap-1.5 text-sm text-slate-600 border border-slate-200 px-3 py-1.5 rounded-lg hover:bg-slate-50 transition-colors"
|
||||
>
|
||||
<Download size={14} />
|
||||
Export
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSave}
|
||||
className="flex items-center gap-1.5 text-sm text-white bg-indigo-600 px-3 py-1.5 rounded-lg hover:bg-indigo-700 transition-colors"
|
||||
>
|
||||
<Save size={14} />
|
||||
Speichern
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Main area */}
|
||||
<div className="flex flex-1 overflow-hidden">
|
||||
<ReactFlowProvider>
|
||||
<NodeSidebar />
|
||||
<ArchitectCanvas />
|
||||
<NodeSettingsPanel />
|
||||
</ReactFlowProvider>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
125
frontend/app/store/council-store.ts
Normal file
125
frontend/app/store/council-store.ts
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
// Zustand store for canvas state and council run state
|
||||
import { create } from "zustand";
|
||||
import { Node, Edge, addEdge, applyNodeChanges, applyEdgeChanges, NodeChange, EdgeChange, Connection } from "@xyflow/react";
|
||||
import { AgentNodeData, CouncilRun, LLMModel } from "@/app/types/council";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
interface CouncilStore {
|
||||
// Canvas
|
||||
nodes: Node<AgentNodeData>[];
|
||||
edges: Edge[];
|
||||
selectedNodeId: string | null;
|
||||
councilName: string;
|
||||
|
||||
// Execution
|
||||
activeRun: CouncilRun | null;
|
||||
activeNodeId: string | null;
|
||||
|
||||
// Canvas actions
|
||||
onNodesChange: (changes: NodeChange[]) => void;
|
||||
onEdgesChange: (changes: EdgeChange[]) => void;
|
||||
onConnect: (connection: Connection) => void;
|
||||
addAgentNode: (position: { x: number; y: number }) => void;
|
||||
updateNodeData: (nodeId: string, data: Partial<AgentNodeData>) => void;
|
||||
selectNode: (nodeId: string | null) => void;
|
||||
setCouncilName: (name: string) => void;
|
||||
setNodes: (nodes: Node<AgentNodeData>[]) => void;
|
||||
setEdges: (edges: Edge[]) => void;
|
||||
|
||||
// Run actions
|
||||
setActiveRun: (run: CouncilRun | null) => void;
|
||||
setActiveNodeId: (nodeId: string | null) => void;
|
||||
markNodeActive: (nodeName: string) => void;
|
||||
clearActiveNode: () => void;
|
||||
}
|
||||
|
||||
function makeDefaultNodeData(label: string): AgentNodeData {
|
||||
return {
|
||||
label,
|
||||
systemPrompt: "",
|
||||
model: "claude-3-5-sonnet",
|
||||
tools: { webSearch: false, pdfReader: false },
|
||||
isActive: false,
|
||||
};
|
||||
}
|
||||
|
||||
export const useCouncilStore = create<CouncilStore>((set, get) => ({
|
||||
nodes: [],
|
||||
edges: [],
|
||||
selectedNodeId: null,
|
||||
councilName: "Mein Rat",
|
||||
activeRun: null,
|
||||
activeNodeId: null,
|
||||
|
||||
onNodesChange: (changes) =>
|
||||
set((state) => ({
|
||||
nodes: applyNodeChanges(changes, state.nodes) as Node<AgentNodeData>[],
|
||||
})),
|
||||
|
||||
onEdgesChange: (changes) =>
|
||||
set((state) => ({
|
||||
edges: applyEdgeChanges(changes, state.edges),
|
||||
})),
|
||||
|
||||
onConnect: (connection) =>
|
||||
set((state) => ({
|
||||
edges: addEdge(
|
||||
{ ...connection, type: "default", data: { type: "linear" } },
|
||||
state.edges
|
||||
),
|
||||
})),
|
||||
|
||||
addAgentNode: (position) => {
|
||||
const id = nanoid();
|
||||
const count = get().nodes.length + 1;
|
||||
const newNode: Node<AgentNodeData> = {
|
||||
id,
|
||||
type: "agentNode",
|
||||
position,
|
||||
data: makeDefaultNodeData(`Agent ${count}`),
|
||||
};
|
||||
set((state) => ({ nodes: [...state.nodes, newNode] }));
|
||||
},
|
||||
|
||||
updateNodeData: (nodeId, data) =>
|
||||
set((state) => ({
|
||||
nodes: state.nodes.map((n) =>
|
||||
n.id === nodeId ? { ...n, data: { ...n.data, ...data } } : n
|
||||
),
|
||||
})),
|
||||
|
||||
selectNode: (nodeId) => set({ selectedNodeId: nodeId }),
|
||||
|
||||
setCouncilName: (name) => set({ councilName: name }),
|
||||
|
||||
setNodes: (nodes) => set({ nodes }),
|
||||
|
||||
setEdges: (edges) => set({ edges }),
|
||||
|
||||
setActiveRun: (run) => set({ activeRun: run }),
|
||||
|
||||
setActiveNodeId: (nodeId) => set({ activeNodeId: nodeId }),
|
||||
|
||||
markNodeActive: (nodeName) => {
|
||||
const node = get().nodes.find((n) => n.data.label === nodeName);
|
||||
if (node) {
|
||||
set((state) => ({
|
||||
activeNodeId: node.id,
|
||||
nodes: state.nodes.map((n) => ({
|
||||
...n,
|
||||
data: { ...n.data, isActive: n.id === node.id },
|
||||
})),
|
||||
}));
|
||||
}
|
||||
},
|
||||
|
||||
clearActiveNode: () =>
|
||||
set((state) => ({
|
||||
activeNodeId: null,
|
||||
nodes: state.nodes.map((n) => ({
|
||||
...n,
|
||||
data: { ...n.data, isActive: false },
|
||||
})),
|
||||
})),
|
||||
}));
|
||||
|
||||
73
frontend/app/types/council.ts
Normal file
73
frontend/app/types/council.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// Council blueprint types — canonical exchange format between frontend and backend
|
||||
// Version field allows schema evolution
|
||||
|
||||
export type LLMModel = "claude-3-5-sonnet" | "gpt-4o" | "local";
|
||||
|
||||
export interface AgentTools {
|
||||
webSearch: boolean;
|
||||
pdfReader: boolean;
|
||||
}
|
||||
|
||||
export interface AgentNodeData extends Record<string, unknown> {
|
||||
label: string;
|
||||
systemPrompt: string;
|
||||
model: LLMModel;
|
||||
tools: AgentTools;
|
||||
isActive?: boolean; // set by WebSocket during execution
|
||||
}
|
||||
|
||||
export type EdgeType = "linear" | "conditional";
|
||||
|
||||
export interface ConditionalEdgeData {
|
||||
condition: string; // e.g. "rework" | "approve"
|
||||
}
|
||||
|
||||
// Blueprint JSON — versioned, stored in PostgreSQL
|
||||
export interface BlueprintNode {
|
||||
id: string;
|
||||
label: string;
|
||||
systemPrompt: string;
|
||||
model: LLMModel;
|
||||
tools: AgentTools;
|
||||
position: { x: number; y: number };
|
||||
}
|
||||
|
||||
export interface BlueprintEdge {
|
||||
id: string;
|
||||
source: string;
|
||||
target: string;
|
||||
type: EdgeType;
|
||||
condition?: string;
|
||||
}
|
||||
|
||||
export interface CouncilBlueprint {
|
||||
version: 1;
|
||||
id?: string;
|
||||
name: string;
|
||||
nodes: BlueprintNode[];
|
||||
edges: BlueprintEdge[];
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
// Council run (execution)
|
||||
export type RunStatus = "pending" | "running" | "completed" | "failed";
|
||||
|
||||
export interface CouncilRun {
|
||||
run_id: string;
|
||||
status: RunStatus;
|
||||
current_node?: string;
|
||||
result?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// WebSocket messages from backend
|
||||
export type WSMessageType = "node_enter" | "node_exit" | "run_complete" | "run_error";
|
||||
|
||||
export interface WSMessage {
|
||||
type: WSMessageType;
|
||||
node_id?: string;
|
||||
node_name?: string;
|
||||
result?: string;
|
||||
error?: string;
|
||||
}
|
||||
56
frontend/app/utils/api-client.ts
Normal file
56
frontend/app/utils/api-client.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// API client for the FastAPI backend
|
||||
import { CouncilBlueprint, CouncilRun } from "@/app/types/council";
|
||||
|
||||
const BASE_URL = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
|
||||
|
||||
async function request<T>(path: string, options?: RequestInit): Promise<T> {
|
||||
const res = await fetch(`${BASE_URL}${path}`, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
...options,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error(`API error ${res.status}: ${text}`);
|
||||
}
|
||||
return res.json() as Promise<T>;
|
||||
}
|
||||
|
||||
// Council blueprint CRUD
|
||||
export const councilApi = {
|
||||
list: () => request<CouncilBlueprint[]>("/api/councils/"),
|
||||
|
||||
get: (id: string) => request<CouncilBlueprint>(`/api/councils/${id}`),
|
||||
|
||||
create: (blueprint: CouncilBlueprint) =>
|
||||
request<CouncilBlueprint>("/api/councils/", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(blueprint),
|
||||
}),
|
||||
|
||||
update: (id: string, blueprint: CouncilBlueprint) =>
|
||||
request<CouncilBlueprint>(`/api/councils/${id}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(blueprint),
|
||||
}),
|
||||
|
||||
delete: (id: string) =>
|
||||
request<void>(`/api/councils/${id}`, { method: "DELETE" }),
|
||||
};
|
||||
|
||||
// Council run (execution)
|
||||
export const runApi = {
|
||||
start: (input_topic: string) =>
|
||||
request<CouncilRun>("/api/run", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ input_topic }),
|
||||
}),
|
||||
|
||||
status: (run_id: string) =>
|
||||
request<CouncilRun>(`/api/run/${run_id}`),
|
||||
};
|
||||
|
||||
// WebSocket URL helper
|
||||
export function wsUrl(run_id: string): string {
|
||||
const wsBase = BASE_URL.replace(/^http/, "ws");
|
||||
return `${wsBase}/ws/council/${run_id}`;
|
||||
}
|
||||
71
frontend/app/utils/blueprint-parser.ts
Normal file
71
frontend/app/utils/blueprint-parser.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
// Parser: React Flow graph state → CouncilBlueprint JSON (backend format)
|
||||
import { Node, Edge } from "@xyflow/react";
|
||||
import { AgentNodeData, BlueprintEdge, BlueprintNode, CouncilBlueprint, EdgeType } from "@/app/types/council";
|
||||
|
||||
export function parseGraphToBlueprint(
|
||||
nodes: Node<AgentNodeData>[],
|
||||
edges: Edge[],
|
||||
name: string,
|
||||
existingId?: string
|
||||
): CouncilBlueprint {
|
||||
const blueprintNodes: BlueprintNode[] = nodes.map((node) => ({
|
||||
id: node.id,
|
||||
label: node.data.label,
|
||||
systemPrompt: node.data.systemPrompt,
|
||||
model: node.data.model,
|
||||
tools: node.data.tools,
|
||||
position: { x: node.position.x, y: node.position.y },
|
||||
}));
|
||||
|
||||
const blueprintEdges: BlueprintEdge[] = edges.map((edge) => {
|
||||
const edgeType: EdgeType = (edge.data?.type as EdgeType) ?? "linear";
|
||||
const result: BlueprintEdge = {
|
||||
id: edge.id,
|
||||
source: edge.source,
|
||||
target: edge.target,
|
||||
type: edgeType,
|
||||
};
|
||||
if (edgeType === "conditional" && edge.data?.condition) {
|
||||
result.condition = edge.data.condition as string;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
return {
|
||||
version: 1,
|
||||
id: existingId,
|
||||
name,
|
||||
nodes: blueprintNodes,
|
||||
edges: blueprintEdges,
|
||||
};
|
||||
}
|
||||
|
||||
// Reverse: CouncilBlueprint → React Flow nodes/edges (for loading saved blueprints)
|
||||
export function parseBlueprintToGraph(blueprint: CouncilBlueprint): {
|
||||
nodes: Node<AgentNodeData>[];
|
||||
edges: Edge[];
|
||||
} {
|
||||
const nodes: Node<AgentNodeData>[] = blueprint.nodes.map((n) => ({
|
||||
id: n.id,
|
||||
type: "agentNode",
|
||||
position: n.position,
|
||||
data: {
|
||||
label: n.label,
|
||||
systemPrompt: n.systemPrompt,
|
||||
model: n.model,
|
||||
tools: n.tools,
|
||||
},
|
||||
}));
|
||||
|
||||
const edges: Edge[] = blueprint.edges.map((e) => ({
|
||||
id: e.id,
|
||||
source: e.source,
|
||||
target: e.target,
|
||||
type: e.type === "conditional" ? "conditionalEdge" : "default",
|
||||
data: { type: e.type, condition: e.condition },
|
||||
label: e.type === "conditional" ? e.condition : undefined,
|
||||
animated: e.type === "conditional",
|
||||
}));
|
||||
|
||||
return { nodes, edges };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue