ui: Linting & Formatting scripts (#26819)
This commit is contained in:
@@ -30,9 +30,11 @@ export async function* parseSseJsonStream<T = unknown>(
|
||||
signal?: AbortSignal
|
||||
): AsyncGenerator<SseJsonEvent<T>> {
|
||||
const reader = response.body?.getReader();
|
||||
|
||||
if (!reader) return;
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
let buffer = '';
|
||||
|
||||
try {
|
||||
@@ -40,19 +42,26 @@ export async function* parseSseJsonStream<T = unknown>(
|
||||
if (signal?.aborted) return;
|
||||
|
||||
const { done, value } = await reader.read();
|
||||
|
||||
if (done) break;
|
||||
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
const records = buffer.split(SSE_RECORD_SEPARATOR);
|
||||
|
||||
buffer = records.pop() ?? '';
|
||||
|
||||
for (const record of records) {
|
||||
if (!record) continue;
|
||||
|
||||
for (const line of record.split(SSE_LINE_SEPARATOR)) {
|
||||
if (!line.startsWith(SSE_DATA_PREFIX)) continue;
|
||||
|
||||
const payload = line.slice(SSE_DATA_PREFIX.length).trim();
|
||||
|
||||
if (payload === SSE_DONE_MARKER) return;
|
||||
|
||||
if (!payload) continue;
|
||||
|
||||
try {
|
||||
yield { data: JSON.parse(payload) as T };
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user