(text: string, tag?: string, durationMs?: number)
| 684 | } |
| 685 | |
| 686 | const appendThinkToBlocks = (text: string, tag?: string, durationMs?: number) => { |
| 687 | if (!text && durationMs === undefined) return |
| 688 | const idx = getAiMessageIndex() |
| 689 | const blocks = targetBuffer.messages[idx].contentBlocks || [] |
| 690 | const thinkTag = tag || 'think' |
| 691 | const lastBlock = blocks[blocks.length - 1] |
| 692 | let targetBlock: ContentBlock | undefined = lastBlock |
| 693 | if (lastBlock && lastBlock.type === 'think' && lastBlock.tag === thinkTag) { |
| 694 | lastBlock.text += text |
| 695 | } else if (text.trim().length > 0) { |
| 696 | targetBlock = { type: 'think', tag: thinkTag, text } |
| 697 | blocks.push(targetBlock) |
| 698 | } else if (durationMs !== undefined) { |
| 699 | for (let index = blocks.length - 1; index >= 0; index--) { |
| 700 | const block = blocks[index] |
| 701 | if (block.type === 'think' && block.tag === thinkTag) { |
| 702 | targetBlock = block |
| 703 | break |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | if (durationMs !== undefined && targetBlock && targetBlock.type === 'think') { |
| 708 | targetBlock.durationMs = durationMs |
| 709 | } |
| 710 | updateAIMessage({ contentBlocks: [...blocks] }) |
| 711 | } |
| 712 | |
| 713 | const appendChartsToBlocks = (charts: ChartPayload[]) => { |
| 714 | if (charts.length === 0) return |
no test coverage detected