MCPcopy
hub / github.com/CopilotKit/CopilotKit / TeamsConversationStore

Class TeamsConversationStore

packages/bot-teams/src/conversation-store.ts:53–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 * implement {@link ConversationStore} against a real datastore and pass it in.
52 */
53export class TeamsConversationStore implements ConversationStore {
54 private readonly history = new Map<string, StoredMessage[]>();
55
56 /**
57 * Append a user message to the conversation transcript. Accepts plain text or
58 * multimodal content parts (uploaded files); empty content is ignored.
59 */
60 recordUser(
61 conversationKey: string,
62 content: string | AgentContentPart[],
63 ): void {
64 if (typeof content === "string" ? !content : content.length === 0) return;
65 this.append(conversationKey, { id: randomUUID(), role: "user", content });
66 }
67
68 /** Append an assistant message to the conversation transcript. */
69 recordAssistant(conversationKey: string, content: string): void {
70 if (!content) return;
71 this.append(conversationKey, {
72 id: randomUUID(),
73 role: "assistant",
74 content,
75 });
76 }
77
78 /** The accumulated transcript as bot-ui `ThreadMessage`s (backs `thread.getMessages()`). */
79 getTranscript(conversationKey: string): ThreadMessage[] {
80 const transcript = this.history.get(conversationKey) ?? [];
81 return transcript.map((m) => ({
82 text: contentToText(m.content),
83 isBot: m.role === "assistant",
84 }));
85 }
86
87 private append(conversationKey: string, message: StoredMessage): void {
88 const existing = this.history.get(conversationKey);
89 if (existing) existing.push(message);
90 else this.history.set(conversationKey, [message]);
91 }
92
93 async getOrCreate(
94 conversationKey: string,
95 _replyTarget: ReplyTarget,
96 makeAgent: (threadId: string) => AbstractAgent,
97 ): Promise<AgentSession> {
98 // Fresh AG-UI thread per turn. Our `history` map is the durable record, so
99 // the server-side thread only needs to live for this turn (mirrors the
100 // Slack adapter's rationale for not reusing a stable thread id).
101 const threadId = `teams-${conversationKey}-${randomUUID()}`;
102 const agent = makeAgent(threadId);
103 const transcript = this.history.get(conversationKey) ?? [];
104 (agent as unknown as { messages: StoredMessage[] }).messages = [
105 ...transcript,
106 ];
107 return { agent };
108 }
109}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…