MCPcopy Create free account
hub / github.com/bywwcnll/StreamPanel / processChunk

Function processChunk

inject.js:428–453  ·  view source on GitHub ↗
(value, stream)

Source from the content-addressed store, hash-verified

426 };
427
428 const processChunk = (value, stream) => {
429 if (!value) return;
430 if (!shouldObserveStream(stream)) return;
431
432 buffer += decoder.decode(value, { stream: true });
433
434 if (isSSE) {
435 const boundaryIndex = findCompleteSSEBoundary(buffer);
436 if (boundaryIndex !== null) {
437 const completeData = buffer.substring(0, boundaryIndex);
438 buffer = buffer.substring(boundaryIndex);
439 const events = parseSSEEvents(completeData);
440 for (const event of events) {
441 emitMessage(event.event, event.data, event.id);
442 }
443 }
444 } else if (isNDJSON) {
445 const lines = buffer.split(/\r?\n/);
446 buffer = lines.pop() || '';
447 for (const line of lines) {
448 if (line.trim()) {
449 emitMessage('message', line);
450 }
451 }
452 }
453 };
454
455 const createObserverTransform = (stream) => new TransformStream({
456 transform(chunk, controller) {

Callers 1

transformFunction · 0.85

Calls 4

shouldObserveStreamFunction · 0.85
findCompleteSSEBoundaryFunction · 0.85
parseSSEEventsFunction · 0.85
emitMessageFunction · 0.85

Tested by

no test coverage detected