diff --git a/bot/lib/ai-helper.js b/bot/lib/ai-helper.js index bbdad09..adfb2d6 100644 --- a/bot/lib/ai-helper.js +++ b/bot/lib/ai-helper.js @@ -15,32 +15,32 @@ async function chatWithAI(prompt, aiConfig) { async function generateAndSaveTask(taskName, aiConfig) { const prompt = ` -You are generating a Minecraft Mineflayer bot task. The task name is: "${taskName}". +You are a Minecraft Mineflayer bot generator. The task is called "${taskName}". -You must return only a valid Node.js module that: +Return only a valid Node.js module that: - Exports: \`module.exports = async function(bot, db, say) { ... }\` -- Uses only valid Mineflayer API methods. -- Do NOT use \`bot.inventory.find()\`. Use \`bot.inventory.items().find(...)\` instead. -- If accessing blocks, use \`bot.findBlock()\`, \`bot.blockAt()\`, or \`bot.openBlock()\`. -- Only respond with valid JavaScript code. No comments or markdown. -`.trim(); +- Uses only Mineflayer APIs like \`bot.inventory.items()\`, \`bot.blockAt()\`, etc. +- DO NOT return markdown, explanations, or comments — code only. + +The task should accomplish: "${taskName.replace(/-/g, ' ')}" + `.trim(); try { const response = await chatWithAI(prompt, aiConfig); let taskCode = response.trim(); - // Remove wrapping backticks if present + // Strip markdown formatting if (taskCode.startsWith('```')) { taskCode = taskCode.replace(/```[a-z]*\n?/i, '').replace(/```$/, '').trim(); } - if (!taskCode.includes('module.exports')) { - throw new Error('AI did not return a valid module.exports function.'); + if (!taskCode.startsWith('module.exports')) { + throw new Error('AI response did not begin with module.exports'); } const taskPath = path.join(__dirname, '../bot-tasks', `${taskName}.js`); fs.writeFileSync(taskPath, taskCode); - console.log(`[AI] Task file generated: ${taskPath}`); + console.log(`[AI] Task file overwritten with AI code: ${taskPath}`); } catch (err) { console.error('[TASK GENERATION ERROR]', err.message); }