Files

1 line
6.4 KiB
JSON

{"repo": "aito0077/legal-analysis", "files": {"src/app/api/ai/suggest-risks/route.ts": {"276f878d627cc2931cb51506683700a1ad4dff5d": {"t": 1785745589.747446, "n": 3047, "h": "96e4f353278836ae", "c": "import { NextRequest, NextResponse } from 'next/server';\nimport { auth } from '@/lib/auth';\nimport prisma from '@/lib/prisma';\nimport { getRiskAIService, UserContext } from '@/lib/ai/risk-ai-service';\nimport { z } from 'zod';\n\nconst suggestRisksSchema = z.object({\n count: z.number().min(1).max(10).optional().default(5),\n});\n\n// POST /api/ai/suggest-risks - Get AI-powered risk suggestions\nexport async function POST(request: NextRequest) {\n try {\n const session = await auth();\n if (!session?.user?.id) {\n return NextResponse.json({ error: 'No autorizado' }, { status: 401 });\n }\n\n // Check if DeepSeek is configured\n const aiService = getRiskAIService();\n if (!process.env.DEEPSEEK_API_KEY) {\n return NextResponse.json(\n {\n error: 'Servicio de IA no configurado',\n message: 'La API de DeepSeek no está configurada. Por favor, contacte al administrador.',\n },\n { status: 503 }\n );\n }\n\n // Parse request body\n const body = await request.json();\n const { count } = suggestRisksSchema.parse(body);\n\n // Get user profile\n const user = await prisma.user.findUnique({\n where: { id: session.user.id },\n include: {\n professionalProfile: true,\n businessProfile: true,\n },\n });\n\n if (!user || !user.profileType) {\n return NextResponse.json(\n { error: 'Perfil de usuario no encontrado o incompleto' },\n { status: 400 }\n );\n }\n\n // Build user context\n const context: UserContext = {\n profileType: user.profileType,\n jurisdiction: user.professionalProfile?.jurisdiction || user.businessProfile?.jurisdiction || 'Argentina',\n };\n\n if (user.profileType === 'PROFESSIONAL' && user.professionalProfile) {\n context.profession = user.professionalProfile.profession;\n context.yearsExperience = user.professionalProfile.yearsExperience || undefined;\n context.practiceAreas = user.professionalProfile.practiceAreas;\n } else if (user.profileType === 'BUSINESS' && user.businessProfile) {\n context.businessType = user.businessProfile.businessType;\n context.companySize = user.businessProfile.companySize;\n context.businessActivities =\n user.businessProfile.businessActivities &&\n typeof user.businessProfile.businessActivities === 'object'\n ? Object.keys(user.businessProfile.businessActivities as object)\n : [];\n }\n\n // Get AI suggestions\n const suggestions = await aiService.suggestRisks(context, count);\n\n return NextResponse.json({ suggestions });\n } catch (error) {\n if (error instanceof z.ZodError) {\n return NextResponse.json(\n { error: 'Datos inválidos', details: error.errors },\n { status: 400 }\n );\n }\n\n console.error('Error generating risk suggestions:', error);\n return NextResponse.json(\n {\n error: 'Error al generar sugerencias',\n message: error instanceof Error ? error.message : 'Error desconocido',\n },\n { status: 500 }\n );\n }\n}\n"}, "9a9ebd259fc028632f5ece1481c2562d70b0dea5": {"t": 1785754559.0769496, "n": 3047, "h": "96e4f353278836ae", "c": "import { NextRequest, NextResponse } from 'next/server';\nimport { auth } from '@/lib/auth';\nimport prisma from '@/lib/prisma';\nimport { getRiskAIService, UserContext } from '@/lib/ai/risk-ai-service';\nimport { z } from 'zod';\n\nconst suggestRisksSchema = z.object({\n count: z.number().min(1).max(10).optional().default(5),\n});\n\n// POST /api/ai/suggest-risks - Get AI-powered risk suggestions\nexport async function POST(request: NextRequest) {\n try {\n const session = await auth();\n if (!session?.user?.id) {\n return NextResponse.json({ error: 'No autorizado' }, { status: 401 });\n }\n\n // Check if DeepSeek is configured\n const aiService = getRiskAIService();\n if (!process.env.DEEPSEEK_API_KEY) {\n return NextResponse.json(\n {\n error: 'Servicio de IA no configurado',\n message: 'La API de DeepSeek no está configurada. Por favor, contacte al administrador.',\n },\n { status: 503 }\n );\n }\n\n // Parse request body\n const body = await request.json();\n const { count } = suggestRisksSchema.parse(body);\n\n // Get user profile\n const user = await prisma.user.findUnique({\n where: { id: session.user.id },\n include: {\n professionalProfile: true,\n businessProfile: true,\n },\n });\n\n if (!user || !user.profileType) {\n return NextResponse.json(\n { error: 'Perfil de usuario no encontrado o incompleto' },\n { status: 400 }\n );\n }\n\n // Build user context\n const context: UserContext = {\n profileType: user.profileType,\n jurisdiction: user.professionalProfile?.jurisdiction || user.businessProfile?.jurisdiction || 'Argentina',\n };\n\n if (user.profileType === 'PROFESSIONAL' && user.professionalProfile) {\n context.profession = user.professionalProfile.profession;\n context.yearsExperience = user.professionalProfile.yearsExperience || undefined;\n context.practiceAreas = user.professionalProfile.practiceAreas;\n } else if (user.profileType === 'BUSINESS' && user.businessProfile) {\n context.businessType = user.businessProfile.businessType;\n context.companySize = user.businessProfile.companySize;\n context.businessActivities =\n user.businessProfile.businessActivities &&\n typeof user.businessProfile.businessActivities === 'object'\n ? Object.keys(user.businessProfile.businessActivities as object)\n : [];\n }\n\n // Get AI suggestions\n const suggestions = await aiService.suggestRisks(context, count);\n\n return NextResponse.json({ suggestions });\n } catch (error) {\n if (error instanceof z.ZodError) {\n return NextResponse.json(\n { error: 'Datos inválidos', details: error.errors },\n { status: 400 }\n );\n }\n\n console.error('Error generating risk suggestions:', error);\n return NextResponse.json(\n {\n error: 'Error al generar sugerencias',\n message: error instanceof Error ? error.message : 'Error desconocido',\n },\n { status: 500 }\n );\n }\n}\n"}}}}