From c43f6a95fcf46c5edbbfa6e9aac760e5ccdfdd62 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 21 Feb 2026 04:44:41 +0800 Subject: [PATCH] fix(agent): fallback to qwen3-vl when primary returns non-json --- lib/ai/smart-analyzer.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/ai/smart-analyzer.ts b/lib/ai/smart-analyzer.ts index e5efe0d25..b7cbd9a34 100644 --- a/lib/ai/smart-analyzer.ts +++ b/lib/ai/smart-analyzer.ts @@ -1353,6 +1353,22 @@ ${historyText} try { const { text: responseText } = await generateText(requestPayload as any); + const hasStructuredJson = /\{[\s\S]*\}/.test(String(responseText || "")); + if (hasImage && !hasStructuredJson) { + console.warn( + "[Smart Analyzer] Primary analyzer returned non-JSON for image input, fallback to hardcoded qwen3-vl", + ); + const qwenFallback = await analyzeWithHardcodedQwen3VlFallback({ + text, + hasImage, + imageUrls, + historyMessages, + context, + reason: "primary_non_json_response", + }); + if (qwenFallback) return qwenFallback; + } + const parsed = parseAnalysisResultFromModelText(responseText, text, hasImage); if (parsed) return parsed; } catch (error) {