feat: implement plant health check functionality with AI analysis, credit management, and UI integration

This commit is contained in:
2026-04-08 21:27:50 +02:00
parent de8130686a
commit 09078c3c20
5 changed files with 46 additions and 21 deletions

View File

@@ -107,10 +107,16 @@ const normalizeIdentifyResult = (raw, language) => {
const waterIntervalRaw = getNumber(careInfoRaw.waterIntervalDays);
const light = getString(careInfoRaw.light);
const temp = getString(careInfoRaw.temp);
if (waterIntervalRaw == null || !light || !temp) {
if (waterIntervalRaw == null) {
return null;
}
const LIGHT_DEFAULTS = { de: 'Helles indirektes Licht', es: 'Luz indirecta brillante', en: 'Bright indirect light' };
const TEMP_DEFAULTS = { de: '1525 °C', es: '1525 °C', en: '5977 °F (1525 °C)' };
const lang = language || 'en';
const resolvedLight = (light && light !== 'Unknown') ? light : (LIGHT_DEFAULTS[lang] || LIGHT_DEFAULTS.en);
const resolvedTemp = (temp && temp !== 'Unknown') ? temp : (TEMP_DEFAULTS[lang] || TEMP_DEFAULTS.en);
const fallbackDescription = language === 'de'
? `${name} wurde per KI erkannt. Pflegehinweise sind unten aufgefuehrt.`
: language === 'es'
@@ -124,8 +130,8 @@ const normalizeIdentifyResult = (raw, language) => {
description: description || fallbackDescription,
careInfo: {
waterIntervalDays: Math.round(clamp(waterIntervalRaw, 1, 45)),
light,
temp,
light: resolvedLight,
temp: resolvedTemp,
},
};
};
@@ -216,6 +222,10 @@ const buildIdentifyPrompt = (language, mode) => {
'Rules:',
nameLanguageInstruction,
`- "description" and "careInfo.light" must be written in ${getLanguageLabel(language)}.`,
`- "careInfo.light": short light requirement in ${getLanguageLabel(language)} (e.g. "bright indirect light", "full sun", "partial shade"). Must always be a real value, never "Unknown".`,
language === 'en'
? '- "careInfo.temp": temperature range in both Celsius and Fahrenheit (e.g. "1824 °C (6475 °F)"). Must always be a real plant-specific value, never "Unknown".'
: '- "careInfo.temp": temperature range in Celsius (e.g. "1824 °C"). Must always be a real plant-specific value, never "Unknown".',
'- "botanicalName" must use accepted Latin scientific naming and must not be invented or misspelled.',
'- If species is uncertain, prefer genus-level naming (for example: "Calathea sp.").',
'- "confidence" must be between 0 and 1.',
@@ -356,7 +366,7 @@ const identifyPlant = async ({ imageUri, language, mode = 'primary', plan = 'fre
role: 'user',
content: [
{ type: 'text', text: buildIdentifyPrompt(language, mode) },
{ type: 'image_url', image_url: { url: imageUri } },
{ type: 'image_url', image_url: { url: imageUri, detail: 'low' } },
],
},
],
@@ -416,7 +426,7 @@ const analyzePlantHealth = async ({ imageUri, language, plantContext }) => {
role: 'user',
content: [
{ type: 'text', text: buildHealthPrompt(language, plantContext) },
{ type: 'image_url', image_url: { url: imageUri } },
{ type: 'image_url', image_url: { url: imageUri, detail: 'low' } },
],
},
],