From 9c41a3f1bf5b93f868539f86ec745fc0e555888b Mon Sep 17 00:00:00 2001 From: Yaohua-Leo <3067173925@qq.com> Date: Fri, 20 Mar 2026 18:19:55 +0800 Subject: [PATCH 1/2] fix(provider): add missing index field to streaming tool_call deltas - Fix #6661: Streaming tool_call arguments lost when OpenAI-compatible proxy omits index field - Gemini and some proxies (e.g. Continue) don't include index field in tool_call deltas - Add default index=0 when missing to prevent ChatCompletionStreamState.handle_chunk() from rejecting chunks Fixes #6661 --- astrbot/core/provider/sources/openai_source.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 6848c5d43a..ca80bd3384 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -307,6 +307,14 @@ async def _query_stream( state = ChatCompletionStreamState() async for chunk in stream: + # Fix for #6661: Add missing 'index' field to tool_call deltas + # Gemini and some OpenAI-compatible proxies omit this field + if chunk.choices: + choice = chunk.choices[0] + if choice.delta and choice.delta.tool_calls: + for tc in choice.delta.tool_calls: + if not hasattr(tc, "index") or tc.index is None: + tc.index = 0 try: state.handle_chunk(chunk) except Exception as e: From 8525d974949fc8ee7ddae89d8d802e4b3f0cc464 Mon Sep 17 00:00:00 2001 From: Yaohua-Leo <3067173925@qq.com> Date: Fri, 20 Mar 2026 19:03:43 +0800 Subject: [PATCH 2/2] fix(provider): use enumerate for multi-tool-call index assignment - Use enumerate() to assign correct index based on list position - Iterate over all choices (not just the first) for completeness - Addresses review feedback from sourcery-ai and gemini-code-assist --- astrbot/core/provider/sources/openai_source.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index ca80bd3384..48a6e222f7 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -310,11 +310,11 @@ async def _query_stream( # Fix for #6661: Add missing 'index' field to tool_call deltas # Gemini and some OpenAI-compatible proxies omit this field if chunk.choices: - choice = chunk.choices[0] - if choice.delta and choice.delta.tool_calls: - for tc in choice.delta.tool_calls: - if not hasattr(tc, "index") or tc.index is None: - tc.index = 0 + for choice in chunk.choices: + if choice.delta and choice.delta.tool_calls: + for idx, tc in enumerate(choice.delta.tool_calls): + if not hasattr(tc, "index") or tc.index is None: + tc.index = idx try: state.handle_chunk(chunk) except Exception as e: