( title: string, messages: ExportMessage[], createdAt: number, labels: ExportLabels )
| 64 | * 格式化对话为 Markdown 格式 |
| 65 | */ |
| 66 | export function formatAsMarkdown( |
| 67 | title: string, |
| 68 | messages: ExportMessage[], |
| 69 | createdAt: number, |
| 70 | labels: ExportLabels |
| 71 | ): string { |
| 72 | const lines: string[] = [] |
| 73 | |
| 74 | // 标题 |
| 75 | lines.push(`# ${title}`) |
| 76 | lines.push('') |
| 77 | lines.push(`> ${labels.createdAt}: ${dayjs(createdAt).format('YYYY-MM-DD HH:mm:ss')}`) |
| 78 | lines.push('') |
| 79 | lines.push('---') |
| 80 | lines.push('') |
| 81 | |
| 82 | // 消息 |
| 83 | for (const msg of messages) { |
| 84 | const time = dayjs(msg.timestamp).format('YYYY-MM-DD HH:mm:ss') |
| 85 | const roleLabel = msg.role === 'user' ? labels.user : labels.assistant |
| 86 | |
| 87 | lines.push(`### ${roleLabel}`) |
| 88 | lines.push(`*${time}*`) |
| 89 | lines.push('') |
| 90 | lines.push(msg.content) |
| 91 | lines.push('') |
| 92 | lines.push('---') |
| 93 | lines.push('') |
| 94 | } |
| 95 | |
| 96 | return lines.join('\n') |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * 格式化对话为纯文本格式 |
no outgoing calls
no test coverage detected