UNPKG

scai

Version:

> AI-powered CLI tools for smart commit messages, auto generated comments, and readme files — all powered by local models.

46 lines (43 loc) 1.53 kB
import { ModelConfig } from '../../config/ModelConfig.js'; export const refactorModule = { name: 'refactor', description: 'Break code into small, clean functions', async run(input) { const model = ModelConfig.getModel(); const lang = ModelConfig.getLanguage(); const prompt = ` You are a senior ${lang.toUpperCase()} engineer. Refactor the following code: - Refactor only long and complex functions - Keep original names and semantics. - Do NOT insert comments --- CODE START --- ${input.code} --- CODE END --- `.trim(); try { const res = await fetch('http://localhost:11434/api/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ model, prompt, stream: false }) }); if (!res.ok) { const errBody = await res.text(); throw new Error(`❌ Refactor failed: ${res.status} ${res.statusText} - ${errBody}`); } const data = await res.json(); if (!data.response) { throw new Error('❌ No response field returned from model.'); } return { code: data.response.trim() }; } catch (err) { console.error('🔥 Error in refactorModule:', err); throw new Error('❌ Error in refactor module: ' + err.message); } } };