food diary improvements
This commit is contained in:
@@ -45,6 +45,7 @@ class FoodInput(BaseModel):
|
||||
amount: Decimal = Field(gt=0)
|
||||
unit: Literal['g', 'ml']
|
||||
product_id: str | None = None
|
||||
inventory_package_id: str | None = None
|
||||
product_name: str | None = None
|
||||
brand: str | None = None
|
||||
barcode: str | None = None
|
||||
@@ -350,7 +351,7 @@ def create_server() -> MCPServer:
|
||||
@server.tool(structured_output=True, description='Search the authenticated user’s saved TaskNest food products before logging a known food. Returns serving sizes, portions, and nutrition per 100 g/ml. Does not change data.')
|
||||
async def food_search_products(query: str, limit: int = 20) -> dict[str, Any]:
|
||||
data = await api_request('GET', 'food/products/', params={'search': query, 'limit': min(max(limit, 1), 100)})
|
||||
fields = ('id', 'product_name', 'brand', 'barcode', 'base_unit', 'serving_size_text',
|
||||
fields = ('id', 'product_name', 'brand', 'barcode', 'base_unit', 'package_amount', 'package_unit', 'serving_size_text',
|
||||
'serving_amount', 'serving_unit', 'energy_kcal_100', 'carbohydrates_100',
|
||||
'protein_100', 'fat_100', 'fibre_100', 'sugars_100', 'salt_100', 'portions')
|
||||
return {'count': data['count'], 'products': [{k: item.get(k) for k in fields} for item in data['results']]}
|
||||
@@ -384,11 +385,11 @@ def create_server() -> MCPServer:
|
||||
return {'status': 'failed', 'reason': str(exc), 'idempotency_key': key}
|
||||
return {**data, 'idempotency_key': key}
|
||||
|
||||
@server.tool(structured_output=True, description='Create one food log entry for the authenticated user. For known foods, search TaskNest products first and use product_id; do not fabricate nutrition when reliable product data exists. For a user-requested estimated meal, product_name and estimated nutrition are allowed. Uses the user’s local date unless date is supplied. Reuse idempotency_key on retries.')
|
||||
@server.tool(structured_output=True, description='Create one food log entry for the authenticated user. For known foods, search TaskNest products first and use product_id; do not fabricate nutrition when reliable product data exists. Optional inventory_package_id atomically consumes the logged g/ml from that exact owned package; use a saved product portion conversion and inventory_get_stock to resolve natural units, never guess piece weights. Inventory logging requires idempotency_key; reuse it on retries. Uses the user’s local date unless date is supplied.')
|
||||
async def food_log(food: FoodInput, idempotency_key: str | None = None) -> dict[str, Any]:
|
||||
key = _key(idempotency_key)
|
||||
data = await api_request('POST', 'food/log/', payload=food.model_dump(mode='json', exclude_none=True), idempotency_key=key)
|
||||
return {'success': True, 'entry': _entry(data), 'idempotency_key': key}
|
||||
return {'success': True, 'entry': _entry(data), 'inventory_consumption_id': data.get('inventory_consumption_id'), 'idempotency_key': key}
|
||||
|
||||
@server.tool(structured_output=True, description='Update only the supplied fields of one owned food log entry by opaque ID. Changes existing data; product nutrition is recalculated by TaskNest when applicable.')
|
||||
async def food_update_entry(entry_id: str, changes: FoodUpdate) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user