MCPcopy Create free account
hub / github.com/microsoft/vscode-extension-samples / getTopic

Function getTopic

chat-sample/src/simple.ts:207–223  ·  view source on GitHub ↗
(history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>)

Source from the content-addressed store, hash-verified

205
206// Get a random topic that the cat has not taught in the chat history yet
207function 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}

Callers 1

handlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected