MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / decode

Method decode

packages/baseai/src/dev/utils/stream/stream.ts:322–363  ·  view source on GitHub ↗
(line: string)

Source from the content-addressed store, hash-verified

320 }
321
322 decode(line: string) {
323 if (line.endsWith('\r')) {
324 line = line.substring(0, line.length - 1);
325 }
326
327 if (!line) {
328 // empty line and we didn't previously encounter any messages
329 if (!this.event && !this.data.length) return null;
330
331 const sse: ServerSentEvent = {
332 event: this.event,
333 data: this.data.join('\n'),
334 raw: this.chunks
335 };
336
337 this.event = null;
338 this.data = [];
339 this.chunks = [];
340
341 return sse;
342 }
343
344 this.chunks.push(line);
345
346 if (line.startsWith(':')) {
347 return null;
348 }
349
350 let [fieldname, _, value] = partition(line, ':');
351
352 if (value.startsWith(' ')) {
353 value = value.substring(1);
354 }
355
356 if (fieldname === 'event') {
357 this.event = value;
358 } else if (fieldname === 'data') {
359 this.data.push(value);
360 }
361
362 return null;
363 }
364}
365
366/**

Callers 3

_iterSSEMessagesFunction · 0.95
readStreamFunction · 0.45
decodeTextMethod · 0.45

Calls 1

partitionFunction · 0.70

Tested by

no test coverage detected