Commit Graph
11 Commits
Author SHA1 Message Date
Jorem Juárez 1d9498b6d5 Make AI consultant distinguish direct vs complement recommendations
The consultant could surface an unrelated dish as if it directly answered the
request. Now each recommendation is classified and presented accordingly.

- Prompt: model classifies each recommendation as type 'direct' (answers what was
  asked) or 'complement' (pairs with it). Direct first and primary; complements
  are optional and never used to pad to a count. Reasons must be anchored to a real
  dish attribute or the dish isn't recommended. If nothing matches directly, the
  intro says so gracefully instead of inventing a false direct match.
- Route: parse/validate the type (defaults to 'direct' if missing), keep existing
  existence validation, order direct-first then complements, cap at 3.
- UI: AiConsultant renders direct cards first, then a 'Para acompañar' / 'To pair
  with' header before complements (glassmorphism preserved).
- i18n: ai.pairWith in es/en (parity); the type field itself is internal, not translated.

Keeps prompt caching and the compact menu context. Verified: build passes; parser
orders direct-first, drops non-existent dishes, defaults missing type to direct.
2026-06-15 15:15:35 -06:00
Jorem Juárez c001550e4f Optimize and harden the AI consultant
A) Token optimization:
- Prompt caching: the stable block (system instructions + full menu) is now a
  single cached system text block with cache_control:ephemeral and goes first;
  the variable diner question stays in messages, after the cache breakpoint, so
  the cached prefix is byte-identical between queries of the same restaurant/locale
- Compact context: only name, price, short description (<=120 chars), diet tags
  and allergens; macros are omitted (rarely change a recommendation). Inactive
  dishes still skipped

B) Hardening:
- Validate existence: each recommended dish must match a real active menu name
  (accent/case/space-insensitive, both locales); non-existent dishes are dropped
- Fewer than 3 valid is fine — return what's valid, never pad with non-fitting dishes
- Robust parsing: reuse the import's tolerant parser (extractJson +
  repairTruncatedJson, now shared in lib/json.ts) so truncated/prose replies don't 502
- max_tokens 700 -> 900 and system prompt asks for one-sentence reasons

Refactor: repairTruncatedJson + parseLenientJson moved into lib/json.ts and shared
by import.ts and ai-consult. No behavior change to import.

Verified: build passes; existence filter drops fake dishes, recovers truncated+prose
replies, and returns <3 without padding.
2026-06-15 15:08:56 -06:00
Jorem Juárez 084a191061 Add per-restaurant macros toggle and public list view
Feature 1 — showMacros toggle:
- Restaurant.showMacros boolean (default false) so existing menus (e.g. NOCNEX)
  never publish with empty macros (migration 0004; default applies to existing rows)
- Editor toggle in the Palette tab, saved via the existing /settings endpoint
- Read live (not from the snapshot) in the public page and /menu API so it takes
  effect immediately without republishing; old snapshots default off
- When off, the public menu hides every macro layer: card flip + 'tap to see
  macros', the gallery macros, and the macro color-code legend

Feature 2 — public list view:
- Card/list toggle in the public menu; preference is NOT persisted (always starts
  on cards)
- New ListRow: compact traditional rows (name + price + allergen tags); tap the
  name to expand image + description (accordion); tap the image to reveal macros
  (only when showMacros is on)

i18n: viewCards/viewList (menu) and showMacros/showMacrosHint (editor) in es/en at parity.
Glassmorphism, mobile-first and safe areas preserved. Existing features untouched
(versioning, import, consultant, QR, i18n).

Verified: build passes; 4 migrations apply in order; existing rows default false;
toggling via /settings updates /menu live without republish.
2026-06-15 14:32:44 -06:00
Jorem Juárez d71ede3d00 Edge-to-edge mobile layout with safe-area insets
The public menu (and editor) left a non-matching rectangular gap around the
iPhone notch / dynamic island. Make the glassmorphism background go edge-to-edge
while keeping interactive content clear of the unsafe regions.

- viewport-fit=cover so the layout uses the full screen incl. behind the island
- Safe-area utility classes (globals.css) built on env(safe-area-inset-*); they
  resolve to 0 on devices without insets, preserving previous spacing
- Public menu: header padding-top, sticky section tabs offset, and floating
  action buttons (Ask AI / +) respect top/bottom insets
- Editor: header padding-top and bottom tab bar respect top/bottom insets

Verified: build passes; all safe-area classes survive Tailwind purge; rendered
meta tag emits viewport-fit=cover.
2026-06-15 13:46:27 -06:00
Jorem Juárez 9fad1d43aa Harden menu import: tolerate truncated JSON + reject oversized files
Bug 1 (malformed/truncated JSON crashed the route with SyntaxError):
- Raise extraction max_tokens 4000 -> 8000 and ask the model for compact, complete JSON
- Parse tolerantly: extractJson() for fences/prose, plus a repair pass that closes
  open strings/brackets and drops a trailing partial entry for token-truncated output
- Wrap JSON.parse; on failure return a friendly code (parse_failed, or output_truncated
  when stop_reason was max_tokens) instead of a raw 500

Bug 2 (40MB PDF -> Anthropic 413):
- Validate visual file size BEFORE calling the API (max 4.5MB raw; base64 inflates ~33%)
- Return 413 {error:file_too_large, maxMb} so the UI shows 'max X MB, compress or use text/link'

i18n: file_too_large (with {mb}), parse_failed, output_truncated (es/en); ImportModal
interpolates the size limit.

Verified: build passes; repair recovers mid-string/mid-property/fenced/prose JSON;
oversized upload returns 413 with the limit; text path fails gracefully (no crash).
2026-06-14 02:14:40 -06:00
Jorem Juárez 9a40a988e0 Add artistic QR (templates + customization) with qr-code-styling
Editor QR tab now generates a styled, scannable QR with live preview and clean
PNG/SVG export (no frame or text — the owner lays it out).

- Restaurant.qrConfig JSON persists the styling (migration 0003)
- qr-code-styling (MIT) runs client-side in QrTab: preview + WYSIWYG PNG (2048px)
  and vector SVG export, avoiding native canvas deps in the alpine image
- Controls: dots color/gradient, background (incl. transparent), corners color,
  dot & corner shapes, optional center logo (uploaded via /upload, capped at 20%)
- Scannability: error correction forced to 'H' whenever there's a logo or color;
  WCAG contrast check warns on low contrast; persistent 'verify before printing' notice
- Templates inherit the menu palette but every value is independently editable
- QR always targets {APP_BASE_URL}/{slug}
- PATCH /api/[slug]/qr saves config; GET stays as a config-aware server fallback
- i18n (es/en) for the qr namespace; glassmorphism, mobile-first

Verified: build passes; migration 0003 applies; PATCH persists qrConfig; GET
honors saved colors/ECC (png + colored svg); auth guard returns 401.
2026-06-14 02:00:45 -06:00
Jorem Juárez d6ffbbd60b Fix missing i18n keys in editor (save/edit/delete)
ProductEditor and CatalogTab use t('save'/'edit'/'delete') from the editor
namespace, but those keys only existed in the common namespace, so the UI showed
raw keys (editor.save, editor.delete). Add them to messages/es.json and en.json.

Audited every useTranslations call across src/ against both catalogs: no other
unresolved keys, and es/en are at full key parity.
2026-06-13 20:47:00 -06:00
Jorem Juárez 112e95dc28 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.
2026-06-13 20:43:06 -06:00
Jorem Juárez 24a412f793 Fix Prisma migrate deploy in standalone production image
The entrypoint invoked the node_modules/.bin/prisma symlink, so Node resolved the
CLI's bundled .wasm files relative to .bin/ and crashed with ENOENT on
prisma_schema_build_bg.wasm. Call the real CLI entry (node_modules/prisma/build/
index.js) instead so the wasm resolves under prisma/build/. Also add the
linux-musl-openssl-3.0.x binaryTarget so the runtime engine matches the alpine
runner regardless of build host arch.

Verified end-to-end in a built alpine image: migrate deploy applies, and the
Prisma client reads/writes against Postgres at runtime.
2026-06-13 20:13:21 -06:00
Jorem Juárez fc12ff5f02 Add public/ directory so Dockerfile COPY succeeds
Next.js standalone build copies /app/public; the folder was empty and untracked,
breaking the Docker build. Keep it in the repo via .gitkeep.
2026-06-13 19:59:25 -06:00
Jorem Juárez 5fb9c7a145 Initial build: Menú inteligente platform
Multi-tenant digital menu platform (Collina Systems): public QR menu with
glassmorphism + 3D macro flip cards, mobile-first editor with draft/publish
versioning (5-version history + restore), AI consultant & translation (Claude
Haiku), realtime orders via SSE, configurable palette, QR generation, superadmin
panel, and Docker/Coolify infra.
2026-06-13 19:33:00 -06:00