diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index a875ce782..9ceaf4a2b 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -829,7 +829,14 @@ export async function equip(bot, itemName) { await bot.equip(item, 'off-hand'); } else { - await bot.equip(item, 'hand'); + try { + if (bot.currentWindow) bot.closeWindow(bot.currentWindow); + await bot.equip(item, 'hand'); + } catch (err) { + console.warn('Failed to equip tool, continuing without equip:', err.message); + log(bot, `Failed to equip ${itemName}.`); + return false; + } } log(bot, `Equipped ${itemName}.`); return true; diff --git a/src/models/gemini.js b/src/models/gemini.js index 178ffff37..8727fd575 100644 --- a/src/models/gemini.js +++ b/src/models/gemini.js @@ -46,20 +46,38 @@ export class Gemini { }); } - const result = await this.genAI.models.generateContent({ - model: this.model_name || "gemini-2.5-flash", - contents: contents, - safetySettings: this.safetySettings, - config: { - systemInstruction: systemMessage, - ...(this.params || {}) + + const MAX_RETRIES = 5; + const RETRY_DELAY = 5000; + + for (let attempt = 0; attempt < MAX_RETRIES; attempt++) { + try { + const result = await this.genAI.models.generateContent({ + model: this.model_name || "gemini-2.5-flash", + contents: contents, + safetySettings: this.safetySettings, + config: { + systemInstruction: systemMessage, + ...(this.params || {}) + } + }); + const response = await result.text; + if (!response) { + console.warn(`Gemini returned empty response, retrying in ${RETRY_DELAY/1000}s... (attempt ${attempt + 1}/${MAX_RETRIES})`); + await new Promise(r => setTimeout(r, RETRY_DELAY)); + continue; + } + console.log('Received.'); + return response; + } catch (err) { + if (attempt < MAX_RETRIES - 1 && (err.status === 503 || err.status === 429)) { + console.warn(`Google API error ${err.status}, retrying in ${RETRY_DELAY/1000}s... (attempt ${attempt + 1}/${MAX_RETRIES})`); + await new Promise(r => setTimeout(r, RETRY_DELAY)); + } else { + throw err; + } } - }); - const response = await result.text; - - console.log('Received.'); - - return response; + } } async sendVisionRequest(turns, systemMessage, imageBuffer) { @@ -173,4 +191,4 @@ function createWavHeader(dataLength, sampleRate, channels, bitsPerSample) { export const TTSConfig = { sendAudioRequest: sendAudioRequest, -} \ No newline at end of file +}