Files
Momento/memento-note/app/api/ai/math-from-text/route.ts
Antigravity d5b409c1ac
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 1m28s
CI / Deploy production (on server) (push) Has been skipped
feat: équations mathématiques (KaTeX) — bloc, inline, barre visuelle, IA
- Bloc équation avec barre visuelle 20 symboles (fractions, intégrales, grec, etc.)
- Math en ligne : tape $x^2$ → rendu KaTeX inline automatique
- Math en bloc : tape $$E=mc^2$$ → converti en bloc
- Génération IA : décrit l'équation en langage naturel → LaTeX
- Service math-from-text + endpoint /api/ai/math-from-text
- CSS KaTeX importé
- i18n FR/EN complet
2026-06-14 18:21:46 +00:00

39 lines
1.4 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { auth } from '@/auth'
import { mathFromTextService } from '@/lib/ai/services/math-from-text.service'
import { checkEntitlementOrThrow, QuotaExceededError, incrementUsageAsync } from '@/lib/entitlements'
export async function POST(request: NextRequest) {
try {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { description } = await request.json()
if (!description || typeof description !== 'string' || !description.trim()) {
return NextResponse.json({ error: 'Description is required' }, { status: 400 })
}
try {
await checkEntitlementOrThrow(session.user.id, 'reformulate')
} catch (err) {
if (err instanceof QuotaExceededError) {
const isTierLocked = err.currentQuota === 0
return NextResponse.json(
{ error: isTierLocked ? 'feature_locked' : 'quota_exceeded', errorKey: isTierLocked ? 'ai.featureLocked' : 'ai.quotaExceeded', upgradeTier: err.upgradeTier, quotaExceeded: true },
{ status: 402 },
)
}
throw err
}
const latex = await mathFromTextService.generate(description)
incrementUsageAsync(session.user.id, 'reformulate')
return NextResponse.json({ latex })
} catch (error: any) {
return NextResponse.json({ error: error.message || 'Failed to generate LaTeX' }, { status: 500 })
}
}