nutri-cal 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +7 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -44,16 +44,20 @@ server.tool(
|
|
|
44
44
|
"calculate_nutrition",
|
|
45
45
|
{
|
|
46
46
|
chatID: z.string().describe("The chat session ID"),
|
|
47
|
+
meal_order: z.string().describe("The order of the meal "),
|
|
47
48
|
ingredientName: z.string().describe("The name of the ingredient"),
|
|
48
49
|
amount: z.number().describe("The amount of ingredient in grams"),
|
|
49
50
|
},
|
|
50
|
-
async ({ chatID, ingredientName, amount }) => {
|
|
51
|
+
async ({ chatID, meal_order, ingredientName, amount }) => {
|
|
51
52
|
try {
|
|
52
53
|
// 1. Fetch food data from Redis
|
|
53
54
|
const foodKey = `food:${ingredientName}`;
|
|
54
55
|
const foodData = await redis.hgetall(foodKey);
|
|
55
56
|
|
|
56
57
|
if (!foodData || Object.keys(foodData).length === 0) {
|
|
58
|
+
const errKey = `cal_err:${chatID}_${meal_order}`;
|
|
59
|
+
await redis.set(errKey, ingredientName);
|
|
60
|
+
|
|
57
61
|
return {
|
|
58
62
|
isError: true,
|
|
59
63
|
content: [
|
|
@@ -78,7 +82,7 @@ server.tool(
|
|
|
78
82
|
};
|
|
79
83
|
|
|
80
84
|
// 3. Store/Accumulate in Redis atomically
|
|
81
|
-
const userKey = `cal_res:${chatID}`;
|
|
85
|
+
const userKey = `cal_res:${chatID}_${meal_order}`;
|
|
82
86
|
|
|
83
87
|
const pipeline = redis.multi();
|
|
84
88
|
pipeline.hincrbyfloat(userKey, "Protein", calculatedNutrition.Protein);
|
|
@@ -101,7 +105,7 @@ Carbs: ${calculatedNutrition.Carbs.toFixed(2)}g
|
|
|
101
105
|
Fiber: ${calculatedNutrition.Fiber.toFixed(2)}g
|
|
102
106
|
Calories: ${calculatedNutrition.Calories.toFixed(2)}kcal
|
|
103
107
|
|
|
104
|
-
Successfully added to daily total for ChatID: ${chatID} (Expires in 10 minutes)`,
|
|
108
|
+
Successfully added to daily total for ChatID: ${chatID}, Meal: ${meal_order} (Expires in 10 minutes)`,
|
|
105
109
|
},
|
|
106
110
|
],
|
|
107
111
|
};
|