"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { CornerDownLeftIcon } from "lucide-react"; import { GraphView } from "@/components/graph-view"; import { SidebarToggle } from "@/components/sidebar"; import { StatsBar } from "@/components/stats-bar"; import type { ChatSettings, TurnUsage } from "@/src/core"; /** * Home — the knowledge graph is the main view (placeholder until the graph * pipeline lands), with the new-session blob docked below it. Sessions live * in the toggleable sidebar. */ export function Home() { const router = useRouter(); const [topic, setTopic] = useState(""); const [busy, setBusy] = useState(false); // The model+thinking selection made pre-chat — lifted from the StatsBar's // ModelControl, carried to the chat POST then PUT-on-create (the model // picker defers its save when chatId is empty; see components/model-picker). const [settings, setSettings] = useState(undefined); const start = async () => { const t = topic.trim(); if (!t || busy) return; setBusy(true); try { const res = await fetch("/api/chats", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title: t }), }); const { id } = (await res.json()) as { id: string }; if (settings) { // Best-effort persist — the selection was made pre-chat. await fetch(`/api/chats/${id}/settings`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(settings), }).catch(() => {}); } router.push(`/chat/${id}?prompt=${encodeURIComponent(t)}`); } catch { setBusy(false); } }; return (
{/* Graph — the main view (W4: sigma.js render of the derived graph). */}
{/* New session — same floating blob as the chat composer. */}
{/* Matches chat.tsx's DOCK geometry (max-w-[46rem] px-4) so nothing shifts when a session starts (owner). */}
{ e.preventDefault(); void start(); }} >