Fix: Strip newlines and extra text from generated title

This commit is contained in:
2026-03-16 22:21:09 -07:00
parent 062592df6a
commit f9d54527c7

View File

@@ -35,7 +35,11 @@ export const generateTitleWithAI = async messages => {
if (!r.ok) return null;
const d = await r.json();
const rawTitle = d.choices?.[0]?.message?.content?.trim() || '';
return rawTitle.replace(/[<>:"/\\|?*\x00-\x1f`]/g, '').trim().replace(/\.$/, '') || null;
// Grab only the first line to strip out any trailing explanations or extra output after a newline
const firstLineTitle = rawTitle.split('\n')[0];
return firstLineTitle.replace(/[<>:"/\\|?*\x00-\x1f`]/g, '').trim().replace(/\.$/, '') || null;
} catch (e) {
console.error('AI title gen failed:', e);
return null;