Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | 1x 26x 26x 26x 25x 1x 1x 1x 1x 1x 1x 24x 5x 19x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 1x | const API_BASE = '/api'
export interface AIStatus {
available: boolean
configured: boolean
valid: boolean
default_model: string
error: string | null
error_code: string | null
}
export interface AIErrorResponse {
error: string
message: string
action?: string // User action to resolve the error (e.g., 'configure_key', 'update_key', 'retry')
}
export interface AIModel {
id: string
name: string
}
export interface AIPrompt {
prompt_type: string
name: string
description: string
system_prompt: string
user_prompt_template: string
model: string
is_active: boolean
}
export interface AIPromptUpdate {
system_prompt?: string
user_prompt_template?: string
model?: string
is_active?: boolean
}
export interface RemixSuggestionsResponse {
suggestions: string[]
}
export interface RemixResponse {
id: number
title: string
description: string
ingredients: string[]
instructions: { text: string }[]
host: string
site_name: string
is_remix: boolean
prep_time: number | null
cook_time: number | null
total_time: number | null
yields: string
servings: number | null
}
export interface NutritionValues {
per_serving: Record<string, string | number>
total: Record<string, string | number>
}
export interface ScaleResponse {
target_servings: number
original_servings: number
ingredients: string[]
instructions: string[] // QA-031
notes: string[]
prep_time_adjusted: number | null // QA-032
cook_time_adjusted: number | null // QA-032
total_time_adjusted: number | null // QA-032
nutrition: NutritionValues | null
cached: boolean
}
export interface TipsResponse {
tips: string[]
cached: boolean
}
export interface DiscoverSuggestion {
type: string
title: string
description: string
search_query: string
}
export interface DiscoverResponse {
suggestions: DiscoverSuggestion[]
refreshed_at: string
}
export interface TimerNameResponse {
label: string
}
export interface TestApiKeyResponse {
success: boolean
message: string
}
export interface SaveApiKeyResponse {
success: boolean
message: string
}
export interface Profile {
id: number
name: string
avatar_color: string
theme: string
unit_preference: string
}
export interface ProfileStats {
favorites: number
collections: number
collection_items: number
remixes: number
view_history: number
scaling_cache: number
discover_cache: number
}
export interface ProfileWithStats {
id: number
name: string
avatar_color: string
theme: string
unit_preference: string
created_at: string
stats: ProfileStats
}
export interface DeletionData {
remixes: number
remix_images: number
favorites: number
collections: number
collection_items: number
view_history: number
scaling_cache: number
discover_cache: number
}
export interface ProfileSummary {
id: number
name: string
avatar_color: string
created_at: string
}
export interface DeletionPreview {
profile: ProfileSummary
data_to_delete: DeletionData
warnings: string[]
}
export interface ProfileInput {
name: string
avatar_color: string
theme?: string
unit_preference?: string
}
export interface Recipe {
id: number
title: string
host: string
image_url: string
image: string | null
total_time: number | null
rating: number | null
is_remix: boolean
scraped_at: string
}
export interface IngredientGroup {
purpose: string
ingredients: string[]
}
export interface RecipeDetail extends Recipe {
source_url: string | null
canonical_url: string
site_name: string
author: string
description: string
ingredients: string[]
ingredient_groups: IngredientGroup[]
instructions: string[]
instructions_text: string
prep_time: number | null
cook_time: number | null
yields: string
servings: number | null
category: string
cuisine: string
cooking_method: string
keywords: string[]
dietary_restrictions: string[]
equipment: string[]
nutrition: Record<string, string>
rating_count: number | null
language: string
links: string[]
ai_tips: string[]
remix_profile_id: number | null
updated_at: string
}
export interface Favorite {
recipe: Recipe
created_at: string
}
export interface HistoryItem {
recipe: Recipe
viewed_at: string
}
export interface Collection {
id: number
name: string
description: string
recipe_count: number
created_at: string
updated_at: string
}
export interface CollectionItem {
recipe: Recipe
order: number
added_at: string
}
export interface CollectionDetail {
id: number
name: string
description: string
recipes: CollectionItem[]
created_at: string
updated_at: string
}
export interface CollectionInput {
name: string
description?: string
}
export interface SearchResult {
url: string
title: string
host: string
image_url: string
cached_image_url: string | null
description: string
rating_count: number | null
}
export interface SearchResponse {
results: SearchResult[]
total: number
page: number
has_more: boolean
sites: Record<string, number>
}
// Sources
export interface Source {
id: number
host: string
name: string
is_enabled: boolean
search_url_template: string
result_selector: string
logo_url: string
last_validated_at: string | null
consecutive_failures: number
needs_attention: boolean
}
export interface SourceTestResult {
success: boolean
message: string
results_count: number
sample_results: string[]
}
export interface TestAllSourcesResult {
tested: number
passed: number
failed: number
details: {
id: number
name: string
host: string
success: boolean
results_count?: number
error?: string
}[]
}
// System/Admin
export interface ResetDataCounts {
profiles: number
recipes: number
recipe_images: number
favorites: number
collections: number
collection_items: number
view_history: number
ai_suggestions: number
serving_adjustments: number
cached_search_images: number
}
export interface ResetPreview {
data_counts: ResetDataCounts
preserved: string[]
warnings: string[]
}
export interface ResetResult {
success: boolean
message: string
actions_performed: string[]
}
async function request<T>(
endpoint: string,
options: RequestInit = {}
): Promise<T> {
const url = `${API_BASE}${endpoint}`
const config: RequestInit = {
...options,
headers: {
'Content-Type': 'application/json',
...options.headers,
},
}
const response = await fetch(url, config)
if (!response.ok) {
// Read body as text first (can only be read once)
const errorText = await response.text()
let errorMessage = errorText || `Request failed with status ${response.status}`
// Try to parse as JSON to extract detail/message
try {
const errorData = JSON.parse(errorText)
errorMessage = errorData.detail || errorData.message || errorMessage
} catch {
// Not JSON, use text as-is
}
throw new Error(errorMessage)
}
// Handle 204 No Content
if (response.status === 204) {
return null as T
}
return response.json()
}
export const api = {
ai: {
status: () => request<AIStatus>('/ai/status'),
testApiKey: (apiKey: string) =>
request<TestApiKeyResponse>('/ai/test-api-key', {
method: 'POST',
body: JSON.stringify({ api_key: apiKey }),
}),
saveApiKey: (apiKey: string) =>
request<SaveApiKeyResponse>('/ai/save-api-key', {
method: 'POST',
body: JSON.stringify({ api_key: apiKey }),
}),
models: () => request<AIModel[]>('/ai/models'),
prompts: {
list: () => request<AIPrompt[]>('/ai/prompts'),
get: (promptType: string) => request<AIPrompt>(`/ai/prompts/${promptType}`),
update: (promptType: string, data: AIPromptUpdate) =>
request<AIPrompt>(`/ai/prompts/${promptType}`, {
method: 'PUT',
body: JSON.stringify(data),
}),
},
remix: {
getSuggestions: (recipeId: number) =>
request<RemixSuggestionsResponse>('/ai/remix-suggestions', {
method: 'POST',
body: JSON.stringify({ recipe_id: recipeId }),
}),
create: (recipeId: number, modification: string, profileId: number) =>
request<RemixResponse>('/ai/remix', {
method: 'POST',
body: JSON.stringify({
recipe_id: recipeId,
modification,
profile_id: profileId,
}),
}),
},
scale: (recipeId: number, targetServings: number, profileId: number, unitSystem: string = 'metric') =>
request<ScaleResponse>('/ai/scale', {
method: 'POST',
body: JSON.stringify({
recipe_id: recipeId,
target_servings: targetServings,
profile_id: profileId,
unit_system: unitSystem,
}),
}),
tips: (recipeId: number, regenerate: boolean = false) =>
request<TipsResponse>('/ai/tips', {
method: 'POST',
body: JSON.stringify({ recipe_id: recipeId, regenerate }),
}),
discover: (profileId: number) =>
request<DiscoverResponse>(`/ai/discover/${profileId}/`),
timerName: (stepText: string, durationMinutes: number) =>
request<TimerNameResponse>('/ai/timer-name', {
method: 'POST',
body: JSON.stringify({
step_text: stepText,
duration_minutes: durationMinutes,
}),
}),
},
profiles: {
list: () => request<ProfileWithStats[]>('/profiles/'),
get: (id: number) => request<Profile>(`/profiles/${id}/`),
create: (data: ProfileInput) =>
request<Profile>('/profiles/', {
method: 'POST',
body: JSON.stringify(data),
}),
update: (id: number, data: ProfileInput) =>
request<Profile>(`/profiles/${id}/`, {
method: 'PUT',
body: JSON.stringify(data),
}),
delete: (id: number) =>
request<null>(`/profiles/${id}/`, {
method: 'DELETE',
}),
select: (id: number) =>
request<Profile>(`/profiles/${id}/select/`, {
method: 'POST',
}),
deletionPreview: (id: number) =>
request<DeletionPreview>(`/profiles/${id}/deletion-preview/`),
},
favorites: {
list: () => request<Favorite[]>('/favorites/'),
add: (recipeId: number) =>
request<Favorite>('/favorites/', {
method: 'POST',
body: JSON.stringify({ recipe_id: recipeId }),
}),
remove: (recipeId: number) =>
request<null>(`/favorites/${recipeId}/`, {
method: 'DELETE',
}),
},
history: {
list: (limit: number = 6) =>
request<HistoryItem[]>(`/history/?limit=${limit}`),
record: (recipeId: number) =>
request<HistoryItem>('/history/', {
method: 'POST',
body: JSON.stringify({ recipe_id: recipeId }),
}),
clear: () =>
request<null>('/history/', {
method: 'DELETE',
}),
},
collections: {
list: () => request<Collection[]>('/collections/'),
get: (id: number) => request<CollectionDetail>(`/collections/${id}/`),
create: (data: CollectionInput) =>
request<Collection>('/collections/', {
method: 'POST',
body: JSON.stringify(data),
}),
update: (id: number, data: CollectionInput) =>
request<Collection>(`/collections/${id}/`, {
method: 'PUT',
body: JSON.stringify(data),
}),
delete: (id: number) =>
request<null>(`/collections/${id}/`, {
method: 'DELETE',
}),
addRecipe: (collectionId: number, recipeId: number) =>
request<CollectionItem>(`/collections/${collectionId}/recipes/`, {
method: 'POST',
body: JSON.stringify({ recipe_id: recipeId }),
}),
removeRecipe: (collectionId: number, recipeId: number) =>
request<null>(`/collections/${collectionId}/recipes/${recipeId}/`, {
method: 'DELETE',
}),
},
recipes: {
get: (id: number) => request<RecipeDetail>(`/recipes/${id}/`),
search: (query: string, sources?: string, page: number = 1) => {
const params = new URLSearchParams({ q: query, page: String(page) })
if (sources) params.append('sources', sources)
return request<SearchResponse>(`/recipes/search/?${params}`)
},
scrape: (url: string) =>
request<RecipeDetail>('/recipes/scrape/', {
method: 'POST',
body: JSON.stringify({ url }),
}),
},
sources: {
list: () => request<Source[]>('/sources/'),
get: (id: number) => request<Source>(`/sources/${id}/`),
enabledCount: () =>
request<{ enabled: number; total: number }>('/sources/enabled-count/'),
toggle: (id: number) =>
request<{ id: number; is_enabled: boolean }>(`/sources/${id}/toggle/`, {
method: 'POST',
}),
bulkToggle: (enable: boolean) =>
request<{ updated_count: number; is_enabled: boolean }>(
'/sources/bulk-toggle/',
{
method: 'POST',
body: JSON.stringify({ enable }),
}
),
updateSelector: (id: number, selector: string) =>
request<{ id: number; result_selector: string }>(
`/sources/${id}/selector/`,
{
method: 'PUT',
body: JSON.stringify({ result_selector: selector }),
}
),
test: (id: number) =>
request<SourceTestResult>(`/sources/${id}/test/`, {
method: 'POST',
}),
testAll: () =>
request<TestAllSourcesResult>('/sources/test-all/', {
method: 'POST',
}),
},
system: {
resetPreview: () => request<ResetPreview>('/system/reset-preview/'),
reset: (confirmationText: string) =>
request<ResetResult>('/system/reset/', {
method: 'POST',
body: JSON.stringify({ confirmation_text: confirmationText }),
}),
},
}
|