From a5f63e8aba1834ba8f905d2f5465dd7b94e8e149 Mon Sep 17 00:00:00 2001 From: Hermes Date: Thu, 9 Apr 2026 21:18:50 -0500 Subject: [PATCH] New session creation page, + button on History - /history/new: compose first message, creates web session, sends, redirects - POST /api/sessions proxy route - History page gets + button in header --- app/api/sessions/route.ts | 21 +++++++++++ app/history/new/page.tsx | 76 +++++++++++++++++++++++++++++++++++++++ app/history/page.tsx | 14 ++++++-- 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 app/api/sessions/route.ts create mode 100644 app/history/new/page.tsx diff --git a/app/api/sessions/route.ts b/app/api/sessions/route.ts new file mode 100644 index 0000000..69957e3 --- /dev/null +++ b/app/api/sessions/route.ts @@ -0,0 +1,21 @@ +import { NextRequest, NextResponse } from "next/server"; + +const BACKEND = process.env.HERMES_BACKEND_URL || "http://127.0.0.1:8643"; + +export async function POST(req: NextRequest) { + const body = await req.text(); + try { + const res = await fetch(BACKEND + "/api/sessions", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body, + }); + const data = await res.text(); + return new NextResponse(data, { + status: res.status, + headers: { "content-type": "application/json" }, + }); + } catch { + return NextResponse.json({ error: "backend unreachable" }, { status: 502 }); + } +} diff --git a/app/history/new/page.tsx b/app/history/new/page.tsx new file mode 100644 index 0000000..8098186 --- /dev/null +++ b/app/history/new/page.tsx @@ -0,0 +1,76 @@ +"use client"; + +import { useState } from "react"; +import { useRouter } from "next/navigation"; +import { ArrowLeft, Send, Loader2 } from "lucide-react"; +import Link from "next/link"; + +export default function NewSessionPage() { + const router = useRouter(); + const [message, setMessage] = useState(""); + const [sending, setSending] = useState(false); + + const create = async () => { + if (!message.trim() || sending) return; + setSending(true); + try { + // Create session + const res = await fetch("/api/sessions", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ source: "web" }), + }); + const data = await res.json(); + const sessionId = data.session?.id; + if (!sessionId) throw new Error("No session ID"); + + // Send first message + await fetch("/api/sessions/" + sessionId + "/chat", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ message: message.trim() }), + }); + + router.push("/history/" + sessionId); + } catch { + setSending(false); + } + }; + + return ( +
+
+ + + +

New Session

+
+ +