(
messages: Array<{ senderName: string; content: string }>,
maxCharsPerSegment: number
)
| 153 | } |
| 154 | |
| 155 | export function splitIntoSegments( |
| 156 | messages: Array<{ senderName: string; content: string }>, |
| 157 | maxCharsPerSegment: number |
| 158 | ): Array<Array<{ senderName: string; content: string }>> { |
| 159 | const segments: Array<Array<{ senderName: string; content: string }>> = [] |
| 160 | let currentSegment: Array<{ senderName: string; content: string }> = [] |
| 161 | let currentLength = 0 |
| 162 | |
| 163 | for (const msg of messages) { |
| 164 | const msgLength = msg.senderName.length + msg.content.length + 3 |
| 165 | if (currentLength + msgLength > maxCharsPerSegment && currentSegment.length > 0) { |
| 166 | segments.push(currentSegment) |
| 167 | currentSegment = [] |
| 168 | currentLength = 0 |
| 169 | } |
| 170 | currentSegment.push(msg) |
| 171 | currentLength += msgLength |
| 172 | } |
| 173 | if (currentSegment.length > 0) segments.push(currentSegment) |
| 174 | return segments |
| 175 | } |
| 176 | |
| 177 | // ==================== Prompt builders ==================== |
| 178 |
no outgoing calls
no test coverage detected