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:
53
apps/web/src/lib/natural-input/voice-examples.test.ts
Normal file
53
apps/web/src/lib/natural-input/voice-examples.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { VOICE_SPLIT_EXAMPLES } from '@superlist/shared'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { parseItemInput } from './parse-item'
|
||||
import { parseQuantity } from './quantity'
|
||||
|
||||
/**
|
||||
* The dictation examples the API shows the model (`@superlist/shared` → voice.ts) must be
|
||||
* written exactly the way this parser reads them: each string is one item with the
|
||||
* expected quantity, unit and note.
|
||||
*/
|
||||
const EXPECTED: Record<
|
||||
string,
|
||||
{ name: string; amount: number | null; unit: string | null; notes: string | null }
|
||||
> = {
|
||||
'2 pascualinas': { name: 'Pascualinas', amount: 2, unit: null, notes: null },
|
||||
'1,5 kg de papas': { name: 'Papas', amount: 1.5, unit: 'kg', notes: null },
|
||||
'400 de jamon. Feteado fino': { name: 'Jamón', amount: 400, unit: null, notes: 'Feteado fino' },
|
||||
'1 lata de atun': { name: 'Atún', amount: 1, unit: 'lata', notes: null },
|
||||
'Queso crema. Solo si hay marca Tregar': {
|
||||
name: 'Queso crema',
|
||||
amount: null,
|
||||
unit: null,
|
||||
notes: 'Solo si hay marca Tregar',
|
||||
},
|
||||
'6 unidades de yogur': { name: 'Yogur', amount: 6, unit: null, notes: null },
|
||||
'400g de queso': { name: 'Queso', amount: 400, unit: 'g', notes: null },
|
||||
'Leche (descremada)': { name: 'Leche', amount: null, unit: null, notes: 'Descremada' },
|
||||
}
|
||||
|
||||
describe('dictation few-shot examples', () => {
|
||||
const items = VOICE_SPLIT_EXAMPLES.flatMap((example) => example.items)
|
||||
|
||||
it('has an expectation for every example item', () => {
|
||||
expect([...items].sort()).toEqual(Object.keys(EXPECTED).sort())
|
||||
})
|
||||
|
||||
it.each(items)('parses "%s" as one item with the expected quantity and note', (text) => {
|
||||
const parsed = parseItemInput(text)
|
||||
expect(parsed).toHaveLength(1)
|
||||
|
||||
const [item] = parsed
|
||||
const quantity = item.quantity ? parseQuantity(item.quantity) : null
|
||||
const expected = EXPECTED[text]
|
||||
|
||||
expect({
|
||||
name: item.name,
|
||||
amount: quantity?.amount ?? null,
|
||||
unit: quantity?.unit ?? null,
|
||||
notes: item.notes,
|
||||
}).toEqual(expected)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user