refactor: share streaming tool event normalization

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
GitHub Actions
2026-04-22 08:07:10 +08:00
parent aac6e2785d
commit b479294af4
2 changed files with 29 additions and 27 deletions

View File

@@ -92,6 +92,23 @@ def _allowed_tool_events(
return out
def _allowed_stream_tool_event(
event: Any,
*,
tool_config: dict[str, Any] | None,
forced_tool_name: str | None = None,
) -> dict[str, Any] | None:
if not isinstance(event, dict) or event.get("type") != "tool":
return None
tool = event.get("tool")
if not isinstance(tool, dict):
return None
tool_name = str(tool.get("name") or "")
if not _tool_event_allowed(tool_name, tool_config, forced_tool_name=forced_tool_name):
return None
return tool
def _openai_forced_tool_name(tool_choice: Any) -> str | None:
if not isinstance(tool_choice, dict):
return None