setup-media.jsโข8.55 kB
/**
* Setup Media Directory Structure
* Creates necessary directories and placeholder files for media storage
*/
const fs = require('fs').promises;
const path = require('path');
const MEDIA_DIRS = [
'media',
'media/screenshots',
'media/recordings',
'media/browser',
'media/thumbnails',
'media/exports',
'data',
'logs'
];
const PLACEHOLDER_FILES = {
'public/placeholder.png': createPlaceholderImage(),
'.env.example': createEnvExample(),
'README.md': createReadme()
};
async function setupMediaDirectories() {
console.log('๐ Setting up media directory structure...\n');
// Create directories
for (const dir of MEDIA_DIRS) {
const dirPath = path.join(__dirname, dir);
try {
await fs.mkdir(dirPath, { recursive: true });
console.log(`โ
Created directory: ${dir}`);
// Add .gitkeep to preserve empty directories
const gitkeepPath = path.join(dirPath, '.gitkeep');
await fs.writeFile(gitkeepPath, '');
} catch (error) {
if (error.code === 'EEXIST') {
console.log(`โญ๏ธ Directory exists: ${dir}`);
} else {
console.error(`โ Failed to create ${dir}:`, error.message);
}
}
}
// Create placeholder files
console.log('\n๐ Creating configuration files...\n');
for (const [filePath, content] of Object.entries(PLACEHOLDER_FILES)) {
const fullPath = path.join(__dirname, filePath);
try {
// Check if file exists
await fs.access(fullPath);
console.log(`โญ๏ธ File exists: ${filePath}`);
} catch {
// File doesn't exist, create it
await fs.writeFile(fullPath, content);
console.log(`โ
Created file: ${filePath}`);
}
}
// Create gitignore for media files
const gitignorePath = path.join(__dirname, 'media', '.gitignore');
const gitignoreContent = `
# Ignore all media files except .gitkeep
*
!.gitignore
!.gitkeep
!*/
`.trim();
await fs.writeFile(gitignorePath, gitignoreContent);
console.log('\nโ
Created media/.gitignore');
console.log('\n๐ Media directory setup complete!');
console.log('\n๐ Next steps:');
console.log('1. Copy .env.example to .env and configure');
console.log('2. Install VS Code extension: cd vscode-extension && npm install');
console.log('3. Run the server: npm start');
console.log('4. Open browser: http://localhost:3000');
}
function createPlaceholderImage() {
// Create a simple SVG placeholder image
return `<svg width="400" height="300" xmlns="http://www.w3.org/2000/svg">
<rect width="400" height="300" fill="#f3f4f6"/>
<text x="50%" y="50%" text-anchor="middle" dy=".3em" fill="#9ca3af" font-family="sans-serif" font-size="20">
No Preview Available
</text>
</svg>`;
}
function createEnvExample() {
return `# Voice Assistant Configuration
# Server Ports
PORT=3000
WS_PORT=3001
# Project Settings
PROJECT_ROOT=${process.cwd()}
PROJECT_NAME=MyProject
# ElevenLabs API (optional)
ELEVENLABS_API_KEY=your_api_key_here
ELEVENLABS_VOICE_ID=rachel
# OpenAI API (optional, for enhanced voice processing)
OPENAI_API_KEY=your_api_key_here
# Media Storage
MAX_STORAGE_GB=5
CLEANUP_DAYS=30
THUMBNAIL_WIDTH=320
THUMBNAIL_HEIGHT=240
# Session Settings
SESSION_TIMEOUT_MINUTES=30
AUTO_SAVE_INTERVAL_SECONDS=60
# Security
CORS_ORIGIN=http://localhost:3000
API_KEY=optional_api_key_for_security
# Features
ENABLE_BROWSER_MCP=true
ENABLE_VOICE_RECOGNITION=true
ENABLE_AUTO_TRANSCRIPTION=false
# VS Code Extension
VSCODE_AUTO_CONNECT=true
VSCODE_SERVER_URL=ws://localhost:3001
`;
}
function createReadme() {
return `# Voice Code Assistant with Media History
A comprehensive voice-enabled AI pair programmer with media documentation capabilities.
## Features
- ๐๏ธ **Voice Control**: Natural voice commands for code analysis
- ๐ธ **Screenshot Capture**: Desktop and browser screenshots
- ๐ฌ **Screen Recording**: Record coding sessions
- ๐ **Browser Integration**: Capture web content via Playwright
- ๐พ **Media History**: SQLite-backed storage with search
- ๐ **Smart Code Search**: Powered by SCS-MCP
- ๐ฏ **VS Code Integration**: Real-time editor context
- ๐ **Analytics Dashboard**: Usage insights and metrics
## Quick Start
1. **Install dependencies**:
\`\`\`bash
npm install
\`\`\`
2. **Setup environment**:
\`\`\`bash
cp .env.example .env
# Edit .env with your configuration
\`\`\`
3. **Initialize database and directories**:
\`\`\`bash
npm run setup
\`\`\`
4. **Install VS Code extension** (optional):
\`\`\`bash
cd vscode-extension
npm install
npm run compile
# Install in VS Code via F5 (debug mode)
\`\`\`
5. **Start the server**:
\`\`\`bash
npm start
\`\`\`
6. **Open the UI**:
Navigate to http://localhost:3000
## Voice Commands
- "Take a screenshot" - Capture current screen
- "Start recording" - Begin screen recording
- "Review this code" - Analyze current selection
- "Find similar code" - Search for patterns
- "Explain this function" - Get code explanation
- "Show media history" - View captured media
## Architecture
\`\`\`
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Web UI โโโโโโถโ Voice Server โโโโโโถโ SCS-MCP โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ SQLite DB โ โ Code Search โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโ
โ Media Storageโ
โโโโโโโโโโโโโโโโ
\`\`\`
## API Endpoints
### REST API
- \`GET /health\` - Server health check
- \`POST /api/voice\` - Process voice command
- \`POST /api/screenshot\` - Capture screenshot
- \`POST /api/recording/start\` - Start recording
- \`POST /api/recording/stop\` - Stop recording
- \`GET /api/media\` - Get media history
- \`POST /api/export\` - Export media
### WebSocket Events
- \`voice\` - Voice command input
- \`context\` - Editor context update
- \`screenshot\` - Screenshot request
- \`recording\` - Recording control
- \`media_history\` - Media updates
## Configuration
### Environment Variables
See \`.env.example\` for all available options.
### VS Code Settings
Add to your VS Code settings.json:
\`\`\`json
{
"voiceAssistant.autoConnect": true,
"voiceAssistant.serverUrl": "ws://localhost:3001"
}
\`\`\`
## Media Storage
Media files are stored in:
- \`media/screenshots/\` - Screenshot images
- \`media/recordings/\` - Video recordings
- \`media/browser/\` - Browser captures
- \`media/thumbnails/\` - Generated thumbnails
Database: \`data/media-history.db\`
## Development
### Run in development mode:
\`\`\`bash
npm run dev
\`\`\`
### Test MCP connection:
\`\`\`bash
npm test
\`\`\`
### Clean up old media:
\`\`\`bash
node cleanup.js
\`\`\`
## Troubleshooting
### Voice recognition not working
- Check browser permissions for microphone
- Ensure HTTPS or localhost connection
- Try Chrome/Edge for best compatibility
### Screenshots not capturing
- Check desktop permissions
- Verify screenshot tool installation
- Try browser-based capture as fallback
### MCP connection issues
- Verify SCS-MCP is properly installed
- Check PROJECT_ROOT in .env
- Review server logs for errors
## License
MIT
## Contributing
Pull requests welcome! Please read CONTRIBUTING.md first.
## Support
- Issues: [GitHub Issues](https://github.com/your-repo/issues)
- Docs: [Documentation](https://your-docs-site.com)
`;
}
// Run setup if executed directly
if (require.main === module) {
setupMediaDirectories().catch(error => {
console.error('โ Setup failed:', error);
process.exit(1);
});
}
module.exports = { setupMediaDirectories };