( compactionIndex: number | null | undefined, model: ModelConfig, llmApi: BaseLlmApi, )
| 165 | |
| 166 | // Helper function to get streaming response based on compaction state |
| 167 | async function getStreamingResponse( |
| 168 | compactionIndex: number | null | undefined, |
| 169 | model: ModelConfig, |
| 170 | llmApi: BaseLlmApi, |
| 171 | ): Promise<string> { |
| 172 | const abortController = new AbortController(); |
| 173 | |
| 174 | if (compactionIndex !== null && compactionIndex !== undefined) { |
| 175 | // Use service to compute history for LLM |
| 176 | const historyForLLM = |
| 177 | services.chatHistory.getHistoryForLLM(compactionIndex); |
| 178 | |
| 179 | return await streamChatResponse( |
| 180 | historyForLLM, |
| 181 | model, |
| 182 | llmApi, |
| 183 | abortController, |
| 184 | ); |
| 185 | } else { |
| 186 | // No compaction - get full history from service |
| 187 | return await streamChatResponse( |
| 188 | services.chatHistory.getHistory(), |
| 189 | model, |
| 190 | llmApi, |
| 191 | abortController, |
| 192 | ); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // Helper function to process and output response in headless mode |
| 197 | function processAndOutputResponse( |
no test coverage detected