Rend les liens entre notes visibles et persistants (sync NoteLink au save, auto-save, graphe réseau rafraîchi), ajoute living blocks, Memory Echo, recherche globale, consentement IA explicite et consolide les prototypes design en architectural-grid. Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { auth } from '@/auth'
|
|
import { getTagsProvider } from '@/lib/ai/factory'
|
|
import { getSystemConfig } from '@/lib/config'
|
|
import { hasUserAiConsent } from '@/lib/consent/server-consent'
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const session = await auth()
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
if (!(await hasUserAiConsent())) {
|
|
return NextResponse.json({ error: 'ai_consent_required' }, { status: 403 })
|
|
}
|
|
|
|
const { text, targetLanguage } = await request.json()
|
|
|
|
if (!text || !targetLanguage) {
|
|
return NextResponse.json({ error: 'text and targetLanguage are required' }, { status: 400 })
|
|
}
|
|
|
|
const config = await getSystemConfig()
|
|
const provider = getTagsProvider(config)
|
|
|
|
const prompt = `Translate the following text to ${targetLanguage}. Return ONLY the translated text, no explanation, no preamble, no quotes:\n\n${text}`
|
|
|
|
const translatedText = await provider.generateText(prompt)
|
|
|
|
return NextResponse.json({ translatedText: translatedText.trim() })
|
|
} catch (error: any) {
|
|
return NextResponse.json({ error: error.message || 'Translation failed' }, { status: 500 })
|
|
}
|
|
}
|