diff --git a/app/api/chat/title/route.ts b/app/api/chat/title/route.ts index b1a696f..990ea61 100644 --- a/app/api/chat/title/route.ts +++ b/app/api/chat/title/route.ts @@ -13,6 +13,9 @@ export async function POST(request: NextRequest) { try { const { model, messages } = await request.json(); + // eslint-disable-next-line no-console + console.log('[Title API] Request received:', { model, messageCount: messages?.length }); + if (!model || !messages || !Array.isArray(messages) || messages.length === 0) { return NextResponse.json({ error: 'Model and messages array are required' }, { status: 400 }); } @@ -54,6 +57,9 @@ export async function POST(request: NextRequest) { title = firstUserMessage.slice(0, 30) + (firstUserMessage.length > 30 ? '...' : ''); } + // eslint-disable-next-line no-console + console.log('[Title API] Generated title:', title); + return NextResponse.json({ title }); } catch (error) { // eslint-disable-next-line no-console diff --git a/components/Chat/ChatLayout.tsx b/components/Chat/ChatLayout.tsx index 6c2adb7..ac6de0c 100644 --- a/components/Chat/ChatLayout.tsx +++ b/components/Chat/ChatLayout.tsx @@ -466,16 +466,25 @@ export default function ChatLayout() { }); const titleData = await titleRes.json(); + // eslint-disable-next-line no-console + console.log('[Title] API response:', titleData); + if (titleData.title) { chatTitle = titleData.title; + // eslint-disable-next-line no-console + console.log('[Title] Setting chat title to:', chatTitle); + // Update title in database - await fetch(`/api/chats/${savedChatId}`, { + const patchRes = await fetch(`/api/chats/${savedChatId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: chatTitle }), }); + // eslint-disable-next-line no-console + console.log('[Title] PATCH response status:', patchRes.status); + // Update title in local state setChats((prev) => prev.map((c) => (c.id === savedChatId ? { ...c, title: chatTitle } : c))