fix(provider): add missing index field to streaming tool_call deltas (#6661) (#6692)

* 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

* 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

---------

Co-authored-by: Yaohua-Leo <3067173925@qq.com>
Co-authored-by: Soulter <905617992@qq.com>
This commit is contained in:
LIU Yaohua
2026-03-25 18:31:35 +08:00
committed by GitHub
parent 11c7591b17
commit e4ce090db2

View File

@@ -334,11 +334,15 @@ class ProviderOpenAIOfficial(Provider):
choice = chunk.choices[0]
delta = choice.delta
# siliconflow workaround
if dtcs := delta.tool_calls:
for tc in dtcs:
for idx, tc in enumerate(dtcs):
# siliconflow workaround
if tc.function and tc.function.arguments:
tc.type = "function"
# Fix for #6661: Add missing 'index' field to tool_call deltas
# Gemini and some OpenAI-compatible proxies omit this field
if not hasattr(tc, "index") or tc.index is None:
tc.index = idx
try:
state.handle_chunk(chunk)
except Exception as e: