mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
feat(llm-parse): read a photo, as a booking or as a receipt in Costs
Whether the AI Parsing model reads images is an admin setting now, and it lands with the two features that send a photo, so it has something to control. The setting is `vision: 'auto' | 'on' | 'off'` on the addon config. On Automatic a local Ollama is asked what the model can do (`/api/show`), and a cloud provider means no; Yes and No are applied as set. The old `multimodal` flag is not read: the admin screens wrote it false on every save, so a stored false meant nothing. The per-user toggle keeps its on/off meaning and is read by the extraction now. The lookup is server-side only: capped read, validated body, never throws, cached per server and model. GET /api/llm/capabilities answers it for the signed-in caller, and both photo pickers below ask it. The booking import takes JPG, PNG and WEBP when the model reads images. The photo goes as an image to every provider (image_url, an Anthropic image block, Ollama's native chat with `images`), capped at 1600px, and skips KDE Itinerary. A scanned PDF, which used to reach the model as empty text, has its first two pages drawn by pdf-parse and sent the same way. The rest is the import as it was: background job, review, the file attached to the booking, the linked cost. On a real qwen3.5:4b a train ticket came back as bare clock times until the router gave the model every type's field meanings, and its price as an object inside a string, which read as 4900; both are handled. Costs gets Scan receipt: a dialog laid out like the booking import's takes one photo, read on the import job queue, then reviewed in the existing expense editor pre-filled with merchant, total, currency, day and lines, the photo waiting in Receipts & Invoices to be uploaded on save. No table, no migration, no category guess, no document-type detection.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* A photographed receipt, as the AI model read it for the Costs tab.
|
||||
*
|
||||
* It only pre-fills the expense editor: nothing is saved until the person saves
|
||||
* the expense there, so every field may be missing and each is checked by eye.
|
||||
* There is no category: which kind of spending it was is the person's call.
|
||||
*/
|
||||
export const receiptLineSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
/** What the line cost in total, quantity included, in the receipt's currency. */
|
||||
price: z.number(),
|
||||
});
|
||||
export type ReceiptLine = z.infer<typeof receiptLineSchema>;
|
||||
|
||||
export const receiptReadSchema = z.object({
|
||||
/** The business, which becomes the expense name. */
|
||||
merchant: z.string().min(1).nullable(),
|
||||
/** YYYY-MM-DD. */
|
||||
date: z
|
||||
.string()
|
||||
.regex(/^\d{4}-\d{2}-\d{2}$/)
|
||||
.nullable(),
|
||||
/** The grand total paid. */
|
||||
total: z.number().positive().nullable(),
|
||||
/** ISO 4217. */
|
||||
currency: z
|
||||
.string()
|
||||
.regex(/^[A-Z]{3}$/)
|
||||
.nullable(),
|
||||
/** The itemized lines, which seed the Ticket split. */
|
||||
items: z.array(receiptLineSchema),
|
||||
});
|
||||
export type ReceiptRead = z.infer<typeof receiptReadSchema>;
|
||||
|
||||
/** What a finished receipt scan job answers: the read, or null with the reason in `warnings`. */
|
||||
export const receiptScanResultSchema = z.object({
|
||||
receipt: receiptReadSchema.nullable(),
|
||||
warnings: z.array(z.string()),
|
||||
});
|
||||
export type ReceiptScanResult = z.infer<typeof receiptScanResultSchema>;
|
||||
|
||||
/** POST /api/trips/:tripId/budget/receipt-scan: the background job reading the photo. */
|
||||
export const receiptScanStartResponseSchema = z.object({ jobId: z.string().min(1) });
|
||||
export type ReceiptScanStartResponse = z.infer<typeof receiptScanStartResponseSchema>;
|
||||
Reference in New Issue
Block a user