fix: auto-tagging provider resolution, email test flow, language detection
Auto-tagging: - CRITICAL FIX: contextual-auto-tag.service.ts was calling getAIProvider() (alias for getEmbeddingsProvider) instead of getTagsProvider(). This meant auto-tagging used the embeddings provider/model instead of the tags one. Now correctly uses getTagsProvider() in both suggestFromExistingLabels and suggestNewLabels methods. - Pass user's detected language to suggestLabels() for localized prompts (was hardcoded to 'en') Email: - Fix Resend "from" field: pass DB config to sendViaResend() instead of re-fetching from DB. Uses SMTP_FROM from config, with localhost-aware fallback. - Add "Sender email" field in admin Resend section so users can set SMTP_FROM - Save SMTP_FROM when Resend is selected (was only saved for SMTP mode) - Test email button now saves config to DB BEFORE testing, so unsaved form values are used (was reading stale DB values) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { getAIProvider } from '@/lib/ai/factory'
|
||||
import { getTagsProvider } from '@/lib/ai/factory'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
|
||||
export interface LabelSuggestion {
|
||||
@@ -77,7 +77,7 @@ export class ContextualAutoTagService {
|
||||
|
||||
try {
|
||||
const config = await getSystemConfig()
|
||||
const provider = getAIProvider(config)
|
||||
const provider = getTagsProvider(config)
|
||||
|
||||
// Use generateText with JSON response
|
||||
const response = await provider.generateText(prompt)
|
||||
@@ -161,7 +161,7 @@ export class ContextualAutoTagService {
|
||||
|
||||
try {
|
||||
const config = await getSystemConfig()
|
||||
const provider = getAIProvider(config)
|
||||
const provider = getTagsProvider(config)
|
||||
|
||||
// Use generateText with JSON response
|
||||
const response = await provider.generateText(prompt)
|
||||
|
||||
@@ -41,12 +41,12 @@ export async function sendEmail({ to, subject, html, attachments }: MailOptions,
|
||||
// Force Resend (no fallback)
|
||||
if (provider === 'resend') {
|
||||
if (!resendKey) return { success: false, error: 'No Resend API key configured' };
|
||||
return sendViaResend(resendKey, { to, subject, html, attachments });
|
||||
return sendViaResend(resendKey, config, { to, subject, html, attachments });
|
||||
}
|
||||
|
||||
// Auto: try Resend, fall back to SMTP
|
||||
if (resendKey) {
|
||||
const result = await sendViaResend(resendKey, { to, subject, html, attachments });
|
||||
const result = await sendViaResend(resendKey, config, { to, subject, html, attachments });
|
||||
if (result.success) return result;
|
||||
|
||||
console.warn('[Mail] Resend failed, falling back to SMTP:', result.error);
|
||||
@@ -56,14 +56,13 @@ export async function sendEmail({ to, subject, html, attachments }: MailOptions,
|
||||
return sendViaSMTP(config, { to, subject, html, attachments });
|
||||
}
|
||||
|
||||
async function sendViaResend(apiKey: string, { to, subject, html, attachments }: MailOptions): Promise<MailResult> {
|
||||
async function sendViaResend(apiKey: string, config: Record<string, string>, { to, subject, html, attachments }: MailOptions): Promise<MailResult> {
|
||||
try {
|
||||
const { Resend } = await import('resend');
|
||||
const resend = new Resend(apiKey);
|
||||
|
||||
// Build a valid "from" address for Resend
|
||||
// Priority: SMTP_FROM from DB config > env var > derived from NEXTAUTH_URL > Resend default
|
||||
const config = await getSystemConfig();
|
||||
const smtpFrom = config.SMTP_FROM || process.env.SMTP_FROM;
|
||||
let from: string;
|
||||
if (smtpFrom) {
|
||||
|
||||
Reference in New Issue
Block a user