feat(scanner): AI Gateway + Layer-1 OCR (convoy #3) #38

Merged
varutasu merged 1 commit from convoy/ai-gateway-and-ocr-layer into main 2026-05-27 13:59:59 -04:00
varutasu commented 2026-05-27 13:58:19 -04:00 (Migrated from github.com)

Summary

  • AI Gateway (Layer 2): Replace direct Gemini API with lib/scan-vision.jshttps://ai-gateway.vercel.sh/v1/chat/completions. Env: AI_GATEWAY_API_KEY, optional SCAN_VISION_MODEL (default google/gemini-2.5-flash-lite).
  • Layer 1 OCR (convoy #3): Tesseract name-strip OCR in browser (lib/ocr-worker.js) → POST /api/cards/identify-by-text with pg_trgm similarity on cards.name. Escalates to vision only when similarity < 0.6 or OCR fails.
  • Migration: 1779853647565_add-pg-trgm-card-name-index.jspg_trgm extension + GIN index on cards.name.
  • CI: schema-map-fresh now watches migrations/**; server-only allowlist updated for scan-vision.js.

Operator action

  • AI_GATEWAY_API_KEY set on Vercel (user confirmed)
  • Run npm run migrate up on production/preview Neon (pg_trgm migration)
  • Redeploy after merge

Test plan

  • npm run test:run — 21/21
  • npm run build — green (Turbopack + tesseract.js dynamic import)
  • Scan known catalog card → Layer 1 match (fast, no vision charge) or Layer 2 fallback
  • Ambiguous name → disambiguation modal from either layer
  • Check scan_attempts.layer distribution (target ≥70% layer=1 over time)

Made with Cursor

## Summary - **AI Gateway (Layer 2):** Replace direct Gemini API with `lib/scan-vision.js` → `https://ai-gateway.vercel.sh/v1/chat/completions`. Env: `AI_GATEWAY_API_KEY`, optional `SCAN_VISION_MODEL` (default `google/gemini-2.5-flash-lite`). - **Layer 1 OCR (convoy #3):** Tesseract name-strip OCR in browser (`lib/ocr-worker.js`) → `POST /api/cards/identify-by-text` with `pg_trgm` similarity on `cards.name`. Escalates to vision only when similarity < 0.6 or OCR fails. - **Migration:** `1779853647565_add-pg-trgm-card-name-index.js` — `pg_trgm` extension + GIN index on `cards.name`. - **CI:** `schema-map-fresh` now watches `migrations/**`; server-only allowlist updated for `scan-vision.js`. ## Operator action - [x] `AI_GATEWAY_API_KEY` set on Vercel (user confirmed) - [ ] Run `npm run migrate up` on production/preview Neon (pg_trgm migration) - [ ] Redeploy after merge ## Test plan - [x] `npm run test:run` — 21/21 - [x] `npm run build` — green (Turbopack + tesseract.js dynamic import) - [ ] Scan known catalog card → Layer 1 match (fast, no vision charge) or Layer 2 fallback - [ ] Ambiguous name → disambiguation modal from either layer - [ ] Check `scan_attempts.layer` distribution (target ≥70% layer=1 over time) Made with [Cursor](https://cursor.com)
vercel[bot] commented 2026-05-27 13:58:22 -04:00 (Migrated from github.com)

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tcg-vault Ready Ready Preview, Comment May 27, 2026 5:58pm

Request Review

[vc]: #8xbiXFhDlDAhvEJ9KBKGR236BiLzEk/SUKNh1KGi+h4=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJ0Y2ctdmF1bHQiLCJwcm9qZWN0SWQiOiJwcmpfRjZXOEVvRkd3Y0g3aWVGcnRvRlNlOXdVVkFhNSIsImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS9yYW5kYWxsLXN0aWxsd2VsbHMtcHJvamVjdHMvdGNnLXZhdWx0L0MxeG1zQUE5cm5hTjZMdmVzTWlHd1AzOFRHb1ciLCJwcmV2aWV3VXJsIjoidGNnLXZhdWx0LWdpdC1jb252b3ktYWktZ2F0ZS1hM2NmZTItcmFuZGFsbC1zdGlsbHdlbGxzLXByb2plY3RzLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQiLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoidGNnLXZhdWx0LWdpdC1jb252b3ktYWktZ2F0ZS1hM2NmZTItcmFuZGFsbC1zdGlsbHdlbGxzLXByb2plY3RzLnZlcmNlbC5hcHAifSwicm9vdERpcmVjdG9yeSI6bnVsbH1dLCJyZXF1ZXN0UmV2aWV3VXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL3ZlcmNlbC1hZ2VudC9yZXF1ZXN0LXJldmlldz9vd25lcj12YXJ1dGFzdSZyZXBvPXRjZy12YXVsdCZwcj0zOCJ9 The latest updates on your projects. Learn more about [Vercel for GitHub](https://vercel.link/github-learn-more). | Project | Deployment | Actions | Updated (UTC) | | :--- | :----- | :------ | :------ | | [tcg-vault](https://vercel.com/randall-stillwells-projects/tcg-vault) | ![Ready](https://vercel.com/static/status/ready.svg) [Ready](https://vercel.com/randall-stillwells-projects/tcg-vault/C1xmsAA9rnaN6LvesMiGwP38TGoW) | [Preview](https://tcg-vault-git-convoy-ai-gate-a3cfe2-randall-stillwells-projects.vercel.app), [Comment](https://vercel.live/open-feedback/tcg-vault-git-convoy-ai-gate-a3cfe2-randall-stillwells-projects.vercel.app?via=pr-comment-feedback-link) | May 27, 2026 5:58pm | <a href="https://vercel.com/vercel-agent/request-review?owner=varutasu&repo=tcg-vault&pr=38" rel="noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://agents-vade-review.vercel.sh/request-review-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://agents-vade-review.vercel.sh/request-review-light.svg"><img src="https://agents-vade-review.vercel.sh/request-review-light.svg" alt="Request Review"></picture></a>
github-actions[bot] commented 2026-05-27 13:58:31 -04:00 (Migrated from github.com)

Pipeline Health

Build + CI gates

Gate Status
Vercel build (Preview) pass
CI: Lint pass
CI: Schema map fresh skipped
Preview smoke pass
Visual diff pass

Build runs on Vercel; this CI runs lint and schema-map drift only (no duplicate build).

Role reports

Role Status
Reviewer report pending
A11y audit pending
Design system audit pending

See individual comments above for details. This rollup updates automatically.

<!-- pipeline-rollup --> ## Pipeline Health ### Build + CI gates | Gate | Status | | --- | --- | | Vercel build (Preview) | ✅ pass | | CI: Lint | ✅ pass | | CI: Schema map fresh | ❌ skipped | | Preview smoke | ✅ pass | | Visual diff | ✅ pass | _Build runs on Vercel; this CI runs lint and schema-map drift only (no duplicate build)._ ### Role reports | Role | Status | | --- | --- | | Reviewer report | ⏳ pending | | A11y audit | ⏳ pending | | Design system audit | ⏳ pending | See individual comments above for details. This rollup updates automatically.
github-actions[bot] commented 2026-05-27 13:59:35 -04:00 (Migrated from github.com)

Visual Diff

Screenshots and diffs uploaded as artifacts: view run

If intentional changes: update snapshots locally with npx playwright test --project=visual --update-snapshots and commit.

## Visual Diff Screenshots and diffs uploaded as artifacts: [view run](https://github.com/varutasu/tcg-vault/actions/runs/26529091522) If intentional changes: update snapshots locally with `npx playwright test --project=visual --update-snapshots` and commit.
Sign in to join this conversation.
No description provided.