feat: Refine keyword generation logic, enforce Serper API usage, and enhance search query construction with platform-specific templates.
This commit is contained in:
@@ -20,7 +20,6 @@ const searchSchema = z.object({
|
||||
rateLimit: z.number()
|
||||
})),
|
||||
strategies: z.array(z.string()),
|
||||
intensity: z.enum(['broad', 'balanced', 'targeted']),
|
||||
maxResults: z.number().default(50)
|
||||
})
|
||||
})
|
||||
@@ -41,6 +40,18 @@ export async function POST(request: NextRequest) {
|
||||
const { projectId, config } = parsed
|
||||
jobId = parsed.jobId
|
||||
|
||||
if (!process.env.SERPER_API_KEY) {
|
||||
const errorMessage = "SERPER_API_KEY is not configured. Add it to your environment to run searches."
|
||||
if (jobId) {
|
||||
await fetchMutation(
|
||||
api.searchJobs.update,
|
||||
{ jobId: jobId as any, status: "failed", error: errorMessage },
|
||||
{ token: await convexAuthNextjsToken() }
|
||||
)
|
||||
}
|
||||
return NextResponse.json({ error: errorMessage }, { status: 400 })
|
||||
}
|
||||
|
||||
const token = await convexAuthNextjsToken();
|
||||
if (jobId) {
|
||||
await fetchMutation(
|
||||
|
||||
@@ -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[]> {
|
||||
|
||||
Reference in New Issue
Block a user