refactor: share streaming tool event normalization
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user