@whyuds/coding-converse
Version:
An MCP server that enables interactive conversations between AI code editors and users for collaborative problem-solving
82 lines • 2.92 kB
JavaScript
export class ConversationManager {
constructor() {
this.conversations = new Map();
this.currentConversationId = null;
}
startNewConversation(topic) {
const id = this.generateConversationId();
const conversation = {
id,
topic,
startTime: new Date(),
exchanges: []
};
this.conversations.set(id, conversation);
this.currentConversationId = id;
return id;
}
addExchange(question, response) {
if (!this.currentConversationId) {
throw new Error('No active conversation. Start a conversation first.');
}
const conversation = this.conversations.get(this.currentConversationId);
if (!conversation) {
throw new Error('Current conversation not found.');
}
conversation.exchanges.push({
question,
response,
timestamp: new Date()
});
}
endConversation(summary) {
if (!this.currentConversationId) {
throw new Error('No active conversation to end.');
}
const conversation = this.conversations.get(this.currentConversationId);
if (!conversation) {
throw new Error('Current conversation not found.');
}
conversation.endTime = new Date();
conversation.summary = summary;
this.currentConversationId = null;
}
getCurrentConversation() {
if (!this.currentConversationId) {
return null;
}
return this.conversations.get(this.currentConversationId) || null;
}
getConversationHistory() {
return Array.from(this.conversations.values());
}
getConversationById(id) {
return this.conversations.get(id) || null;
}
generateConversationId() {
return `conv_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
exportConversation(id) {
const conversation = this.conversations.get(id);
if (!conversation) {
throw new Error('Conversation not found.');
}
const lines = [
`# Conversation: ${conversation.topic}`,
`**Started:** ${conversation.startTime.toISOString()}`,
conversation.endTime ? `**Ended:** ${conversation.endTime.toISOString()}` : '**Status:** Active',
conversation.summary ? `**Summary:** ${conversation.summary}` : '',
'',
'## Exchanges',
''
];
conversation.exchanges.forEach((exchange, index) => {
lines.push(`### Exchange ${index + 1} (${exchange.timestamp.toLocaleTimeString()})`);
lines.push(`**Question:** ${exchange.question}`);
lines.push(`**Response:** ${exchange.response}`);
lines.push('');
});
return lines.join('\n');
}
}
//# sourceMappingURL=conversation-manager.js.map