fix(chat): complete streaming for reasoning, tools, and tool calls

- Forward reasoning_content and non-stream reasoning to on_token in
  OpenAI chat completions; Gemini thought parts to on_token.
- Stream bubble: always render session.tool panels; format tool_use_call
  payloads and title as call · tool_name.
- Emit tool_use_call via on_tool_ui before tool execution so WS shows
  invoke cards before tool_use_result.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-05-10 14:02:14 +08:00
parent 75a3038f33
commit 398d85ba06
4 changed files with 68 additions and 17 deletions

View file

@ -224,6 +224,8 @@ class GoogleGeminiChatModel(ChatModel):
txt = str(p.get("text") or "")
if txt:
thinking_parts.append(txt)
if on_token:
on_token(txt)
sig = p.get("thoughtSignature")
if isinstance(sig, str) and sig:
thinking_signature = sig

View file

@ -551,8 +551,11 @@ class OpenAIChatModel(ChatModel):
reasoning_parts = getattr(msg, "reasoning_content", None) or ""
reasoning_text = str(reasoning_parts).strip() if reasoning_parts else ""
content = msg.content or ""
if on_token and content:
on_token(content)
if on_token:
if reasoning_text:
on_token(reasoning_text)
if content:
on_token(content)
tool_calls: list[LLMToolCall] = []
if msg.tool_calls:
@ -620,6 +623,8 @@ class OpenAIChatModel(ChatModel):
rc = getattr(delta, "reasoning_content", None) or ""
if rc:
reasoning_parts.append(rc)
if on_token:
on_token(rc)
if delta.tool_calls:
for tc in delta.tool_calls:
idx = int(tc.index)