MCPcopy Create free account
hub / github.com/anus-dev/ANUS / processStreamResponse

Method processStreamResponse

packages/core/src/core/anusChat.ts:453–490  ·  view source on GitHub ↗
(
    streamResponse: AsyncGenerator<GenerateContentResponse>,
    inputContent: Content,
  )

Source from the content-addressed store, hash-verified

451 }
452
453 private async *processStreamResponse(
454 streamResponse: AsyncGenerator<GenerateContentResponse>,
455 inputContent: Content,
456 ) {
457 const outputContent: Content[] = [];
458 const chunks: GenerateContentResponse[] = [];
459 let errorOccurred = false;
460
461 try {
462 for await (const chunk of streamResponse) {
463 if (isValidResponse(chunk)) {
464 chunks.push(chunk);
465 const content = chunk.candidates?.[0]?.content;
466 if (content !== undefined) {
467 if (this.isThoughtContent(content)) {
468 yield chunk;
469 continue;
470 }
471 outputContent.push(content);
472 }
473 }
474 yield chunk;
475 }
476 } catch (error) {
477 errorOccurred = true;
478 throw error;
479 }
480
481 if (!errorOccurred) {
482 const allParts: Part[] = [];
483 for (const content of outputContent) {
484 if (content.parts) {
485 allParts.push(...content.parts);
486 }
487 }
488 }
489 this.recordHistory(inputContent, outputContent);
490 }
491
492 private recordHistory(
493 userInput: Content,

Callers 1

sendMessageStreamMethod · 0.95

Calls 3

isThoughtContentMethod · 0.95
recordHistoryMethod · 0.95
isValidResponseFunction · 0.85

Tested by

no test coverage detected