import { generateId, type Message } from 'ai'; interface FileContent { path: string; content: string; } interface DetectedCommand { type: string; command: string; description: string; } export async function detectProjectCommands(files: FileContent[]): Promise { const commands: DetectedCommand[] = []; // Look for package.json to detect npm/node projects const packageJson = files.find(f => f.path === 'package.json'); if (packageJson) { try { const pkg = JSON.parse(packageJson.content); // Add install command commands.push({ type: 'install', command: 'npm install', description: 'Install dependencies' }); // Add dev command if it exists if (pkg.scripts?.dev) { commands.push({ type: 'dev', command: 'npm run dev', description: 'Start development server' }); } // Add build command if it exists if (pkg.scripts?.build) { commands.push({ type: 'build', command: 'npm run build', description: 'Build the project' }); } } catch (e) { console.error('Error parsing package.json:', e); } } return commands; } export function createCommandsMessage(commands: DetectedCommand[]): Message | null { if (commands.length === 0) { return null; } const commandsContent = commands.map(cmd => ` ${cmd.command} ` ).join('\n'); return { role: 'assistant', content: `Here are the available commands for this project: ${commandsContent} `, id: generateId(), createdAt: new Date() }; }