Grounding pipeline and recipe-search settings API
CI / ci (push) Successful in 1m49s
CI / ci (pull_request) Successful in 1m48s

recipes.Grounder ties search, fetch/extract, Rank, the photo cache and
normalize_recipe together. Ground(ctx, dishName, query) reuses a stored
source_url among the top candidates without fetching, otherwise tries the
ranked recipes best first and stores the photo, recipe, ingredients and
steps in one transaction, returning Grounded{recipe_id, photo_id, method,
minutes_total, difficulty, source_url, site_name} or a typed
*ErrUngroundable listing every reason. GroundURL grounds a pasted URL the
same way; GroundMany grounds items 3 at a time with per-item results.

PhotoCache is split into DownloadPhoto (fetch, decode, size check, no
writes) and CachePhoto(ctx, tx, photo), which records the row in the
caller's transaction; RemovePhotoFiles cleans up after a rollback.

Migration 0007 adds photo_id, method, difficulty and minutes_total to
recipes, and api_key_last4 to recipe_search_settings. SearXNG is now
called at recipe_search_settings.base_url.

GET/PATCH /api/v1/settings/recipe-search (Brave key sealed with
secretbox, only api_key_set and api_key_last4 returned) and POST
/api/v1/settings/recipe-search/test (searches "chicken tikka masala",
returns the count, 409 not_configured or 502 search_failed).

Maestro task 53afd59c-6c35-4af7-904c-6c167d1ad69d.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-05 15:06:39 -04:00
co-authored by Claude Opus 5.5
parent 2a19e89e5a
commit ceedc45309
27 changed files with 1821 additions and 143 deletions
+18
View File
@@ -0,0 +1,18 @@
-- 0007_recipe_grounding: a grounded recipe keeps what recipes.Ground
-- returns, so a stored source_url is reused without fetching or normalizing
-- it again: its cached photo, and normalize_recipe's method, difficulty and
-- minutes_total (prep to table; total_minutes stays the page's own JSON-LD
-- total). Nothing wrote recipes before Ground did, so the columns are added
-- nullable rather than with a default no recipe has; Ground always sets
-- photo_id, method and difficulty and refuses to reuse a row without them.
--
-- recipe_search_settings gains api_key_last4, the last four characters of
-- the Brave API key, so the settings can show which key is stored without
-- ever returning it.
ALTER TABLE recipes ADD COLUMN photo_id TEXT REFERENCES photos (id);
ALTER TABLE recipes ADD COLUMN method TEXT CHECK (method IN ('stovetop', 'oven', 'crockpot', 'grill', 'other'));
ALTER TABLE recipes ADD COLUMN difficulty TEXT CHECK (difficulty IN ('easy', 'medium', 'hard'));
ALTER TABLE recipes ADD COLUMN minutes_total INTEGER;
ALTER TABLE recipe_search_settings ADD COLUMN api_key_last4 TEXT;
+8 -2
View File
@@ -5,10 +5,12 @@
-- DeleteRecipeIngredients/DeleteRecipeSteps then the Create queries.
INSERT INTO recipes (
id, source_url, site_name, title, total_minutes, prep_minutes,
cook_minutes, yield, raw_jsonld, fetched_at, created_at, updated_at
cook_minutes, yield, raw_jsonld, photo_id, method, difficulty,
minutes_total, fetched_at, created_at, updated_at
) VALUES (
?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?
?, ?, ?, ?, ?, ?,
?, ?, ?, ?
)
ON CONFLICT (source_url) DO UPDATE SET
site_name = excluded.site_name,
@@ -18,6 +20,10 @@ ON CONFLICT (source_url) DO UPDATE SET
cook_minutes = excluded.cook_minutes,
yield = excluded.yield,
raw_jsonld = excluded.raw_jsonld,
photo_id = excluded.photo_id,
method = excluded.method,
difficulty = excluded.difficulty,
minutes_total = excluded.minutes_total,
fetched_at = excluded.fetched_at,
updated_at = excluded.updated_at
RETURNING *;
+3 -2
View File
@@ -70,14 +70,15 @@ WHERE id = 1;
-- Creates the single row (id 1) or replaces every column except id and
-- created_at.
INSERT INTO recipe_search_settings (
id, provider, base_url, api_key_ct, created_at, updated_at
id, provider, base_url, api_key_ct, api_key_last4, created_at, updated_at
) VALUES (
1, ?, ?, ?, ?, ?
1, ?, ?, ?, ?, ?, ?
)
ON CONFLICT (id) DO UPDATE SET
provider = excluded.provider,
base_url = excluded.base_url,
api_key_ct = excluded.api_key_ct,
api_key_last4 = excluded.api_key_last4,
updated_at = excluded.updated_at
RETURNING *;