Merge pull request #4 from dannyjosephgarcia/WOOL-22

feature: local and production level connection
This commit is contained in:
Danny Garcia 2026-01-16 12:52:51 -06:00 committed by GitHub
commit 5eb6f9ea31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 19 deletions

View File

@ -1,7 +1,8 @@
import type { ChatMode } from '@/types/chat'
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000'
const USE_MOCK_DATA = true // Set to false when backend is ready
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000'
const API_ENDPOINT = import.meta.env.VITE_API_ENDPOINT || '/chat/stream'
const USE_MOCK_DATA = false // Set to true to use mock data for testing
// Session management
export const getChatSessionId = (): string | null => {
@ -102,15 +103,14 @@ class ApiClient {
yield { type: 'session_id', data: actualSessionId }
try {
const response = await fetch(`${API_BASE_URL}/api/chat/stream`, {
const response = await fetch(`${API_BASE_URL}${API_ENDPOINT}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
question,
mode,
sessionId: actualSessionId,
message: question,
conversation_id: actualSessionId,
}),
})
@ -141,24 +141,19 @@ class ApiClient {
if (line.startsWith('data: ')) {
const data = line.slice(6)
if (data === '[DONE]') {
yield { type: 'done', data: null }
return
}
try {
const parsed = JSON.parse(data)
if (parsed.type === 'error') {
yield { type: 'error', data: parsed.message }
} else if (parsed.content) {
if (parsed.type === 'chunk' && parsed.content) {
yield { type: 'chunk', data: parsed.content }
} else {
// Raw string chunk
yield { type: 'chunk', data: data }
} else if (parsed.type === 'done') {
yield { type: 'done', data: null }
return
} else if (parsed.type === 'error') {
yield { type: 'error', data: parsed.message || 'Unknown error' }
return
}
} catch {
// Raw string chunk (not JSON)
yield { type: 'chunk', data: data }
// Skip non-JSON lines
}
}
}