feat(items): voice dictation with Gemma 4 and a reworked list UI

Dictation: a mic button in the add field uses the Web Speech API (es-AR) and
shows the partial transcript in the input. POST /api/voice/split asks Gemma 4
(Gemini API, plain fetch) to split the sentence into one string per item,
written the way the existing parser reads typed text; each string then goes
through the usual add flow. The endpoint never fails because of the model:
missing key, timeout, 429 or invalid JSON fall back to splitting on commas,
semicolons, " y " and " e ". A toast offers "Deshacer" for the whole dictation;
if the request fails, the transcript is added as a single item.

UI: "+" instead of the search icon, quantity tags ("2 L", "×12", "1 kg"), the
list name with a list switcher and the pending/bought count in the header,
"Comprados (N)" folded by default, and a bottom sheet to edit name, quantity
(− / + and unit), note and delete. PATCH items now accepts a name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-10-28 19:25:10 -03:00
parent eb1f6cb2a9
commit a814b34036
39 changed files with 1673 additions and 288 deletions

View File

@@ -0,0 +1,45 @@
/**
* Dictation: `POST /api/voice/split` turns a spoken sentence into one string per item,
* each written the way the web app's item parser (`apps/web/src/lib/natural-input`)
* reads typed text. The API only splits and normalizes; quantities are read by that
* parser, so these examples live here, where both workspaces can reach them: the API
* shows them to the model and the web tests check the parser reads them as expected.
*/
/** Body of `POST /api/voice/split`. */
export type VoiceSplitRequest = { text: string }
/** Response of `POST /api/voice/split`. */
export type VoiceSplitResponse = { items: string[] }
/** Longest transcript the API reads; the rest is cut off. */
export const VOICE_TEXT_MAX_LENGTH = 500
/** Most items one dictation can add. */
export const VOICE_MAX_ITEMS = 30
/** Longest item string kept from one dictation. */
export const VOICE_ITEM_MAX_LENGTH = 100
/**
* Few-shot examples for the model: what was said and the items it should answer with.
* Every item string is copied verbatim from the parser's tests (`parse-item.test.ts`).
*/
export const VOICE_SPLIT_EXAMPLES: { said: string; items: string[] }[] = [
{
said: 'dos pascualinas y un kilo y medio de papas',
items: ['2 pascualinas', '1,5 kg de papas'],
},
{
said: 'cuatrocientos de jamón feteado fino y una lata de atún',
items: ['400 de jamon. Feteado fino', '1 lata de atun'],
},
{
said: 'queso crema solo si hay marca tregar y seis yogures',
items: ['Queso crema. Solo si hay marca Tregar', '6 unidades de yogur'],
},
{
said: 'cuatrocientos gramos de queso y leche descremada',
items: ['400g de queso', 'Leche (descremada)'],
},
]