From fd46d6154315320de1a2d5f9b47993c440c076fe Mon Sep 17 00:00:00 2001 From: Liang Jiaqing Date: Thu, 23 Apr 2026 23:44:50 +0800 Subject: [PATCH] fix: SSE tool_call streaming compat for non-standard index/id, MockToolCall handle list args & None fallback; sop: CDP bringToFront note --- llmcore.py | 10 +++++++--- memory/tmwebdriver_sop.md | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/llmcore.py b/llmcore.py index 675e4e2..f290884 100644 --- a/llmcore.py +++ b/llmcore.py @@ -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: diff --git a/memory/tmwebdriver_sop.md b/memory/tmwebdriver_sop.md index d758893..823f779 100644 --- a/memory/tmwebdriver_sop.md +++ b/memory/tmwebdriver_sop.md @@ -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权限)