fix: add proper logging for SMTP and AI brief generation
All checks were successful
Build & Push / build-and-push (push) Successful in 1m30s
All checks were successful
Build & Push / build-and-push (push) Successful in 1m30s
Logs now show: - Whether SMTP is configured and which addresses emails go to - Success/failure for each email (client brief + admin notification) - Whether OpenRouter API key is set - AI generation success/failure with status codes - Fallback to template brief when AI is unavailable Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -78,9 +78,12 @@ Timeline: ${timeline}`;
|
|||||||
async function generateBriefWithAI(body: ConfigureRequestBody): Promise<string> {
|
async function generateBriefWithAI(body: ConfigureRequestBody): Promise<string> {
|
||||||
const apiKey = process.env.OPENROUTER_API_KEY;
|
const apiKey = process.env.OPENROUTER_API_KEY;
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
|
console.log('[configure] OPENROUTER_API_KEY not set, using fallback brief template');
|
||||||
return generateFallbackBrief(body);
|
return generateFallbackBrief(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[configure] Generating AI brief via OpenRouter (deepseek/deepseek-v3.2)...');
|
||||||
|
|
||||||
const context = buildContext(body);
|
const context = buildContext(body);
|
||||||
const displayName = body.name.split(' ')[0] || body.name;
|
const displayName = body.name.split(' ')[0] || body.name;
|
||||||
|
|
||||||
@@ -131,10 +134,12 @@ ${context}`;
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error('OpenRouter API error:', response.status, response.statusText);
|
console.error(`[configure] OpenRouter API error: ${response.status} ${response.statusText}`);
|
||||||
return generateFallbackBrief(body);
|
return generateFallbackBrief(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[configure] AI brief generated successfully');
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const content = data.choices?.[0]?.message?.content;
|
const content = data.choices?.[0]?.message?.content;
|
||||||
|
|
||||||
@@ -144,9 +149,10 @@ ${context}`;
|
|||||||
|
|
||||||
return content;
|
return content;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('AI brief generation failed:', error);
|
console.error('[configure] AI brief generation failed:', error);
|
||||||
return generateFallbackBrief(body);
|
return generateFallbackBrief(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Fallback Brief (no API key or API failure) ──────────────────────────────
|
// ─── Fallback Brief (no API key or API failure) ──────────────────────────────
|
||||||
@@ -254,7 +260,12 @@ export async function POST(request: NextRequest) {
|
|||||||
const brief = await generateBriefWithAI(body);
|
const brief = await generateBriefWithAI(body);
|
||||||
|
|
||||||
// Send emails (non-blocking — don't fail the response if email fails)
|
// Send emails (non-blocking — don't fail the response if email fails)
|
||||||
if (process.env.SMTP_HOST && process.env.SMTP_PASS) {
|
const smtpHost = process.env.SMTP_HOST;
|
||||||
|
const smtpPass = process.env.SMTP_PASS;
|
||||||
|
|
||||||
|
if (smtpHost && smtpPass) {
|
||||||
|
console.log(`[configure] SMTP configured (host: ${smtpHost}), sending emails to ${body.email} and ${process.env.ADMIN_EMAIL || 'hello@letsbe.biz'}...`);
|
||||||
|
|
||||||
Promise.allSettled([
|
Promise.allSettled([
|
||||||
sendBriefToClient({
|
sendBriefToClient({
|
||||||
to: body.email,
|
to: body.email,
|
||||||
@@ -270,9 +281,18 @@ export async function POST(request: NextRequest) {
|
|||||||
services: body.services,
|
services: body.services,
|
||||||
email: body.email,
|
email: body.email,
|
||||||
}),
|
}),
|
||||||
]).catch(() => {
|
]).then((results) => {
|
||||||
console.error('Email sending failed');
|
results.forEach((result, i) => {
|
||||||
|
const target = i === 0 ? 'client brief' : 'admin notification';
|
||||||
|
if (result.status === 'fulfilled') {
|
||||||
|
console.log(`[configure] Email sent successfully: ${target}`);
|
||||||
|
} else {
|
||||||
|
console.error(`[configure] Email failed: ${target}`, result.reason);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.log(`[configure] SMTP not configured (SMTP_HOST: ${smtpHost ? 'set' : 'missing'}, SMTP_PASS: ${smtpPass ? 'set' : 'missing'}), skipping emails`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json({ success: true, brief });
|
return NextResponse.json({ success: true, brief });
|
||||||
|
|||||||
Reference in New Issue
Block a user