Format tool-related information. Args: fields: ChatDocLoggerFields containing tool information entry_id: Parent entry ID Returns: HTML string for the tool section
(self, fields: BaseModel, entry_id: str)
| 749 | </div>""" |
| 750 | |
| 751 | def _format_tool_section(self, fields: BaseModel, entry_id: str) -> str: |
| 752 | """Format tool-related information. |
| 753 | |
| 754 | Args: |
| 755 | fields: ChatDocLoggerFields containing tool information |
| 756 | entry_id: Parent entry ID |
| 757 | |
| 758 | Returns: |
| 759 | HTML string for the tool section |
| 760 | """ |
| 761 | tool = getattr(fields, "tool", "") |
| 762 | tool_type = getattr(fields, "tool_type", "") |
| 763 | content = getattr(fields, "content", "") |
| 764 | |
| 765 | tool_id = f"{entry_id}_tool_{self.tool_counter}" |
| 766 | self.tool_counter += 1 |
| 767 | |
| 768 | # Try to parse content as JSON for better formatting |
| 769 | try: |
| 770 | if content.strip().startswith("{"): |
| 771 | content_dict = json.loads(content) |
| 772 | formatted_content = json.dumps(content_dict, indent=2) |
| 773 | content_html = ( |
| 774 | f'<pre class="code-block">{html.escape(formatted_content)}</pre>' |
| 775 | ) |
| 776 | else: |
| 777 | content_html = html.escape(content) |
| 778 | except Exception: |
| 779 | content_html = html.escape(content) |
| 780 | |
| 781 | # Build tool section |
| 782 | tool_name = f"{tool_type}({tool})" if tool_type else tool |
| 783 | |
| 784 | return f""" |
| 785 | <div class="tool-section"> |
| 786 | <div class="collapsible collapsed" id="{tool_id}"> |
| 787 | <span class="toggle" onclick="toggle('{tool_id}')">[+]</span> |
| 788 | <span class="tool-name">{html.escape(tool_name)}</span> |
| 789 | <div class="content">{content_html}</div> |
| 790 | </div> |
| 791 | </div>""" |
| 792 | |
| 793 | def _append_to_file(self, content: str) -> None: |
| 794 | """Append content to the HTML file. |