feat: async product/receipt recognition via Kafka

Backend:
- Migration 002: product_recognition_jobs table with JSONB images column
  and job_type CHECK ('receipt' | 'products')
- New Kafka topics: ai.products.paid / ai.products.free
- ProductJob model, ProductJobRepository (mirrors dish job pattern)
- itemEnricher extracted from Handler — shared by HTTP handler and worker
- ProductSSEBroker: PG LISTEN on product_job_update channel
- ProductWorkerPool: 5 workers, branches on job_type to call
  RecognizeReceipt or RecognizeProducts per image in parallel
- Handler: RecognizeReceipt and RecognizeProducts now return 202 Accepted
  instead of blocking; 4 new endpoints: GET /ai/product-jobs,
  /product-jobs/history, /product-jobs/{id}, /product-jobs/{id}/stream
- cmd/worker: extended to run ProductWorkerPool alongside dish WorkerPool
- cmd/server: wires productJobRepository + productSSEBroker; both SSE
  brokers started in App.Start()

Flutter client:
- ProductJobCreated, ProductJobResult, ProductJobSummary, ProductJobEvent
  models + submitReceiptRecognition/submitProductsRecognition/stream methods
- Shared _openSseStream helper eliminates duplicate SSE parsing loop
- ScanScreen: replace blocking AI calls with async submit + navigate to
  ProductJobWatchScreen
- ProductJobWatchScreen: watches SSE stream, navigates to /scan/confirm
  when done, shows error on failure
- ProductsScreen: prepends _RecentScansSection (hidden when empty); compact
  horizontal list of recent scans with "See all" → history
- ProductJobHistoryScreen: full list of all product recognition jobs
- New routes: /scan/product-job-watch, /products/job-history
- L10n: 7 new keys in all 12 ARB files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-03-23 23:01:30 +02:00
parent bffeb05a43
commit c7317c4335
43 changed files with 2073 additions and 239 deletions

View File

@@ -28,7 +28,9 @@
"queuePosition": "Position {position}",
"@queuePosition": {
"placeholders": {
"position": { "type": "int" }
"position": {
"type": "int"
}
}
},
"processing": "Processing...",
@@ -116,7 +118,9 @@
"noResultsForQuery": "Nothing found for \"{query}\"",
"@noResultsForQuery": {
"placeholders": {
"query": { "type": "String" }
"query": {
"type": "String"
}
}
},
"servingsLabel": "Servings",
@@ -125,7 +129,9 @@
"planningForDate": "Planning for {date}",
"@planningForDate": {
"placeholders": {
"date": { "type": "String" }
"date": {
"type": "String"
}
}
},
"markAsEaten": "Mark as eaten",
@@ -134,7 +140,6 @@
"generateWeekSubtitle": "AI will create a menu with breakfast, lunch and dinner for the whole week",
"generatingMenu": "Generating menu...",
"dayPlannedLabel": "Day planned",
"planMenuButton": "Plan meals",
"planMenuTitle": "What to plan?",
"planOptionSingleMeal": "Single meal",
@@ -149,16 +154,23 @@
"planSelectMealType": "Meal type",
"planSelectRange": "Select period",
"planGenerateButton": "Plan",
"planGenerating": "Generating plan\u2026",
"planGenerating": "Generating plan",
"planSuccess": "Menu planned!",
"planProductsTitle": "Products for the menu",
"planProductsSubtitle": "AI will take the selected products into account when generating recipes",
"planProductsEmpty": "No products added",
"planProductsEmptyMessage": "Add products you have at home \u2014 AI will suggest recipes from what you already have",
"planProductsEmptyMessage": "Add products you have at home AI will suggest recipes from what you already have",
"planProductsAddProducts": "Add products",
"planProductsContinue": "Continue",
"planProductsSkip": "Skip product selection",
"planProductsSkipNoProducts": "Plan without products",
"planProductsSelectAll": "Select all",
"planProductsDeselectAll": "Deselect all"
"planProductsDeselectAll": "Deselect all",
"recentScans": "Recent scans",
"seeAllScans": "See all",
"productJobHistoryTitle": "Scan history",
"jobTypeReceipt": "Receipt",
"jobTypeProducts": "Products",
"scanSubmitting": "Submitting...",
"processingProducts": "Processing..."
}