Add AI smart menu import (Cargar menú)

Import a menu from PDF, photo, Excel/CSV, web link, or pasted text and turn it
into draft sections + products with Claude.

- Product.aiEstimated JSON flags AI-inferred macros/allergens (migration 0002)
- POST /api/[slug]/import: resolves the source (vision via Sonnet for PDF/photo,
  Haiku for text/CSV/XLSX/web), extracts structured JSON for review only
- POST /api/[slug]/import/apply: writes to the draft in add or replace mode,
  preserving aiEstimated flags; replace wipes the draft first
- Editor: 'Cargar menú' button + glass ImportModal (method -> review -> add/replace),
  'Estimado por IA — verifica' badges, verification disclaimer; ProductEditor shows
  the badge and clears the flag when the value is edited
- Reuses anthropic.ts, upload/guard, shared extractJson (moved to lib/json.ts)
- i18n labels (es/en); adds xlsx dependency for spreadsheet parsing

Verified: build passes; migration applies; apply add/replace persist correctly
with aiEstimated; extract validation + auth guard behave as expected.
This commit is contained in:
Jorem Juárez committed 2026-06-13 20:43:06 -06:00
1 parent 24a412f793
commit 112e95dc28
19 files changed
+819 -16

No files matched your search

+29
View File
@@ -84,6 +84,35 @@
"copied": "Copiado",
"paletteHint": "Esto no afecta el código de color de macros"
},
"import": {
"title": "Cargar menú",
"loadMenu": "Cargar menú",
"method": {
"file": "Archivo",
"link": "Link",
"text": "Texto"
},
"filePrompt": "Toca para elegir un archivo",
"fileHint": "PDF, foto de la carta, Excel o CSV",
"textPrompt": "Pega aquí el texto de tu menú…",
"disclaimer": "Las estimaciones (sobre todo los alérgenos) son generadas por IA y deben verificarse antes de publicar. Smart Menu no se responsabiliza por datos no verificados.",
"extract": "Extraer menú",
"extracting": "Leyendo tu menú con IA…",
"reviewSummary": "Encontramos {sections} secciones y {products} platillos. Revísalos antes de aplicar.",
"estimatedBadge": "Estimado por IA — verifica",
"modeAdd": "Añadir a mi menú actual",
"modeReplace": "Reemplazar mi menú actual",
"replaceWarning": "Esto borrará tus secciones y platillos actuales del borrador.",
"apply": "Aplicar al borrador",
"errors": {
"import_failed": "No pudimos leer ese menú. Intenta con otro archivo o pega el texto.",
"nothing_found": "No encontramos platillos en lo que enviaste.",
"invalid_link": "El link no es válido.",
"fetch_failed": "No pudimos abrir ese link.",
"empty_text": "Pega algo de texto primero.",
"no_file": "Elige un archivo primero."
}
},
"auth": {
"login": "Iniciar sesión",
"username": "Usuario",