Files
Momento/memento-note/app/api/ai/reformulate/route.ts
sepehr 153c921960
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 1m7s
fix: comprehensive i18n — replace hardcoded French/English strings with t() calls
Replaced ~100+ hardcoded French and English text strings across 30+ components
with proper i18n t() calls. Added 57 new translation keys to all 15 locale files
(ar, de, en, es, fa, fr, hi, it, ja, ko, nl, pl, pt, ru, zh).

Key changes:
- contextual-ai-chat.tsx: 30 French strings → t() (actions, toasts, labels, placeholders)
- ai-chat.tsx: 15 French/English strings → t() (header, tabs, welcome, insights, history)
- note-inline-editor.tsx: 20 French fallbacks removed (toolbar, save status, checklist)
- lab-skeleton.tsx: French loading text → t()
- admin-header.tsx, header.tsx, editor-connections-section.tsx: French fallbacks removed
- New AI chat component, agent cards, sidebar, settings panel i18n cleanup

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-26 21:14:45 +02:00

65 lines
2.0 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { auth } from '@/auth'
import { paragraphRefactorService } from '@/lib/ai/services/paragraph-refactor.service'
import { getAISettings } from '@/app/actions/ai-settings'
export async function POST(request: NextRequest) {
try {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
// Respect user's paragraphRefactor toggle (Assistant IA)
const userSettings = await getAISettings(session.user.id)
if (userSettings.paragraphRefactor === false) {
return NextResponse.json({ error: 'Feature disabled' }, { status: 403 })
}
const { text, option } = await request.json()
// Validation
if (!text || typeof text !== 'string') {
return NextResponse.json({ error: 'Text is required' }, { status: 400 })
}
// Map option to refactor mode
const modeMap: Record<string, 'clarify' | 'shorten' | 'improveStyle'> = {
'clarify': 'clarify',
'shorten': 'shorten',
'improve': 'improveStyle'
}
const mode = modeMap[option]
if (!mode) {
return NextResponse.json(
{ error: 'Invalid option. Use: clarify, shorten, or improve' },
{ status: 400 }
)
}
// Validate word count
const validation = paragraphRefactorService.validateWordCount(text)
if (!validation.valid) {
return NextResponse.json({ error: validation.error }, { status: 400 })
}
// Use the ParagraphRefactorService
const result = await paragraphRefactorService.refactor(text, mode)
return NextResponse.json({
originalText: result.original,
reformulatedText: result.refactored,
option: option,
language: result.language,
wordCountChange: result.wordCountChange
})
} catch (error: any) {
return NextResponse.json(
{ error: error.message || 'Failed to reformulate text' },
{ status: 500 }
)
}
}