11import type { Duration } from "@/lib/duration"
22import type { LLMModel , LLMModelConfig } from "@/lib/models"
3- import { getModelClient } from "@/lib/models" // Assuming getModelClient is a named export
3+ import { getModelClient } from "@/lib/models"
44import { toEnhancedPrompt } from "@/lib/enhanced-prompt"
55import ratelimit from "@/lib/ratelimit"
66import { fragmentSchema as schema } from "@/lib/schema"
@@ -22,7 +22,7 @@ export async function POST(req: Request) {
2222 try {
2323 console . log ( `[Chat API ${ requestId } ] Processing request` )
2424
25- // Parse request body with enhanced error handling
25+
2626 let body : any
2727 try {
2828 body = await req . json ( )
@@ -62,7 +62,7 @@ export async function POST(req: Request) {
6262 analysisInstructions ?: string
6363 } = body
6464
65- // Enhanced validation with better error messages
65+
6666 const validation = validateRequestData ( body )
6767 if ( ! validation . valid ) {
6868 logError ( "Request validation failed" , new Error ( validation . errors . join ( ", " ) ) , { requestId, errors : validation . errors } )
@@ -97,7 +97,7 @@ export async function POST(req: Request) {
9797 }
9898 }
9999
100- // Rate limiting check
100+
101101 try {
102102 const limit = ! config . apiKey
103103 ? await ratelimit ( req . headers . get ( "x-forwarded-for" ) , rateLimitMaxRequests , ratelimitWindow )
@@ -150,7 +150,7 @@ export async function POST(req: Request) {
150150 )
151151 }
152152
153- // Extract user prompt from the last message
153+
154154 const lastMessage = messages [ messages . length - 1 ]
155155 let userPrompt = ''
156156 if ( Array . isArray ( lastMessage ?. content ) ) {
@@ -216,7 +216,7 @@ export async function POST(req: Request) {
216216 hasProjectContext : ! ! projectStructure
217217 } )
218218
219- // Enhanced error categorization
219+
220220 const errorMessage = error . message || "Unknown error"
221221
222222 if ( errorMessage . includes ( "API key" ) || errorMessage . includes ( "authentication" ) || error . status === 401 ) {
@@ -322,4 +322,4 @@ IMPORTANT GUIDELINES:
322322- Include proper security measures
323323
324324Generate complete, functional code that fulfills the user's request.`
325- }
325+ }
0 commit comments