"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { CornerDownLeftIcon } from "lucide-react"; import { GraphView } from "@/components/graph-view"; import { GraphContextControl, effectiveContextTokens } from "@/components/graph-context-control"; import { useDefaultSettings } from "@/components/default-settings"; import { DictationBar, useDictation } from "@/components/dictation"; 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, full-bleed edge to edge * (owner, graph-view round 1): the canvas owns the whole column, running * under the header and the new-session dock, both of which float over it * with no gradient scrims. Sessions live in the toggleable sidebar. */ export function Home({ initialSettings }: { initialSettings: ChatSettings | null }) { const router = useRouter(); const [topic, setTopic] = useState(""); // Voice dictation (STT wave, 2026-09-17): finals append at the end of the // topic draft; the strip lives in the stats bar's middle slot. const dictation = useDictation({ append: (t) => setTopic((v) => (v ? v.replace(/\s+$/, "") + " " + t : t)), }); const [busy, setBusy] = useState(false); // THE default settings (owner, 2026-09-18): this topic dock IS the // settings page for the default model — no baked-in default exists; the // user's last choice (server-rendered in via initialSettings, shared // with /chat/new through data/default-settings.json) IS the default. // Still 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, save: saveDraft } = useDefaultSettings(initialSettings); 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 (