aura-ai
Version:
AI-powered marketing strategist CLI tool for developers
124 lines (104 loc) • 3.4 kB
JavaScript
import { openai } from '@ai-sdk/openai'
import { generateText } from 'ai'
import dotenv from 'dotenv'
// Load environment variables
dotenv.config({ path: '.env.local' })
dotenv.config()
class SyncAIService {
constructor() {
this.apiKey = process.env.OPENAI_API_KEY
this.model = 'gpt-4o-mini'
}
async generateDailyReport(commits) {
if (!this.apiKey || this.apiKey === 'your_openai_api_key_here') {
throw new Error('OpenAI API key not configured')
}
if (commits.length === 0) {
return {
summary: "No commits today yet. Start coding to track your progress!",
highlights: [],
markdown: "# 📅 Daily Progress Report\n\nNo commits found today."
}
}
const prompt = `Analyze these git commits from today and create a concise daily progress report.
Git commits:
${commits}
Instructions:
1. Write a ONE sentence executive summary of what was accomplished today
2. List 3-5 key highlights (what would impress a manager or client)
3. Ignore generic commits like "update", "fix", "commit" unless they're part of something bigger
4. Use plain English that non-developers can understand
5. Focus on business value and user-facing improvements
6. Be concise but enthusiastic
Output JSON format:
{
"summary": "One sentence summary here",
"highlights": [
"First achievement",
"Second achievement",
"Third achievement"
]
}
IMPORTANT: Return ONLY valid JSON, no markdown formatting or extra text.`
try {
const result = await generateText({
model: openai(this.model),
prompt,
temperature: 0.7,
maxTokens: 500,
})
// Parse the AI response
let parsed
try {
// Clean the response in case AI added markdown formatting
const cleanJson = result.text.replace(/```json\n?|\n?```/g, '').trim()
parsed = JSON.parse(cleanJson)
} catch (e) {
// Fallback if JSON parsing fails
console.error('Failed to parse AI response:', e)
return {
summary: "Made several improvements to the project today.",
highlights: ["Various updates and improvements"],
markdown: this.generateFallbackMarkdown(commits)
}
}
// Generate markdown from the parsed response
const markdown = this.generateMarkdown(parsed)
return {
...parsed,
markdown
}
} catch (error) {
console.error('Error generating AI report:', error)
throw error
}
}
generateMarkdown(report) {
const date = new Date().toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
})
let markdown = `# 📅 Daily Progress Report\n`
markdown += `**${date}**\n\n`
markdown += `${report.summary}\n\n`
if (report.highlights && report.highlights.length > 0) {
markdown += `### ✨ Key Achievements\n\n`
report.highlights.forEach(highlight => {
markdown += `• ${highlight}\n`
})
}
return markdown
}
generateFallbackMarkdown(commits) {
const date = new Date().toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
})
return `# 📅 Daily Progress Report\n**${date}**\n\n## Today's Commits\n\n${commits}`
}
}
export default new SyncAIService()