Skip to content

Commit bccbdc9

Browse files
jwfingclaude
andcommitted
fix: reset currentEvent on unknown SSE event type
Set currentEvent to null when event type is not in VALID_EVENTS, and skip data lines when currentEvent is null to prevent emitting events with a stale type. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e6db246 commit bccbdc9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/lib/api/platform.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,16 @@ export async function streamDiagnosticAnalysis(
172172
const reader = body.getReader();
173173
const decoder = new TextDecoder();
174174
let buffer = '';
175-
let currentEvent: DiagnosticSSEEvent['type'] = 'delta';
175+
let currentEvent: DiagnosticSSEEvent['type'] | null = 'delta';
176176

177177
const VALID_EVENTS = new Set<string>(['delta', 'tool_call', 'tool_result', 'done', 'error']);
178178

179179
const processLine = (line: string): void => {
180180
if (line.startsWith('event:')) {
181181
const evt = line.slice(6).trim();
182-
if (VALID_EVENTS.has(evt)) {
183-
currentEvent = evt as DiagnosticSSEEvent['type'];
184-
}
182+
currentEvent = VALID_EVENTS.has(evt) ? evt as DiagnosticSSEEvent['type'] : null;
185183
} else if (line.startsWith('data:')) {
184+
if (!currentEvent) return;
186185
const raw = line.slice(5).trim();
187186
if (!raw) return;
188187
try {

0 commit comments

Comments
 (0)