added fast apply

if isEdit === true & Morph API Key is in .env:
- Morph Fast Apply is activated.
This commit is contained in:
Bekbol Bolatov
2025-09-11 18:24:27 +05:00
parent 280c177619
commit 2327442b89
5 changed files with 351 additions and 7 deletions
+30 -1
View File
@@ -551,7 +551,7 @@ Remember: You are a SURGEON making a precise incision, not an artist repainting
}
// Build system prompt with conversation awareness
const systemPrompt = `You are an expert React developer with perfect memory of the conversation. You maintain context across messages and remember scraped websites, generated components, and applied code. Generate clean, modern React code for Vite applications.
let systemPrompt = `You are an expert React developer with perfect memory of the conversation. You maintain context across messages and remember scraped websites, generated components, and applied code. Generate clean, modern React code for Vite applications.
${conversationContext}
🚨 CRITICAL RULES - YOUR MOST IMPORTANT INSTRUCTIONS:
@@ -897,6 +897,24 @@ CRITICAL: When files are provided in the context:
4. Do NOT ask to see files - they are already provided in the context above
5. Make the requested change immediately`;
// If Morph Fast Apply is enabled (edit mode + MORPH_API_KEY), force <edit> block output
const morphFastApplyEnabled = Boolean(isEdit && process.env.MORPH_API_KEY);
if (morphFastApplyEnabled) {
systemPrompt += `
MORPH FAST APPLY MODE (EDIT-ONLY):
- Output edits as <edit> blocks, not full <file> blocks, for files that already exist.
- Format for each edit:
<edit target_file="src/components/Header.jsx">
<instructions>Describe the minimal change, single sentence.</instructions>
<update>Provide the SMALLEST code snippet necessary to perform the change.</update>
</edit>
- Only use <file> blocks when you must CREATE a brand-new file.
- Prefer ONE edit block for a simple change; multiple edits only if absolutely needed for separate files.
- Keep updates minimal and precise; do not rewrite entire files.
`;
}
// Build full prompt with context
let fullPrompt = prompt;
if (context) {
@@ -1140,6 +1158,17 @@ CRITICAL: When files are provided in the context:
}
if (contextParts.length > 0) {
if (morphFastApplyEnabled) {
contextParts.push('\nOUTPUT FORMAT (REQUIRED IN MORPH MODE):');
contextParts.push('<edit target_file="src/components/Component.jsx">');
contextParts.push('<instructions>Minimal, precise instruction.</instructions>');
contextParts.push('<update>// Smallest necessary snippet</update>');
contextParts.push('</edit>');
contextParts.push('\nIf you need to create a NEW file, then and only then output a full file:');
contextParts.push('<file path="src/components/NewComponent.jsx">');
contextParts.push('// Full file content when creating new files');
contextParts.push('</file>');
}
fullPrompt = `CONTEXT:\n${contextParts.join('\n')}\n\nUSER REQUEST:\n${prompt}`;
}
}