From fc5f80ae876daaf30299fc82b619ca92daff84c4 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 25 Jun 2026 21:15:28 -0400 Subject: [PATCH] fix(ai_client): use FileItem class via local import (regression fix) In Phase 2 (commit 96f0aa54), I migrated the half-measure pattern to use 'models.FileItem.from_dict(fi)'. This worked in some scopes but failed in _send_qwen/_send_grok/_send_llama because ai_client.py imports 'FileItem' from src.type_aliases (which is a TypeAlias string forward reference 'models.FileItem', NOT the class). The earlier import from src.models was shadowed by the type_aliases import at line 71. Hence 'isinstance(fi, FileItem)' failed with 'isinstance() arg 2 must be a type'. Fix: add local 'from src.models import FileItem as _FIC' inside the if-block and use _FIC for isinstance + from_dict. Discovered by test_qwen_provider.py::test_qwen_vision_vl_model_accepts_image. Tests: 11/11 pass (test_qwen_provider, test_ai_client_result, test_ai_client_tool_loop). --- src/ai_client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ai_client.py b/src/ai_client.py index 028c4b14..858caf1d 100644 --- a/src/ai_client.py +++ b/src/ai_client.py @@ -2561,7 +2561,8 @@ def _send_grok(md_content: str, user_message: str, base_dir: str, if file_items: for fi in file_items: if fi.get("is_image") and fi.get("base64_data"): - fi_item = fi if isinstance(fi, models.FileItem) else models.FileItem.from_dict(fi) + from src.models import FileItem as _FIC + fi_item = fi if isinstance(fi, _FIC) else _FIC.from_dict(fi) user_content = f"[IMAGE: {fi_item.path or 'attachment'}]\n{user_content}" if discussion_history and not history: history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"}) @@ -2804,7 +2805,8 @@ def _send_qwen(md_content: str, user_message: str, base_dir: str, if file_items: for fi in file_items: if fi.get("is_image") and fi.get("base64_data"): - fi_item = fi if isinstance(fi, models.FileItem) else models.FileItem.from_dict(fi) + from src.models import FileItem as _FIC + fi_item = fi if isinstance(fi, _FIC) else _FIC.from_dict(fi) user_content = f"[IMAGE: {fi_item.path or 'attachment'}]\n{user_content}" if discussion_history and not history: history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"}) @@ -2896,7 +2898,8 @@ def _send_llama(md_content: str, user_message: str, base_dir: str, if file_items: for fi in file_items: if fi.get("is_image") and fi.get("base64_data"): - fi_item = fi if isinstance(fi, models.FileItem) else models.FileItem.from_dict(fi) + from src.models import FileItem as _FIC + fi_item = fi if isinstance(fi, _FIC) else _FIC.from_dict(fi) user_content = f"[IMAGE: {fi_item.path or 'attachment'}]\n{user_content}" if discussion_history and not history: history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"})