fix(ai_client): Add missing response_received events for gemini streaming and non-streaming paths

This commit is contained in:
2026-03-05 19:21:57 -05:00
parent 937759a7a3
commit 03b68c9cea
3 changed files with 4 additions and 2 deletions

View File

@@ -712,6 +712,7 @@ def _send_gemini(md_content: str, user_message: str, base_dir: str,
txt = "".join(txt_chunks)
# Final validation of response object for subsequent code
resp = final_resp
events.emit("response_received", payload={"provider": "gemini", "model": _model, "usage": usage, "round": r_idx})
else:
config = types.GenerateContentConfig(
tools=[types.Tool(function_declarations=[types.FunctionDeclaration(**s) for s in mcp_client.get_tool_schemas()])] if enable_tools else [],
@@ -728,6 +729,7 @@ def _send_gemini(md_content: str, user_message: str, base_dir: str,
"cache_read_input_tokens": getattr(resp.usage_metadata, "cached_content_token_count", 0)
}
reason = resp.candidates[0].finish_reason.name if (resp.candidates and hasattr(resp.candidates[0], "finish_reason")) else "STOP"
events.emit("response_received", payload={"provider": "gemini", "model": _model, "usage": usage, "round": r_idx})
_append_comms("IN", "response", {"round": r_idx, "stop_reason": reason, "text": txt, "tool_calls": [{"name": c.name, "args": dict(c.args)} for c in calls], "usage": usage})
total_in = usage.get("input_tokens", 0)