fix: increase reformulate word limit to 2000 + i18n error messages
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 4s
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 4s
- Raise MAX_WORDS from 500 to 2000 for text reformulation - Error messages now use i18n keys (ai.wordCountMin/Max) instead of hardcoded English strings - Client translates server errors using the user's UI language Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -42,7 +42,11 @@ export async function POST(request: NextRequest) {
|
||||
// Validate word count
|
||||
const validation = paragraphRefactorService.validateWordCount(text)
|
||||
if (!validation.valid) {
|
||||
return NextResponse.json({ error: validation.error }, { status: 400 })
|
||||
return NextResponse.json({
|
||||
error: validation.error,
|
||||
errorKey: validation.errorKey,
|
||||
params: validation.params,
|
||||
}, { status: 400 })
|
||||
}
|
||||
|
||||
// Use the ParagraphRefactorService
|
||||
|
||||
@@ -205,7 +205,13 @@ export function ContextualAIChat({
|
||||
body: JSON.stringify(action.body(noteContent, undefined, language)),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw new Error(data.error || t('ai.genericError'))
|
||||
if (!res.ok) {
|
||||
// Use i18n key if provided by the server
|
||||
if (data.errorKey) {
|
||||
throw new Error(t(data.errorKey, data.params || {}))
|
||||
}
|
||||
throw new Error(data.error || t('ai.genericError'))
|
||||
}
|
||||
const result = data[action.resultKey] || ''
|
||||
setActionPreview({ label: t(action.i18nKey), text: result })
|
||||
} catch (e: any) {
|
||||
|
||||
@@ -56,7 +56,7 @@ export const REFACTOR_OPTIONS: RefactorOption[] = [
|
||||
export class ParagraphRefactorService {
|
||||
private languageDetection: LanguageDetectionService
|
||||
private readonly MIN_WORDS = 10
|
||||
private readonly MAX_WORDS = 500
|
||||
private readonly MAX_WORDS = 2000
|
||||
|
||||
constructor() {
|
||||
this.languageDetection = new LanguageDetectionService()
|
||||
@@ -288,20 +288,24 @@ CRITICAL: Respond ONLY with the refactored text in ${language}. No explanations,
|
||||
/**
|
||||
* Validate that text is within acceptable word count range
|
||||
*/
|
||||
validateWordCount(content: string): { valid: boolean; error?: string } {
|
||||
validateWordCount(content: string): { valid: boolean; error?: string; errorKey?: string; params?: Record<string, number> } {
|
||||
const wordCount = content.split(/\s+/).length
|
||||
|
||||
if (wordCount < this.MIN_WORDS) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Please select at least ${this.MIN_WORDS} words to reformulate (currently ${wordCount} words)`
|
||||
errorKey: 'ai.wordCountMin',
|
||||
params: { min: this.MIN_WORDS, current: wordCount },
|
||||
error: `min:${this.MIN_WORDS}:current:${wordCount}`
|
||||
}
|
||||
}
|
||||
|
||||
if (wordCount > this.MAX_WORDS) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Please select at most ${this.MAX_WORDS} words to reformulate (currently ${wordCount} words)`
|
||||
errorKey: 'ai.wordCountMax',
|
||||
params: { max: this.MAX_WORDS, current: wordCount },
|
||||
error: `max:${this.MAX_WORDS}:current:${wordCount}`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -376,6 +376,8 @@
|
||||
"undoAI": "Undo AI transformation",
|
||||
"undoApplied": "Original text restored",
|
||||
"minWordsError": "Note must contain at least 5 words to use AI actions.",
|
||||
"wordCountMin": "Please select at least {min} words to reformulate (currently {current} words)",
|
||||
"wordCountMax": "Please select at most {max} words to reformulate (currently {current} words)",
|
||||
"genericError": "AI error",
|
||||
"actionError": "Error during AI action",
|
||||
"appliedToNote": "Applied to note",
|
||||
|
||||
@@ -376,6 +376,8 @@
|
||||
"undoAI": "Annuler la transformation IA",
|
||||
"undoApplied": "Texte original restauré",
|
||||
"minWordsError": "La note doit contenir au moins 5 mots pour utiliser les actions IA.",
|
||||
"wordCountMin": "Veuillez sélectionner au moins {min} mots pour reformuler ({current} mots sélectionnés)",
|
||||
"wordCountMax": "Veuillez sélectionner au maximum {max} mots pour reformuler ({current} mots sélectionnés)",
|
||||
"genericError": "Erreur IA",
|
||||
"actionError": "Erreur lors de l'action IA",
|
||||
"appliedToNote": "Appliqué à la note",
|
||||
|
||||
Reference in New Issue
Block a user