{"repo": "akhilmaratha/agentic-ai-website-builder", "files": {"server/services/aiService.ts": {"c1a99293469ab566ace71aecfc2fbcf197211ed8": {"t": 1786068460.4027345, "n": 2337, "h": "9da107e041e72e62", "c": "import { runAgentPipeline, type OrchestratorResult } from \"../agents/orchestrator\";\n\n/**\n * AI Service\n * Wraps the multi-agent pipeline with LLM integration.\n */\nexport class AIService {\n private apiKey: string;\n private baseURL: string;\n private model: string;\n\n constructor() {\n this.apiKey = process.env.OPENROUTER_API_KEY ?? \"\";\n this.baseURL = process.env.AI_BASE_URL ?? \"https://openrouter.ai/api/v1\";\n this.model = process.env.AI_MODEL ?? \"deepseek/deepseek-chat\";\n }\n\n /**\n * Run the full multi-agent pipeline on a prompt.\n */\n async generateFromPrompt(\n prompt: string,\n options?: { skipDeployment?: boolean }\n ): Promise {\n return runAgentPipeline(prompt, options);\n }\n\n /**\n * Enhance a single component via LLM (optional).\n */\n async enhanceWithLLM(code: string, instructions: string): Promise {\n if (!this.apiKey) return code; // no-op if no key\n\n try {\n const headers: Record = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n };\n\n if (this.baseURL.includes(\"openrouter.ai\")) {\n headers[\"HTTP-Referer\"] = process.env.NEXTAUTH_URL ?? \"http://localhost:3000\";\n headers[\"X-Title\"] = \"Agentic AI Website Builder\";\n }\n\n const res = await fetch(`${this.baseURL}/chat/completions`, {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n model: this.model,\n messages: [\n {\n role: \"system\",\n content:\n \"You are a React/Tailwind expert. Modify the component code according to instructions. Return ONLY the modified code, no explanations.\",\n },\n {\n role: \"user\",\n content: `Instructions: ${instructions}\\n\\nCode:\\n${code}`,\n },\n ],\n temperature: 0.3,\n max_tokens: 4096,\n }),\n });\n\n if (!res.ok) return code;\n\n const data = await res.json();\n const result = data?.choices?.[0]?.message?.content ?? code;\n\n // Strip code fences\n return result\n .replace(/^```(?:tsx|jsx|typescript|javascript)?\\s*/i, \"\")\n .replace(/\\s*```\\s*$/, \"\")\n .trim();\n } catch {\n return code;\n }\n }\n}\n\nexport const aiService = new AIService();\n"}}}}