This commit is contained in:
2026-03-07 14:39:40 -05:00
parent a856d73f95
commit 6ab359deda
3 changed files with 53 additions and 9 deletions

View File

@@ -638,12 +638,16 @@ async def _execute_single_tool_call_async(
out = "USER REJECTED: tool execution cancelled" if _res is None else await mcp_client.async_dispatch(name, args)
else:
out = await mcp_client.async_dispatch(name, args)
if tool_log_callback:
tool_log_callback(f"# MCP TOOL: {name}\n{json.dumps(args, indent=1)}", out)
elif name == TOOL_NAME:
scr = cast(str, args.get("script", ""))
_append_comms("OUT", "tool_call", {"name": TOOL_NAME, "id": call_id, "script": scr})
out = await asyncio.to_thread(_run_script, scr, base_dir, qa_callback, patch_callback)
else:
out = f"ERROR: unknown tool '{name}'"
if tool_log_callback:
tool_log_callback(f"ERROR: {name}", out)
return (name, call_id, out, name)
@@ -1495,6 +1499,26 @@ def _ensure_minimax_client() -> None:
raise ValueError("MiniMax API key not found in credentials.toml")
_minimax_client = OpenAI(api_key=api_key, base_url="https://api.minimax.chat/v1")
def _repair_deepseek_history(history: list[dict[str, Any]]) -> None:
if not history:
return
last = history[-1]
if last.get("role") != "assistant":
return
tool_calls = last.get("tool_calls", [])
if not tool_calls:
return
call_ids = [tc.get("id") for tc in tool_calls if tc.get("id")]
for cid in call_ids:
# Check if already present in tail (to be safe, though usually missing if we're here)
already_has = any(m.get("role") == "tool" and m.get("tool_call_id") == cid for m in history[-len(call_ids)-1:])
if not already_has:
history.append({
"role": "tool",
"tool_call_id": cid,
"content": "ERROR: Session was interrupted before tool result was recorded.",
})
def _send_deepseek(md_content: str, user_message: str, base_dir: str,
file_items: list[dict[str, Any]] | None = None,
discussion_history: str = "",
@@ -1522,6 +1546,7 @@ def _send_deepseek(md_content: str, user_message: str, base_dir: str,
# Update history following Anthropic pattern
with _deepseek_history_lock:
_repair_deepseek_history(_deepseek_history)
if discussion_history and not _deepseek_history:
user_content = f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"
else: