changes
This commit is contained in:
@@ -13,6 +13,9 @@ export async function POST(request: NextRequest) {
|
|||||||
try {
|
try {
|
||||||
const { model, messages } = await request.json();
|
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) {
|
if (!model || !messages || !Array.isArray(messages) || messages.length === 0) {
|
||||||
return NextResponse.json({ error: 'Model and messages array are required' }, { status: 400 });
|
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 ? '...' : '');
|
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 });
|
return NextResponse.json({ title });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
|
|||||||
@@ -466,16 +466,25 @@ export default function ChatLayout() {
|
|||||||
});
|
});
|
||||||
const titleData = await titleRes.json();
|
const titleData = await titleRes.json();
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('[Title] API response:', titleData);
|
||||||
|
|
||||||
if (titleData.title) {
|
if (titleData.title) {
|
||||||
chatTitle = titleData.title;
|
chatTitle = titleData.title;
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('[Title] Setting chat title to:', chatTitle);
|
||||||
|
|
||||||
// Update title in database
|
// Update title in database
|
||||||
await fetch(`/api/chats/${savedChatId}`, {
|
const patchRes = await fetch(`/api/chats/${savedChatId}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ title: chatTitle }),
|
body: JSON.stringify({ title: chatTitle }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('[Title] PATCH response status:', patchRes.status);
|
||||||
|
|
||||||
// Update title in local state
|
// Update title in local state
|
||||||
setChats((prev) =>
|
setChats((prev) =>
|
||||||
prev.map((c) => (c.id === savedChatId ? { ...c, title: chatTitle } : c))
|
prev.map((c) => (c.id === savedChatId ? { ...c, title: chatTitle } : c))
|
||||||
|
|||||||
Reference in New Issue
Block a user