Skip to content

Commit 1625cdb

Browse files
committed
fix(ai-client): warn when receiving deprecated [DONE] sentinel
Old servers still emit `data: [DONE]\n\n` after the stream. The client already skips it, but now logs a deprecation warning so users know to upgrade their @tanstack/ai server package.
1 parent dc385ee commit 1625cdb

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

packages/typescript/ai-client/src/connection-adapters.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,12 @@ export function fetchServerSentEvents(
312312
// Handle Server-Sent Events format
313313
const data = line.startsWith('data: ') ? line.slice(6) : line
314314

315-
if (data === '[DONE]') continue
315+
if (data === '[DONE]') {
316+
console.warn(
317+
'[@tanstack/ai-client] Received [DONE] sentinel. This is deprecated — upgrade your @tanstack/ai server package. RUN_FINISHED is the stream terminator.',
318+
)
319+
continue
320+
}
316321

317322
try {
318323
const parsed: StreamChunk = JSON.parse(data)

packages/typescript/ai-client/src/sse-parser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ export async function* parseSSEResponse(
6464
for await (const line of readStreamLines(reader, abortSignal)) {
6565
const data = line.startsWith('data: ') ? line.slice(6) : line
6666

67-
if (data === '[DONE]') continue
67+
if (data === '[DONE]') {
68+
console.warn(
69+
'[@tanstack/ai-client] Received [DONE] sentinel. This is deprecated — upgrade your @tanstack/ai server package. RUN_FINISHED is the stream terminator.',
70+
)
71+
continue
72+
}
6873

6974
try {
7075
const parsed: StreamChunk = JSON.parse(data)

packages/typescript/ai-client/tests/connection-adapters.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ describe('connection-adapters', () => {
104104
expect(chunks).toHaveLength(1)
105105
})
106106

107-
it('should skip [DONE] markers', async () => {
107+
it('should skip [DONE] markers and warn about deprecation', async () => {
108+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
109+
108110
const mockReader = {
109111
read: vi
110112
.fn()
@@ -135,6 +137,11 @@ describe('connection-adapters', () => {
135137
}
136138

137139
expect(chunks).toHaveLength(0)
140+
expect(warnSpy).toHaveBeenCalledWith(
141+
expect.stringContaining('[DONE] sentinel'),
142+
)
143+
144+
warnSpy.mockRestore()
138145
})
139146

140147
it('should handle malformed JSON gracefully', async () => {

0 commit comments

Comments
 (0)