import type { ConversationNode } from './contracts'; /** Only real user messages name a conversation; no model call or tool output. */ export function firstMessageTitle(node: ConversationNode): string | null { if (node.kind !== 'message' || node.role !== 'user' || node.status !== 'complete') return null; const text = node.blocks.flatMap((block) => block.kind === 'text' ? [block.text] : []).join('\n').trim(); if (text.startsWith('/')) return null; const firstLine = text.split(/\r?\n/)[0].replace(/\s+/g, ' ').trim(); return [...firstLine].slice(0, 32).join('') || (node.blocks.some((block) => block.kind === 'image') ? '附件对话' : null); }