diff --git a/rag/bin/rag-web.py b/rag/bin/rag-web.py
index 8635fde..1059125 100644
--- a/rag/bin/rag-web.py
+++ b/rag/bin/rag-web.py
@@ -137,7 +137,8 @@
const parts=buf.split('\\n\\n'); buf=parts.pop();
for(const p of parts){
const line=p.split('\\n').find(l=>l.startsWith('data:')); if(!line) continue;
- const ev=JSON.parse(line.slice(5));
+ const data=line.slice(5).trim(); if(!data||data==='[DONE]') continue;
+ const ev=JSON.parse(data);
if(ev.token){text+=ev.token; body.innerHTML=render(text);
ad.scrollIntoView({block:'end'})}
if(ev.error){body.innerHTML+='
'+esc(ev.error)+'
'}
diff --git a/tests/test_web.py b/tests/test_web.py
index e362cea..a1d8497 100644
--- a/tests/test_web.py
+++ b/tests/test_web.py
@@ -95,6 +95,12 @@ def test_page_asks_for_a_key_and_sends_it(web):
assert "res.status===401" in body
+def test_page_skips_the_done_sentinel(web):
+ """The [DONE] line is not JSON; the page must skip it, not parse it."""
+ body = get(web.url + "/").read().decode()
+ assert "data==='[DONE]'" in body
+
+
def test_models_endpoint_names_the_rag_model(web):
body = json.load(get(web.url + "/v1/models"))
assert body["data"][0]["id"] == "cpts-notes-rag"