mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-04-26 10:31:07 +00:00
Some checks are pending
CI / checks (push) Waiting to run
Consolidates the incremental refactor work into a single change set: modular web tools (api/web_tools), native Anthropic request building and SSE block policy, OpenAI conversion and error handling, provider transports and rate limiting, messaging handler and tree queue, safe logging, smoke tests, and broad test coverage.
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
"""Safe metadata summaries for HTTP 422 validation logging (no raw text content)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def summarize_request_validation_body(
|
|
body: Any,
|
|
) -> tuple[list[dict[str, Any]], list[str]]:
|
|
"""Return message shape summary and tool name list for debug logs."""
|
|
messages = body.get("messages") if isinstance(body, dict) else None
|
|
message_summary: list[dict[str, Any]] = []
|
|
if isinstance(messages, list):
|
|
for msg in messages:
|
|
if not isinstance(msg, dict):
|
|
message_summary.append({"message_kind": type(msg).__name__})
|
|
continue
|
|
content = msg.get("content")
|
|
item: dict[str, Any] = {
|
|
"role": msg.get("role"),
|
|
"content_kind": type(content).__name__,
|
|
}
|
|
if isinstance(content, list):
|
|
item["block_types"] = [
|
|
block.get("type", "dict")
|
|
if isinstance(block, dict)
|
|
else type(block).__name__
|
|
for block in content[:12]
|
|
]
|
|
item["block_keys"] = [
|
|
sorted(str(key) for key in block)[:12]
|
|
for block in content[:5]
|
|
if isinstance(block, dict)
|
|
]
|
|
elif isinstance(content, str):
|
|
item["content_length"] = len(content)
|
|
message_summary.append(item)
|
|
|
|
tool_names: list[str] = []
|
|
if isinstance(body, dict) and isinstance(body.get("tools"), list):
|
|
tool_names = [
|
|
str(tool.get("name", ""))
|
|
for tool in body["tools"]
|
|
if isinstance(tool, dict)
|
|
]
|
|
|
|
return message_summary, tool_names
|