Files
makelore/electron/coding-runtime/conversation-title.ts

15 lines
885 B
TypeScript

import type { ConversationNode } from './contracts';
import { OPEN_WORK_PROMPT } from '../../shared/coding-work-preview';
import { CONTINUE_CODING_PROMPT } from '../../shared/coding-recovery';
/** 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 === OPEN_WORK_PROMPT || text === CONTINUE_CODING_PROMPT) return null;
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);
}