Your personal intelligence agent. Watches the world from multiple data sources and pings you when something changes.
fix(llm): Gemini 2.5 compatibility — thinking parts and response parsing
exe.dev user96863bff53c2
diff --git a/lib/llm/gemini.mjs b/lib/llm/gemini.mjsindex 04cf65d..736ead4 100644--- a/lib/llm/gemini.mjs+++ b/lib/llm/gemini.mjs@@ -23,6 +23,9 @@ export class GeminiProvider extends LLMProvider {contents: [{ parts: [{ text: userMessage }] }],generationConfig: {maxOutputTokens: opts.maxTokens || 4096,+ // Gemini 2.5 models use thinking tokens from a separate budget;+ // set thinkingConfig to keep reasoning concise+ thinkingConfig: { thinkingBudget: 1024 },},}),signal: AbortSignal.timeout(opts.timeout || 60000),@@ -34,7 +37,14 @@ export class GeminiProvider extends LLMProvider {}const data = await res.json();- const text = data.candidates?.[0]?.content?.parts?.[0]?.text || '';+ // Gemini 2.5+ models may return multiple parts (thinking + response)+ // Filter out thinking parts and concatenate the rest+ const parts = data.candidates?.[0]?.content?.parts || [];+ const text = parts+ .filter(p => !p.thought) // Skip thinking/reasoning parts+ .map(p => p.text || '')+ .join('\n')+ .trim() || '';return {text,diff --git a/lib/llm/ideas.mjs b/lib/llm/ideas.mjsindex f3d6020..63b4447 100644--- a/lib/llm/ideas.mjs+++ b/lib/llm/ideas.mjs@@ -43,12 +43,12 @@ Output ONLY valid JSON array. Each object:}`;try {- const result = await provider.complete(systemPrompt, context, { maxTokens: 4096, timeout: 90000 });+ const result = await provider.complete(systemPrompt, context, { maxTokens: 8192, timeout: 90000 });const ideas = parseIdeasResponse(result.text);if (ideas && ideas.length > 0) {return ideas;}- console.warn('[LLM Ideas] No valid ideas parsed from response');+ console.warn('[LLM Ideas] No valid ideas parsed from response. Raw length:', result.text?.length, 'First 1000 chars:', JSON.stringify(result.text?.slice(0, 1000)));return null;} catch (err) {console.error('[LLM Ideas] Generation failed:', err.message);@@ -167,10 +167,19 @@ function compactSweepForLLM(data, delta, previousIdeas) {function parseIdeasResponse(text) {if (!text) return null;- // Strip markdown code block wrappers+ // Strip markdown code block wrappers (handles trailing whitespace, thinking tags, etc.)let cleaned = text.trim();- if (cleaned.startsWith('```')) {- cleaned = cleaned.replace(/^```(?:json)?\n?/, '').replace(/\n?```$/, '');+ // Extract content from code blocks anywhere in the response+ const codeBlockMatch = cleaned.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);+ if (codeBlockMatch) {+ cleaned = codeBlockMatch[1].trim();+ } else if (cleaned.startsWith('```')) {+ cleaned = cleaned.replace(/^```(?:json)?\n?/, '').replace(/\n?```\s*$/, '');+ }+ // Strip any leading/trailing non-JSON text (find the array)+ const arrayMatch = cleaned.match(/(\[[\s\S]*\])/);+ if (arrayMatch) {+ cleaned = arrayMatch[1];}try {