( fullHistory: ChatHistoryItem[], compactionIndex: number | null, )
| 220 | } |
| 221 | |
| 222 | export function getHistoryForLLM( |
| 223 | fullHistory: ChatHistoryItem[], |
| 224 | compactionIndex: number | null, |
| 225 | ): ChatHistoryItem[] { |
| 226 | if (compactionIndex === null || compactionIndex >= fullHistory.length) { |
| 227 | return fullHistory; |
| 228 | } |
| 229 | |
| 230 | // Include system message (if at index 0) and everything from compaction index forward |
| 231 | const systemMessage = |
| 232 | fullHistory[0]?.message?.role === "system" ? fullHistory[0] : null; |
| 233 | const messagesFromCompaction = fullHistory.slice(compactionIndex); |
| 234 | |
| 235 | return systemMessage && compactionIndex > 0 |
| 236 | ? [systemMessage, ...messagesFromCompaction] |
| 237 | : messagesFromCompaction; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Parameters for auto-compaction check |
no outgoing calls
no test coverage detected