fix: streaming tool call parsing, error handling, and fake HA state mutation

- Fix Gemini streaming tool call merge bug: multiple tool calls with same
  index but different IDs are now parsed as separate calls instead of
  concatenating names (e.g. ha_call_serviceha_call_service)
- Handle partial results in voice mode: show error and stop continuous
  mode when agent returns partial/failed results with empty response
- Fix error display during streaming TTS: error messages are shown in
  full response box even when streaming box was already opened
- Add duplicate sentence filter in TTS: skip near-duplicate sentences
  from LLM repetition
- Fix fake HA server state mutation: turn_on/turn_off/set_temperature
  correctly update entity states; temperature sensor simulates change
  when thermostat is adjusted
This commit is contained in:
0xbyt4
2026-03-07 01:49:12 +03:00
parent 404123aea7
commit 46db7aeffd
4 changed files with 41 additions and 5 deletions

View File

@@ -2646,7 +2646,21 @@ class AIAgent:
# Tool call deltas
if delta and delta.tool_calls:
for tc_delta in delta.tool_calls:
idx = tc_delta.index
idx = tc_delta.index if tc_delta.index is not None else 0
# Gemini may reuse index 0 for multiple tool calls,
# sending a new id each time. Detect this and assign
# a fresh virtual index so calls don't merge.
if idx in tool_calls_acc and tc_delta.id and tc_delta.id != tool_calls_acc[idx]["id"]:
# Look for existing entry with this id first
# (follow-up deltas for an already-created tool call)
matched = False
for eidx, eentry in tool_calls_acc.items():
if eentry["id"] == tc_delta.id:
idx = eidx
matched = True
break
if not matched:
idx = (max(k for k in tool_calls_acc if isinstance(k, int)) + 1) if tool_calls_acc else 0
if idx not in tool_calls_acc:
tool_calls_acc[idx] = {
"id": tc_delta.id or "",