diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index b804c66..38abf90 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -172,6 +172,32 @@ async function fetchOIDCConfig(): Promise { return response.json() } +function parseSSE(chunk: string, onMessage: (message: string) => void) { + const events = chunk.split(/\n\n+/) + for (const event of events) { + if (!event.trim()) continue + const lines = event.split(/\n/) + let data = '' + for (const line of lines) { + const [field, ...rest] = line.split(':') + if (field === 'data') { + data += rest.join(':').trim() + } + } + if (data && data !== '[DONE]') { + try { + const parsed = JSON.parse(data) + const text = parsed?.choices?.[0]?.delta?.content + if (typeof text === 'string') { + onMessage(text) + } + } catch { + onMessage(data) + } + } + } +} + async function handleRedirectCallback(): Promise { const params = new URLSearchParams(window.location.search) const code = params.get('code')