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) {