(
body: dict, text: str, calls: list[dict[str, Any]], finish: str
)
| 665 | |
| 666 | |
| 667 | def _build_capture_dict( |
| 668 | body: dict, text: str, calls: list[dict[str, Any]], finish: str |
| 669 | ) -> dict[str, Any]: |
| 670 | sys_field = body.get("system", "") |
| 671 | if isinstance(sys_field, list): |
| 672 | system_text = " ".join( |
| 673 | (b.get("text") or "") |
| 674 | for b in sys_field |
| 675 | if isinstance(b, dict) and b.get("type") == "text" |
| 676 | ) |
| 677 | else: |
| 678 | system_text = str(sys_field) if sys_field else "" |
| 679 | raw_tools = body.get("tools") or body.get("customTools") or [] |
| 680 | raw = { |
| 681 | "request_messages": list(body.get("messages") or []), |
| 682 | "request_system": system_text, |
| 683 | "request_tools_count": len(raw_tools) if isinstance(raw_tools, list) else 0, |
| 684 | "response_text": text, |
| 685 | "response_tool_calls": calls, |
| 686 | "response_finish_reason": finish, |
| 687 | "content_truncated": False, |
| 688 | } |
| 689 | cap_bytes = _content_cap_bytes() |
| 690 | if cap_bytes <= 0: |
| 691 | raw["content_truncated"] = False |
| 692 | return raw |
| 693 | truncated, was_trunc = truncate_content_payload(raw, cap_bytes=cap_bytes) |
| 694 | truncated["content_truncated"] = was_trunc |
| 695 | return truncated |
| 696 | |
| 697 | |
| 698 | def _content_cap_bytes() -> int: |
no test coverage detected