This commit is contained in:
2026-02-04 12:51:41 +00:00
parent 4fdbfb0fb3
commit f1e13f87f6
19 changed files with 722 additions and 67 deletions

View File

@@ -5,6 +5,7 @@ import { api } from "@/convex/_generated/api";
import { z } from 'zod'
import { analyzeFromText } from '@/lib/scraper'
import { performDeepAnalysis } from '@/lib/analysis-pipeline'
import { logServer } from "@/lib/server-logger";
const bodySchema = z.object({
productName: z.string().min(1),
@@ -22,6 +23,7 @@ export async function POST(request: NextRequest) {
detail?: string
}[] = []
try {
const requestId = request.headers.get("x-request-id") ?? undefined;
if (!(await isAuthenticatedNextjs())) {
const redirectUrl = new URL("/auth", request.url);
const referer = request.headers.get("referer");
@@ -100,7 +102,14 @@ export async function POST(request: NextRequest) {
)
}
console.log('📝 Creating content from manual input...')
await logServer({
level: "info",
message: "Preparing manual input for analysis",
labels: ["api", "analyze-manual", "scrape"],
payload: { productName },
requestId,
source: "api/analyze-manual",
});
const scrapedContent = await analyzeFromText(productName, description, features)
if (jobId) {
await updateTimeline({
@@ -111,7 +120,13 @@ export async function POST(request: NextRequest) {
})
}
console.log('🤖 Starting enhanced analysis...')
await logServer({
level: "info",
message: "Starting enhanced analysis",
labels: ["api", "analyze-manual", "analysis"],
requestId,
source: "api/analyze-manual",
});
const progressMap: Record<string, number> = {
features: 35,
competitors: 50,
@@ -128,7 +143,17 @@ export async function POST(request: NextRequest) {
progress: progressMap[update.key] ?? 80,
})
})
console.log(` ✓ Analysis complete: ${analysis.features.length} features, ${analysis.keywords.length} keywords`)
await logServer({
level: "info",
message: "Analysis complete",
labels: ["api", "analyze-manual", "analysis"],
payload: {
features: analysis.features.length,
keywords: analysis.keywords.length,
},
requestId,
source: "api/analyze-manual",
});
if (jobId) {
await updateTimeline({
key: "finalize",
@@ -186,7 +211,14 @@ export async function POST(request: NextRequest) {
persisted = true
}
} catch (persistError) {
console.error("Failed to persist manual analysis:", persistError)
await logServer({
level: "error",
message: "Failed to persist manual analysis",
labels: ["api", "analyze-manual", "persist", "error"],
payload: { error: String(persistError) },
requestId,
source: "api/analyze-manual",
});
}
}
@@ -205,7 +237,17 @@ export async function POST(request: NextRequest) {
})
} catch (error: any) {
console.error('❌ Manual analysis error:', error)
await logServer({
level: "error",
message: "Manual analysis error",
labels: ["api", "analyze-manual", "error"],
payload: {
message: error?.message,
stack: error?.stack,
},
requestId: request.headers.get("x-request-id") ?? undefined,
source: "api/analyze-manual",
});
if (jobId) {
try {