UNPKG

marsdevs-git-workreport

Version:

🚀 Advanced Git Work Report Generator with AI-Powered Summaries - Generate intelligent daily work reports from Git commit history using Claude AI or OpenRouter. Perfect for DevOps teams, development companies, and client reporting with comprehensive stati

145 lines (140 loc) • 5.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AISummarizer = void 0; const sdk_1 = __importDefault(require("@anthropic-ai/sdk")); class AISummarizer { constructor(options) { this.provider = options.provider; this.apiKey = options.apiKey; this.model = options.model || this.getDefaultModel(); if (this.provider === 'anthropic') { this.anthropic = new sdk_1.default({ apiKey: this.apiKey, }); } } /** * Generate a summary of changes from commit messages using AI */ async generateSummary(commitMessages, totalLinesChanged) { try { const prompt = this.buildPrompt(commitMessages, totalLinesChanged); if (this.provider === 'anthropic') { return await this.generateAnthropicSummary(prompt); } else if (this.provider === 'openrouter') { return await this.generateOpenRouterSummary(prompt); } else { throw new Error(`Unsupported AI provider: ${this.provider}`); } } catch (error) { console.warn(`Failed to generate AI summary: ${error instanceof Error ? error.message : 'Unknown error'}`); return this.generateFallbackSummary(commitMessages, totalLinesChanged); } } /** * Generate summary using Anthropic API */ async generateAnthropicSummary(prompt) { if (!this.anthropic) { throw new Error('Anthropic client not initialized'); } const response = await this.anthropic.messages.create({ model: this.model, max_tokens: 500, messages: [ { role: 'user', content: prompt } ] }); return response.content[0].type === 'text' ? response.content[0].text : 'Unable to generate summary'; } /** * Generate summary using OpenRouter API */ async generateOpenRouterSummary(prompt) { const response = await fetch('https://openrouter.ai/api/v1/chat/completions', { method: 'POST', headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json', 'HTTP-Referer': 'https://github.com/zayan-devops-444/git-workreport', 'X-Title': 'Git Work Report' }, body: JSON.stringify({ model: this.model, messages: [ { role: 'user', content: prompt } ], max_tokens: 500, temperature: 0.7 }) }); if (!response.ok) { throw new Error(`OpenRouter API error: ${response.status} ${response.statusText}`); } const data = await response.json(); return data.choices?.[0]?.message?.content || 'Unable to generate summary'; } /** * Get default model for the selected provider */ getDefaultModel() { switch (this.provider) { case 'anthropic': return 'claude-3-haiku-20240307'; case 'openrouter': return 'anthropic/claude-3-haiku'; default: return 'claude-3-haiku-20240307'; } } /** * Build the prompt for the AI model */ buildPrompt(commitMessages, totalLinesChanged) { const messagesText = commitMessages.join('\n'); return `You are a helpful assistant that summarizes daily development work based on commit messages. Given the following commit messages from a single day of development work, provide a concise bullet-point summary of what was accomplished. Focus only on the actual changes made. Commit messages: ${messagesText} Total lines of code changed: ${totalLinesChanged} Please provide a bullet-point summary with the following requirements: - Use bullet points (• or -) for each change - Focus only on the actual changes made - No introductory or closing sentences - No extra words or explanations - Keep each point concise and direct - List only the main changes and improvements Example format: • Added user authentication system • Fixed login form validation • Updated database schema for user profiles`; } /** * Generate a fallback summary when AI is not available */ generateFallbackSummary(commitMessages, totalLinesChanged) { const uniqueMessages = [...new Set(commitMessages)]; const messageCount = uniqueMessages.length; if (messageCount === 0) { return 'No changes were made on this date.'; } if (messageCount === 1) { return `Made changes: ${uniqueMessages[0]}`; } return `Completed ${messageCount} tasks with ${totalLinesChanged} lines of code changed.`; } } exports.AISummarizer = AISummarizer; //# sourceMappingURL=ai-summarizer.js.map