feat: AI Writer inline — génère du contenu au curseur
- Mode 'write' ajouté à paragraph-refactor.service.ts - Endpoint /api/ai/reformulate étendu (option 'write' + writePrompt) - UI : champ de prompt inline apparaît au curseur après slash menu - Tape / → 'Écrire avec l'IA' → décrit ce que tu veux → Entrée - L'IA génère et insère le contenu à la position du curseur - Pas de migration DB, réutilise l'infra existante - i18n FR/EN
This commit is contained in:
@@ -23,39 +23,37 @@ export async function POST(request: NextRequest) {
|
||||
return NextResponse.json({ error: 'Feature disabled' }, { status: 403 })
|
||||
}
|
||||
|
||||
const { text, option, format, language } = await request.json()
|
||||
|
||||
// Validation
|
||||
if (!text || typeof text !== 'string') {
|
||||
return NextResponse.json({ error: 'Text is required' }, { status: 400 })
|
||||
}
|
||||
const { text, option, format, language, writePrompt } = await request.json()
|
||||
|
||||
// Map option to refactor mode
|
||||
const modeMap: Record<string, 'clarify' | 'shorten' | 'improveStyle' | 'fix_grammar' | 'translate' | 'explain'> = {
|
||||
const modeMap: Record<string, 'clarify' | 'shorten' | 'improveStyle' | 'fix_grammar' | 'translate' | 'explain' | 'write'> = {
|
||||
'clarify': 'clarify',
|
||||
'shorten': 'shorten',
|
||||
'improve': 'improveStyle',
|
||||
'fix_grammar': 'fix_grammar',
|
||||
'translate': 'translate',
|
||||
'explain': 'explain'
|
||||
'explain': 'explain',
|
||||
'write': 'write'
|
||||
}
|
||||
|
||||
const mode = modeMap[option]
|
||||
if (!mode) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid option. Use: clarify, shorten, improve, fix_grammar, translate, or explain' },
|
||||
{ error: 'Invalid option. Use: clarify, shorten, improve, fix_grammar, translate, explain, or write' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
// Validate word count
|
||||
const validation = paragraphRefactorService.validateWordCount(text)
|
||||
if (!validation.valid) {
|
||||
return NextResponse.json({
|
||||
error: validation.error,
|
||||
errorKey: validation.errorKey,
|
||||
params: validation.params,
|
||||
}, { status: 400 })
|
||||
// Validate word count (skip for 'write' mode — no selection needed)
|
||||
if (mode !== 'write') {
|
||||
const validation = paragraphRefactorService.validateWordCount(text)
|
||||
if (!validation.valid) {
|
||||
return NextResponse.json({
|
||||
error: validation.error,
|
||||
errorKey: validation.errorKey,
|
||||
params: validation.params,
|
||||
}, { status: 400 })
|
||||
}
|
||||
}
|
||||
|
||||
// Check quota
|
||||
@@ -75,7 +73,7 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
// Use the ParagraphRefactorService
|
||||
const result = await paragraphRefactorService.refactor(text, mode, format === 'html' ? 'html' : 'markdown', language)
|
||||
const result = await paragraphRefactorService.refactor(text, mode, format === 'html' ? 'html' : 'markdown', language, writePrompt)
|
||||
|
||||
incrementUsageAsync(session.user.id, 'reformulate')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user