feat: Refine keyword generation logic, enforce Serper API usage, and enhance search query construction with platform-specific templates.

This commit is contained in:
2026-02-03 22:52:13 +00:00
parent 358f2a42dd
commit f9222627ef
7 changed files with 274 additions and 209 deletions

View File

@@ -47,6 +47,13 @@ export async function POST(request: NextRequest) {
const body = await request.json()
const { analysis } = bodySchema.parse(body)
if (!process.env.SERPER_API_KEY) {
return NextResponse.json(
{ error: 'SERPER_API_KEY is not configured. Add it to your environment to run searches.' },
{ status: 400 }
)
}
console.log(`🔍 Finding opportunities for: ${analysis.productName}`)
// Sort queries by priority
@@ -103,15 +110,7 @@ export async function POST(request: NextRequest) {
}
async function searchGoogle(query: string, num: number): Promise<SearchResult[]> {
// Try Serper first
if (process.env.SERPER_API_KEY) {
try {
return await searchSerper(query, num)
} catch (e) {
console.error('Serper failed, falling back to direct')
}
}
return searchDirect(query, num)
return searchSerper(query, num)
}
async function searchSerper(query: string, num: number): Promise<SearchResult[]> {