| 709 | } |
| 710 | |
| 711 | function getSessionLabel(session: { sessionId: string; title: string | null; messages: ReadonlyArray<{ role: string; content: string }> }): string { |
| 712 | if (session.title) return session.title; |
| 713 | // 后端会在第一条用户消息发送时立即把消息内容持久化为占位标题。 |
| 714 | // 这里处理的是"已有消息但标题还没同步回来"的短暂中间态(乐观显示)。 |
| 715 | const firstUserMsg = session.messages.find((m) => m.role === "user")?.content?.trim(); |
| 716 | if (firstUserMsg) { |
| 717 | const oneLine = firstUserMsg.replace(/\s+/g, " "); |
| 718 | return oneLine.length > 20 ? `${oneLine.slice(0, 20)}…` : oneLine; |
| 719 | } |
| 720 | return "新会话"; |
| 721 | } |
| 722 | |
| 723 | function formatRelativeTime(sessionId: string): string { |
| 724 | const rawTs = Number(sessionId.split("-")[0]); |