@simonarcher/fika-types 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,79 @@
20
20
  * - `created_new` — user created a new bean record from this scan
21
21
  */
22
22
  export type BeanScanAction = "pending" | "saved" | "tried" | "rejected" | "created_new";
23
+ /**
24
+ * FIK-185 — AI vision draft persisted on bean_scans.ai_inferred when the
25
+ * trigram matcher returns bean_score < 0.4. Mobile uses this to prefill the
26
+ * AddBeanStep submission form; admin uses it to show the curator what AI
27
+ * suggested vs what the user actually submitted.
28
+ *
29
+ * Field shape mirrors the gpt-4o-mini extraction prompt in
30
+ * Fika-server/src/services/openAIService.ts (`extractBeanFromImage`).
31
+ * Curator-only fields (variety, roastDate, weightG) aren't on the mobile
32
+ * form — they sit here for the admin review screen to surface.
33
+ */
34
+ export interface BeanScanAiDraft {
35
+ name: string | null;
36
+ roasterName: string | null;
37
+ roastLevel: string | null;
38
+ processing: string | null;
39
+ country: string | null;
40
+ isDecaf: boolean | null;
41
+ tastingNotes: string[] | null;
42
+ variety: string | null;
43
+ roastDate: string | null;
44
+ weightG: number | null;
45
+ model: string;
46
+ latencyMs: number;
47
+ extractedAt: string;
48
+ }
49
+ /**
50
+ * FIK-187 — admin scan log + FIK-186 user scan history list shape.
51
+ *
52
+ * Returned by:
53
+ * GET /admin/bean-scans (admin-only, all users)
54
+ * GET /bean-scans/me (caller-only, pinned to res.locals.uid)
55
+ *
56
+ * Carries enough to render a list row without a per-row catalog lookup —
57
+ * the top candidate is denormalised in. The full `candidates` array,
58
+ * `ai_inferred` payload, and `device_meta` are returned only on the
59
+ * detail endpoints.
60
+ */
61
+ export interface BeanScanListItem {
62
+ id: string;
63
+ userId: string;
64
+ photoUrl: string;
65
+ ocrText?: string;
66
+ action: BeanScanAction;
67
+ matchedBeanId?: string;
68
+ /**
69
+ * Denormalised top candidate, derived server-side from the persisted
70
+ * `candidates` jsonb. Lets the list render a meaningful primary line
71
+ * without a join. May be undefined when the matcher returned zero
72
+ * candidates (e.g. empty OCR text).
73
+ */
74
+ topCandidate?: {
75
+ beanName: string;
76
+ roasterName: string;
77
+ score: number;
78
+ };
79
+ /** True when bean_scans.ai_inferred IS NOT NULL. */
80
+ hasAiInferred: boolean;
81
+ createdAt: string;
82
+ resolvedAt?: string;
83
+ }
84
+ /**
85
+ * Cursor-paginated list response shared by both endpoints.
86
+ *
87
+ * `nextCursor` is the ISO `created_at` of the oldest item in this page —
88
+ * caller passes it as `?before=<cursor>` on the next request. Null when
89
+ * exhausted.
90
+ */
91
+ export interface BeanScanListResponse {
92
+ success: true;
93
+ scans: BeanScanListItem[];
94
+ nextCursor: string | null;
95
+ }
23
96
  /**
24
97
  * One row per user scan event. Powers the bag-scan loop: photograph →
25
98
  * OCR + photo similarity → top-N candidate beans → user picks (or rejects).
@@ -47,6 +120,12 @@ export interface BeanScan {
47
120
  matchedBeanId?: string;
48
121
  action: BeanScanAction;
49
122
  deviceMeta?: Record<string, unknown>;
123
+ /**
124
+ * FIK-185 — gpt-4o-mini vision draft, set by POST /bean-scans/:id/enrich
125
+ * when the trigram matcher's top bean_score is below the auto-route gate.
126
+ * NULL until enriched (or if the kill switch is off).
127
+ */
128
+ aiInferred?: BeanScanAiDraft;
50
129
  createdAt: string;
51
130
  resolvedAt?: string;
52
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonarcher/fika-types",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "Shared TypeScript types for Fika projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",