From 684f8eaebb26029de62821e11ae636ae344728a7 Mon Sep 17 00:00:00 2001 From: mic Date: Wed, 24 Sep 2025 22:23:39 +0200 Subject: [PATCH] checking response arrays in google gemini worker. see #514 --- js/workers/model-worker-google_gemini.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/js/workers/model-worker-google_gemini.js b/js/workers/model-worker-google_gemini.js index cb961a66..5e2683d2 100644 --- a/js/workers/model-worker-google_gemini.js +++ b/js/workers/model-worker-google_gemini.js @@ -115,8 +115,24 @@ self.onmessage = async function(event) { for (const parsedLine of parsedLines) { const { candidates } = parsedLine; + + if (!Array.isArray(candidates) || candidates.length === 0) { + taLog.warn('[ThunderAI] Gemini stream skipped: candidates is not a non-empty array'); + continue; + } + const { content } = candidates[0]; + if (!content || typeof content !== 'object') { + taLog.warn('[ThunderAI] Gemini stream skipped: missing candidate content'); + continue; + } + const { parts } = content; + if (!Array.isArray(parts) || parts.length === 0) { + taLog.warn('[ThunderAI] Gemini stream skipped: parts is not a non-empty array. [finishReason: ' + content.finishReason + ']'); + continue; + } + const { text } = parts[0]; // Update the UI with the new content if (text) {