From 56cf1a3efdbf5dbb1f4fbd0e1cdaa1ba833330da Mon Sep 17 00:00:00 2001 From: Muyue Date: Sat, 18 Oct 2025 23:50:39 +0200 Subject: [PATCH] Clean up dead code and unused imports - Remove unused Readable import from mistralClient.js - Remove unused generateAgentResponse streaming function - Remove unused parseStreamResponse helper function - Remove unused updateDocumentFromMessage from collaboration store - Remove unused documentVersions state from store - Remove unused getRandomName function from nameGenerator.js - Clean up store exports and clearCurrentSession function --- backend/src/services/mistralClient.js | 64 --------------------------- backend/src/services/nameGenerator.js | 4 -- frontend/src/stores/collaboration.js | 21 --------- 3 files changed, 89 deletions(-) diff --git a/backend/src/services/mistralClient.js b/backend/src/services/mistralClient.js index 6c14abf..5d76744 100644 --- a/backend/src/services/mistralClient.js +++ b/backend/src/services/mistralClient.js @@ -1,5 +1,4 @@ import dotenv from 'dotenv' -import { Readable } from 'stream' dotenv.config() @@ -69,69 +68,6 @@ async function callMistralAPI(messages, options = {}) { return response } -/** - * Parse streaming response - */ -async function* parseStreamResponse(reader) { - const decoder = new TextDecoder() - let buffer = '' - - while (true) { - const { done, value } = await reader.read() - if (done) break - - buffer += decoder.decode(value, { stream: true }) - const lines = buffer.split('\n') - buffer = lines.pop() || '' - - for (const line of lines) { - if (line.startsWith('data: ')) { - const data = line.slice(6) - if (data === '[DONE]') continue - try { - const json = JSON.parse(data) - if (json.choices?.[0]?.delta?.content) { - yield json.choices[0].delta.content - } - } catch (e) { - // Skip invalid JSON - } - } - } - } -} - -/** - * Generate agent response with streaming thoughts - */ -export async function* generateAgentResponse(agentName, prompt, currentDocument = '', onThought = null) { - const systemPrompt = getAgentPrompt(agentName) - - const messages = [ - { role: 'system', content: systemPrompt }, - { role: 'user', content: `Project description: ${prompt}\n\nCurrent document:\n${currentDocument}` } - ] - - try { - const response = await callMistralAPI(messages, { stream: true }) - const reader = response.body.getReader() - let fullContent = '' - - for await (const chunk of parseStreamResponse(reader)) { - fullContent += chunk - if (onThought) { - onThought(chunk) - } - yield chunk - } - - return fullContent - } catch (error) { - console.error(`Error generating response from ${agentName}:`, error) - return `Error: ${error.message}` - } -} - /** * Generate agent response (non-streaming version for simpler integration) */ diff --git a/backend/src/services/nameGenerator.js b/backend/src/services/nameGenerator.js index 931a80c..d0e54e8 100644 --- a/backend/src/services/nameGenerator.js +++ b/backend/src/services/nameGenerator.js @@ -31,7 +31,3 @@ export function getRandomNames(count) { const shuffled = [...allNames].sort(() => Math.random() - 0.5) return shuffled.slice(0, count) } - -export function getRandomName() { - return allNames[Math.floor(Math.random() * allNames.length)] -} diff --git a/frontend/src/stores/collaboration.js b/frontend/src/stores/collaboration.js index e56035f..bd50c3d 100644 --- a/frontend/src/stores/collaboration.js +++ b/frontend/src/stores/collaboration.js @@ -7,7 +7,6 @@ export const useCollaborationStore = defineStore('collaboration', () => { const loading = ref(false) const error = ref(null) const currentDocument = ref('') - const documentVersions = ref([]) const currentRound = ref(0) const conversationHistory = ref([]) @@ -138,23 +137,6 @@ export const useCollaborationStore = defineStore('collaboration', () => { } } - /** - * Update document from WebSocket message - */ - function updateDocumentFromMessage(message) { - if (message.type === 'initial_document_created') { - currentDocument.value = message.content - currentRound.value = 1 - } else if (message.type === 'document_modified') { - currentDocument.value = message.content - } else if (message.type === 'round_complete') { - conversationHistory.value.push({ - roundNumber: message.roundNumber, - agentsMadeChanges: message.agentsMadeChanges - }) - } - } - /** * Complete a session */ @@ -184,7 +166,6 @@ export const useCollaborationStore = defineStore('collaboration', () => { function clearCurrentSession() { currentSession.value = null currentDocument.value = '' - documentVersions.value = [] currentRound.value = 0 conversationHistory.value = [] } @@ -213,14 +194,12 @@ export const useCollaborationStore = defineStore('collaboration', () => { loading, error, currentDocument, - documentVersions, currentRound, conversationHistory, createSession, startSession, runRound, getSession, - updateDocumentFromMessage, completeSession, clearCurrentSession, downloadDocument