diff --git a/vibn-frontend/components/vibn-chat/chat-panel.tsx b/vibn-frontend/components/vibn-chat/chat-panel.tsx index bb0ac419..531dcf9f 100644 --- a/vibn-frontend/components/vibn-chat/chat-panel.tsx +++ b/vibn-frontend/components/vibn-chat/chat-panel.tsx @@ -787,7 +787,8 @@ export function ChatPanel({ const [threadsLoaded, setThreadsLoaded] = useState(false); const [activeThread, setActiveThread] = useState(null); const [messages, setMessages] = useState([]); - const [input, setInput] = useState(""); + const [input, setInput] = useState(""); + const [chatMode, setChatMode] = useState<"collaborate" | "vibe" | "delegate">("collaborate"); const [sending, setSending] = useState(false); const [showThreads, setShowThreads] = useState(false); const [mcpToken, setMcpToken] = useState(null); @@ -1029,6 +1030,33 @@ export function ChatPanel({ abortRef.current = controller; try { + // If Delegate mode is selected, route to the background runner instead of streaming chat! + if (chatMode === "delegate") { + const r = await fetch( + `/api/projects/${projectId}/agent/sessions`, + { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + appName: "frontend", + appPath: ".", + task: text, + }), + }, + ); + if (!r.ok) { + const err = await r.json().catch(() => ({})); + throw new Error(err.error || `HTTP ${r.status}`); + } + + setMessages((prev) => [ + ...prev, + { role: "assistant", content: "I have started a background runner for this task. You can safely close this browser or work on something else. I will commit and ship the code when I am finished!" }, + ]); + setSending(false); + return; + } + const res = await fetch("/api/chat", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -1037,6 +1065,7 @@ export function ChatPanel({ message: text, workspace, mcp_token: mcpToken, + chatMode, }), signal: controller.signal, });