( title: string, messages: ExportMessage[], createdAt: number, labels: ExportLabels )
| 100 | * 格式化对话为纯文本格式 |
| 101 | */ |
| 102 | export function formatAsPlainText( |
| 103 | title: string, |
| 104 | messages: ExportMessage[], |
| 105 | createdAt: number, |
| 106 | labels: ExportLabels |
| 107 | ): string { |
| 108 | const lines: string[] = [] |
| 109 | |
| 110 | // 标题 |
| 111 | lines.push(`${title}`) |
| 112 | lines.push(`${labels.createdAt}: ${dayjs(createdAt).format('YYYY-MM-DD HH:mm:ss')}`) |
| 113 | lines.push('') |
| 114 | lines.push('='.repeat(50)) |
| 115 | lines.push('') |
| 116 | |
| 117 | // 消息 |
| 118 | for (const msg of messages) { |
| 119 | const time = dayjs(msg.timestamp).format('YYYY-MM-DD HH:mm:ss') |
| 120 | const roleLabel = msg.role === 'user' ? labels.user : labels.assistant |
| 121 | |
| 122 | lines.push(`[${roleLabel}] ${time}`) |
| 123 | lines.push('') |
| 124 | lines.push(msg.content) |
| 125 | lines.push('') |
| 126 | lines.push('-'.repeat(50)) |
| 127 | lines.push('') |
| 128 | } |
| 129 | |
| 130 | return lines.join('\n') |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * 清理文件名中的非法字符 |
no outgoing calls
no test coverage detected