| 205 | |
| 206 | // Get a random topic that the cat has not taught in the chat history yet |
| 207 | function getTopic(history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>): string { |
| 208 | const topics = ['linked list', 'recursion', 'stack', 'queue', 'pointers']; |
| 209 | // Filter the chat history to get only the responses from the cat |
| 210 | const previousCatResponses = history.filter(h => { |
| 211 | return h instanceof vscode.ChatResponseTurn && h.participant === CAT_PARTICIPANT_ID; |
| 212 | }) as vscode.ChatResponseTurn[]; |
| 213 | // Filter the topics to get only the topics that have not been taught by the cat yet |
| 214 | const topicsNoRepetition = topics.filter(topic => { |
| 215 | return !previousCatResponses.some(catResponse => { |
| 216 | return catResponse.response.some(r => { |
| 217 | return r instanceof vscode.ChatResponseMarkdownPart && r.value.value.includes(topic); |
| 218 | }); |
| 219 | }); |
| 220 | }); |
| 221 | |
| 222 | return topicsNoRepetition[Math.floor(Math.random() * topicsNoRepetition.length)] || 'I have taught you everything I know. Meow!'; |
| 223 | } |