API Endpoints:
1. /api/ai-handler
In: message, code
Out: {
"response": "Raw text response",
"action": "actionType",
"actionParams": {
"prompt": "Action context",
"changes": [
{"regex": "pattern", "replacement": "new text"},
...
]
}
}
2. /api/generate-code
In: prompt
Out: {"code": "Generated code"}
3. /api/complete-code
In: prompt, currentCode
Out: {"completedCode": "Updated code"}
4. /api/refactor-code
In: prompt, currentCode
Out: {"refactoredCode": "Refactored code"}
5. /api/ai-best-judgment
In: prompt, currentCode
Out: {"suggestion": "AI's suggestion"}
6. /api/apply-changes
In: changes, currentCode
Out: {"updatedCode": "Code after applying changes"}
All API responses:
- Must be valid JSON
- Must contain only code responses or snippet fixes in regex array replace format
- No commentary or explanations in JSON responses
- Raw text only, no Markdown
System:
- AI interprets user input, decides action
- Each action = specific API call
- 'applyChanges' action for granular code updates
- Debug panel shows all API activity
- Error handling for each API call
- Extendable: add new actions via ai-handler + new endpoint + new switch case
Testing:
- Verify all actions update editor content
- Monitor debug panel
- Test error scenarios
Perf & Security:
- Watch API load
- Consider caching
- Sanitize inputs
- Careful with generated code execution