| 22 | } |
| 23 | |
| 24 | export function formatQueuedPreview( |
| 25 | messages: Array<{ content: string }>, |
| 26 | maxChars: number = 60, |
| 27 | ): string { |
| 28 | if (messages.length === 0) return '' |
| 29 | |
| 30 | const latestMessage = messages[messages.length - 1].content |
| 31 | const singleLine = latestMessage.replace(/\s+/g, ' ').trim() |
| 32 | if (!singleLine) return '' |
| 33 | |
| 34 | const countSuffix = messages.length > 1 ? ` (+ ${messages.length - 1})` : '' |
| 35 | const prefix = '↑ ' |
| 36 | const suffix = ' ↑' |
| 37 | const availableChars = |
| 38 | maxChars - prefix.length - suffix.length - countSuffix.length |
| 39 | |
| 40 | let messagePreview = singleLine |
| 41 | if (singleLine.length > availableChars) { |
| 42 | messagePreview = |
| 43 | singleLine.slice(0, Math.max(0, availableChars - 3)) + '...' |
| 44 | } |
| 45 | |
| 46 | return `${prefix}${messagePreview}${countSuffix}${suffix}` |
| 47 | } |