MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / appendTextToRootStream

Function appendTextToRootStream

cli/src/utils/block-operations.ts:392–432  ·  view source on GitHub ↗
(
  blocks: ContentBlock[],
  delta: { type: 'text' | 'reasoning'; text: string },
)

Source from the content-addressed store, hash-verified

390}
391
392export const appendTextToRootStream = (
393 blocks: ContentBlock[],
394 delta: { type: 'text' | 'reasoning'; text: string },
395) => {
396 if (!delta.text) {
397 return blocks
398 }
399
400 // For reasoning type (from native reasoning_chunk events), use original behavior
401 if (delta.type === 'reasoning') {
402 const nextBlocks = [...blocks]
403 const lastBlock = nextBlocks[nextBlocks.length - 1]
404
405 if (
406 lastBlock &&
407 lastBlock.type === 'text' &&
408 lastBlock.textType === 'reasoning'
409 ) {
410 const updatedBlock: ContentBlock = {
411 ...lastBlock,
412 content: lastBlock.content + delta.text,
413 }
414 nextBlocks[nextBlocks.length - 1] = updatedBlock
415 return nextBlocks
416 }
417
418 const newBlock: ContentBlock = {
419 type: 'text',
420 content: delta.text,
421 textType: 'reasoning',
422 thinkingCollapseState: 'preview',
423 thinkingId: generateThinkingId(),
424 }
425
426 return [...nextBlocks, newBlock]
427 }
428
429 // For text type: first close any open native reasoning block, then parse for <think> tags
430 const blocksWithClosedReasoning = closeNativeReasoningBlock(blocks)
431 return appendTextWithThinkParsingToBlocks(blocksWithClosedReasoning, delta.text)
432}
433
434export const appendTextToAgentBlock = (
435 blocks: ContentBlock[],

Callers 3

appendRootChunkFunction · 0.90
processTextChunkFunction · 0.90

Calls 3

generateThinkingIdFunction · 0.85

Tested by

no test coverage detected