Skip to content

Commit 6c00ccb

Browse files
authored
docs: added contributor's guide for the AI Debugger
1 parent 19feed2 commit 6c00ccb

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

js/widgets/aidebugger-guide.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# AI-powered Debugger Widget - Contributor Guide
2+
3+
## Overview
4+
5+
The AI-powered Debugger Widget is an intelligent debugging assistant for Music Blocks that provides AI-powered analysis and child-friendly debugging suggestions through an interactive chat interface.
6+
7+
### Key Features
8+
- Interactive chat interface within Music Blocks
9+
- Real-time project analysis using AI
10+
- Educational explanations for children
11+
- Export/reset conversation functionality
12+
- Integration with Music Blocks widget system
13+
14+
### Architecture
15+
```
16+
Music Blocks Frontend → AI Debugger Widget → FastAPI Backend → Google Gemini AI
17+
→ RAG System → Qdrant Vector DB
18+
```
19+
20+
**Components:**
21+
- **Frontend**: `js/widgets/aidebugger.js` (main widget)
22+
- **Block Definition**: `js/blocks/WidgetBlocks.js` (lines 1643-1719)
23+
- **Registration**: `js/activity.js` (line 165)
24+
- **Backend**: External FastAPI server with AI processing
25+
26+
## Quick Start
27+
28+
### Setup
29+
```bash
30+
git clone https://github.com/sugarlabs/musicblocks.git
31+
cd musicblocks
32+
npm install
33+
npm run serve # Access at http://localhost:3000
34+
```
35+
36+
### Key Files
37+
- `js/widgets/aidebugger.js` - Main widget implementation
38+
- `js/blocks/WidgetBlocks.js` - Block definition (lines 1643-1719)
39+
- `js/activity.js` - Widget registration (line 165)
40+
41+
## Frontend Implementation
42+
43+
### Widget Structure
44+
```javascript
45+
function AIDebuggerWidget() {
46+
const BACKEND_CONFIG = {
47+
BASE_URL: "http://13.49.246.243:8000",
48+
ENDPOINTS: { ANALYZE: "/analyze" }
49+
};
50+
51+
this.chatHistory = [];
52+
this.promptCount = 0;
53+
this.conversationId = null;
54+
}
55+
```
56+
57+
### Key Methods
58+
- `init(activity)` - Initialize widget and UI
59+
- `_createLayout()` - Build chat interface
60+
- `_sendMessage()` - Handle user input and AI responses
61+
- `_convertProjectToLLMFormat()` - Convert Music Blocks JSON to readable text
62+
63+
### API Communication
64+
```javascript
65+
const payload = {
66+
code: projectData, // Music Blocks JSON
67+
prompt: message, // User question
68+
history: history, // Chat history
69+
prompt_count: this.promptCount
70+
};
71+
72+
fetch(`${BACKEND_CONFIG.BASE_URL}/analyze`, {
73+
method: "POST",
74+
headers: { "Content-Type": "application/json" },
75+
body: JSON.stringify(payload)
76+
});
77+
```
78+
79+
## Development Workflow
80+
81+
### Adding Features
82+
1. **Edit Widget**: Modify `js/widgets/aidebugger.js`
83+
2. **Test Locally**: Run `npm run serve`
84+
3. **Block Integration**: Update `js/blocks/WidgetBlocks.js` if needed
85+
4. **Register Widget**: Ensure listed in `js/activity.js`
86+
87+
### Code Standards
88+
```javascript
89+
// Use descriptive names
90+
this._createChatInterface = function() { ... };
91+
92+
// Add documentation
93+
/**
94+
* Sends message to backend and processes AI response
95+
* @param {string} message - User input message
96+
*/
97+
this._sendToBackend = function(message) { ... };
98+
99+
// Handle errors gracefully
100+
.catch(error => {
101+
console.error("Backend error:", error.message);
102+
this.activity.textMsg(_("Connection error"));
103+
});
104+
```
105+
106+
### Code Review Checklist
107+
- [ ] Widget initializes correctly
108+
- [ ] Chat interface is responsive
109+
- [ ] Backend communication works
110+
- [ ] Error handling is robust
111+
- [ ] Language is child-appropriate
112+
- [ ] No console errors
113+
114+
## Testing
115+
116+
### Manual Testing
117+
1. Open Music Blocks → Drag AI Debugger block → Click block
118+
2. Verify widget window opens with chat interface
119+
3. Type message → Click Send → Check AI response
120+
4. Test export/reset functionality
121+
5. Verify works with different project types
122+
123+
### Debug Commands
124+
```javascript
125+
// Frontend debugging
126+
console.log("Widget initialized:", this);
127+
console.log("Backend URL:", BACKEND_CONFIG.BASE_URL);
128+
129+
// Backend testing
130+
curl -X POST http://localhost:8000/analyze \
131+
-H "Content-Type: application/json" \
132+
-d '{"code": "[]", "prompt": "test"}'
133+
```
134+
135+
## Troubleshooting
136+
137+
### Common Issues
138+
- **Widget not loading**: Check `activity.js` registration and console errors
139+
- **Backend connection**: Verify `BACKEND_CONFIG.BASE_URL` and CORS
140+
- **UI problems**: Check CSS styles and widget window creation
141+
142+
### Resources
143+
- **GitHub Issues**: [Music Blocks Issues](https://github.com/sugarlabs/musicblocks/issues)
144+
- **Documentation**: [Music Blocks Guide](https://github.com/sugarlabs/musicblocks/tree/master/guide)
145+
- **Backend Repo**: [AI Debugger Backend](https://github.com/omsuneri/AI-powered-Debugger-for-Music-Blocks)
146+
147+
---
148+
149+
**Made with ❤️ for Music Blocks and Sugar Labs**
150+
**Created by**: [Om Santosh Suneri](https://github.com/omsuneri/) | **[GSoC 2025](https://summerofcode.withgoogle.com/programs/2025/projects/l4402WCJ)**

0 commit comments

Comments
 (0)