(evt)
| 725 | |
| 726 | // ---- Assistant ---- |
| 727 | function renderAssistant(evt) { |
| 728 | const blocks = evt.message.content || []; |
| 729 | const msgId = evt.message.id; |
| 730 | const usage = evt.message.usage; |
| 731 | |
| 732 | syncConfirmedModel(evt.message.model, { allowToast: true }); |
| 733 | |
| 734 | for (const b of blocks) { |
| 735 | try { |
| 736 | if (b.type === 'thinking' && b.thinking) renderThinking(b); |
| 737 | else if (b.type === 'text' && b.text) { closeGroup(); renderText(b.text, msgId); } |
| 738 | else if (b.type === 'tool_use') { |
| 739 | const toolName = b.name || ''; |
| 740 | if (isTodoTool(toolName)) { |
| 741 | handleTodoToolUse(b); |
| 742 | } |
| 743 | if (registerInteractiveToolUse(b)) { |
| 744 | // handled by interaction state machine |
| 745 | } else if (!HIDDEN_STEP_TOOLS.has(toolName)) { |
| 746 | renderTool(b); |
| 747 | } |
| 748 | } |
| 749 | } catch (e) { |
| 750 | console.error('[renderBlock]', e); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | if (usage && evt.message.stop_reason) { |
| 755 | const total = (usage.input_tokens || 0) + (usage.cache_read_input_tokens || 0) + |
| 756 | (usage.cache_creation_input_tokens || 0) + (usage.output_tokens || 0); |
| 757 | if (total > 0 && S.currentGroup) { |
| 758 | let tc = S.currentGroup.querySelector('.token-count'); |
| 759 | if (!tc) { |
| 760 | tc = document.createElement('div'); |
| 761 | tc.className = 'token-count'; |
| 762 | S.currentGroup.appendChild(tc); |
| 763 | } |
| 764 | tc.textContent = formatTokens(total); |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | function renderText(text, msgId) { |
| 770 | let el = S.messageMap.get(msgId); |
no test coverage detected