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