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
This commit is contained in:
parent
b4ccf03b8e
commit
56cf1a3efd
@ -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)
|
||||
*/
|
||||
|
||||
@ -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)]
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user