fix: SSE tool_call streaming compat for non-standard index/id, MockToolCall handle list args & None fallback; sop: CDP bringToFront note

This commit is contained in:
Liang Jiaqing
2026-04-23 23:44:50 +08:00
parent 8a6a5715ff
commit fd46d61543
2 changed files with 8 additions and 3 deletions

View File

@@ -243,9 +243,13 @@ def _parse_openai_sse(resp_lines, api_mode="chat_completions"):
text = delta["content"]; content_text += text; yield text
for tc in (delta.get("tool_calls") or []):
idx = tc.get("index", 0)
if idx not in tc_buf: tc_buf[idx] = {"id": tc.get("id") or '', "name": "", "args": ""}
if tc.get("function", {}).get("name"): tc_buf[idx]["name"] = tc["function"]["name"]
has_name = bool(tc.get("function", {}).get("name"))
if idx not in tc_buf:
if has_name or not tc_buf: tc_buf[idx] = {"id": tc.get("id") or '', "name": "", "args": ""}
else: idx = max(tc_buf)
if has_name: tc_buf[idx]["name"] = tc["function"]["name"]
if tc.get("function", {}).get("arguments"): tc_buf[idx]["args"] += tc["function"]["arguments"]
if tc.get("id") and not tc_buf[idx]["id"]: tc_buf[idx]["id"] = tc["id"]
usage = evt.get("usage")
if usage: _record_usage(usage, api_mode)
blocks = []
@@ -672,7 +676,7 @@ class MockFunction:
class MockToolCall:
def __init__(self, name, args, id=''):
arg_str = json.dumps(args, ensure_ascii=False) if isinstance(args, dict) else args
arg_str = json.dumps(args, ensure_ascii=False) if isinstance(args, (dict, list)) else (args or '{}')
self.function = MockFunction(name, arg_str); self.id = id
class MockResponse:

View File

@@ -37,6 +37,7 @@ fetch('PDF_URL').then(r=>r.blob()).then(b=>{
## Chrome后台标签节流
- 后台标签中`setTimeout`被Chrome intensive throttling延迟到≥1min/次扩展脚本中避免依赖setTimeout轮询
- 某些SPA页面需CDP `Page.bringToFront`切到前台才会加载数据
## CDP桥(tmwd_cdp_bridge扩展) ⭐首选
扩展路径:`assets/tmwd_cdp_bridge/`(需安装含debugger权限)