ideas-generator/server/migrations/add-starter-message.js
DJP 77da1f44f0 Add comprehensive admin dashboard with analytics, full agent management, and complete system improvements
## Major Features Added:
- Complete admin dashboard with user, agent, conversation, and usage management
- Real-time usage analytics with interactive Chart.js visualizations
- Advanced trend analysis with line charts and bar graphs
- CSV export functionality for usage reports with date/user/agent filtering
- Full CRUD operations for agent management including system prompts and starter messages

## UI/UX Improvements:
- Professional top navigation bar with admin access and logout functionality
- Moved admin link from homepage to navigation for better UX
- Reduced all font sizes by 20% for better formatting consistency
- Changed color scheme from blue to orange (#e6a335) throughout application
- Fixed conversation double-click bug in chat interface
- Added separate starter message field distinct from system instructions

## Backend Enhancements:
- Added analytics API endpoints (/api/analytics/usage, /api/analytics/stats, /api/analytics/trends)
- Enhanced assistant API with admin-level data access and full CRUD operations
- Implemented starterMessage database field with automatic migration and data extraction
- Added comprehensive usage tracking and trend analysis capabilities
- Imported 34 additional agents from CSV (total: 53 agents)

## Technical Architecture:
- Integrated Chart.js with Vue.js for professional data visualization
- Implemented proper chart cleanup to prevent memory leaks
- Added comprehensive error handling and fallback states
- Enhanced API service layer with dedicated analytics methods
- Implemented role-based authentication and admin route protection

## Database Improvements:
- Added starterMessage field to Assistant model with automatic data migration
- Enhanced seed script with proper agent categorization and data cleanup
- Improved assistant API responses to include all necessary admin fields
- Implemented proper foreign key relationships for analytics queries

🚀 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-03 14:41:32 -04:00

78 lines
No EOL
2.4 KiB
JavaScript

require('dotenv').config();
const { sequelize } = require('../config/database');
async function addStarterMessageColumn() {
try {
console.log('🔧 Adding starterMessage column to assistants table...');
// Add the starterMessage column
await sequelize.getQueryInterface().addColumn('assistants', 'starterMessage', {
type: sequelize.Sequelize.DataTypes.TEXT,
allowNull: true,
});
console.log('✅ Column added successfully');
// Now extract starter messages from existing systemPrompt data
console.log('🔍 Extracting starter messages from systemPrompt data...');
const assistants = await sequelize.query(
'SELECT id, "systemPrompt" FROM assistants WHERE "systemPrompt" IS NOT NULL',
{ type: sequelize.QueryTypes.SELECT }
);
for (const assistant of assistants) {
const systemPrompt = assistant.systemPrompt;
// Look for STARTER MESSAGE pattern
const starterMatch = systemPrompt.match(/STARTER MESSAGE:\s*"([^"]+)"/i);
if (starterMatch) {
const starterMessage = starterMatch[1];
// Clean the systemPrompt by removing the starter message section
const cleanSystemPrompt = systemPrompt
.replace(/\n\nSTARTER MESSAGE:\s*"[^"]+"/i, '')
.trim();
// Update the database
await sequelize.query(
'UPDATE assistants SET "starterMessage" = :starterMessage, "systemPrompt" = :systemPrompt WHERE id = :id',
{
replacements: {
id: assistant.id,
starterMessage: starterMessage,
systemPrompt: cleanSystemPrompt
},
type: sequelize.QueryTypes.UPDATE
}
);
console.log(`✅ Updated assistant: ${starterMessage.substring(0, 50)}...`);
}
}
console.log('✅ Migration completed successfully');
} catch (error) {
console.error('❌ Migration failed:', error);
throw error;
} finally {
await sequelize.close();
}
}
// Run the migration if this file is executed directly
if (require.main === module) {
addStarterMessageColumn()
.then(() => {
console.log('Migration finished');
process.exit(0);
})
.catch((error) => {
console.error('Migration error:', error);
process.exit(1);
});
}
module.exports = addStarterMessageColumn;