get_car_data.json 4.8 KB

12345678
  1. {
  2. "name": "get_car_data",
  3. "description": "Wyszukaj dane klimatyzacji pojazdu (typ gazu, ilość, olej, adaptery). Podaj markę i/lub model i rok. Gdy API zwróci listę opcji do wyboru (np. silnik, model), zaprezentuj je użytkownikowi i wywołaj narzędzie ponownie z wybraną wartością.",
  4. "color": "linear-gradient(rgb(150,150,150), rgb(100,100,100))",
  5. "iconSrc": "",
  6. "schema": "[{\"id\":0,\"property\":\"make\",\"description\":\"Marka pojazdu (np. Toyota, BMW)\",\"type\":\"string\",\"required\":false},{\"id\":1,\"property\":\"model\",\"description\":\"Model pojazdu (np. Corolla, E46)\",\"type\":\"string\",\"required\":false},{\"id\":2,\"property\":\"year\",\"description\":\"Rok produkcji pojazdu\",\"type\":\"string\",\"required\":false},{\"id\":3,\"property\":\"engine\",\"description\":\"Silnik pojazdu (np. 1.8 - 141 kW / 192 KM) — podaj po wybraniu przez użytkownika\",\"type\":\"string\",\"required\":false}]",
  7. "func": "const fetch = require('node-fetch')\n\nconst base = String(($vars && ($vars.relay_base || $vars.webhook_base)) || 'http://localhost:8080').replace(/\\/$/,'')\nconst secret = String(($vars && $vars.relay_shared_secret) || '')\n\nconst make = typeof $make !== 'undefined' && $make ? String($make) : ''\nconst model = typeof $model !== 'undefined' && $model ? String($model) : ''\nconst year = typeof $year !== 'undefined' && $year ? String($year) : ''\nconst engine = typeof $engine !== 'undefined' && $engine ? String($engine) : ''\n\nif (!make && !model) return 'Błąd: podaj przynajmniej markę (make) lub model pojazdu'\nif (!secret) return 'Błąd: brak $vars.relay_shared_secret'\n\ntry {\n const body = {}\n if (make) body.make = make\n if (model) body.model = model\n if (year) body.year = year\n if (engine) body.engine = engine\n\n const res = await fetch(`${base}/tools/get_car_data`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${secret}`\n },\n body: JSON.stringify(body)\n })\n const data = await res.json()\n if (data.ok) {\n const result = data.data\n\n // Opcje do wyboru (model, marka, silnik)\n if (result && result.error === 'options') {\n const fieldName = result.field || 'pole'\n const options = (result.options || []).map(o => String(o).trim()).filter(Boolean)\n if (options.length === 0) {\n const carDesc = [make, model, year].filter(Boolean).join(' ')\n return `Brak danych o pojeździe \"${carDesc}\" w naszej bazie. Możliwe że to auto jest spoza zakresu obsługiwanych lat lub marka/model są wpisane niepoprawnie. Poinformuj klienta że nie mamy danych dla tego pojazdu.`\n }\n return `Potrzebny wybór dla pola \"${fieldName}\". Dostępne opcje:\\n${options.map((o, i) => `${i + 1}. ${o}`).join('\\n')}\\nZapytaj użytkownika o wybór, a następnie wywołaj narzędzie ponownie z wybraną wartością jako parametr \"${fieldName}\".`\n }\n\n // Sukces — dane o klimatyzacji auta\n if (result && result.success) {\n const car = result.selected_car || {}\n const gasType = (result.ac_gas_type || car.ek_ac_gas_type || '').toUpperCase()\n const engineStr = car.ek_engine_type && car.ek_engine_type.trim() && car.ek_engine_type.trim() !== '0.0 - kW / KM' ? ' ' + car.ek_engine_type.trim() : ''\n const carLabel = `${car.ek_brand || make} ${car.ek_model || model} ${car.ek_year || year}${engineStr}`\n\n let text = `Dane klimatyzacji dla ${carLabel}:\\n`\n text += `- Typ gazu: ${gasType}\\n`\n if (result.ac_gas_amount) text += `- Ilość gazu: ${result.ac_gas_amount}\\n`\n if (result.ac_oil) text += `- Olej: ${result.ac_oil} ${result.ac_oil_amount || ''}\\n`\n if (result.ac_ports_count) text += `- Liczba portów klimatyzacji: ${result.ac_ports_count}\\n`\n if (result.adapters) text += `- Wymagane adaptery: ${result.adapters}\\n`\n if (result.shop_url) text += `- Strona auta: ${result.shop_url}\\n`\n\n if (result.maybe_different_layout) {\n const gas2 = (result.different_layout_ac_gas_type || '').toUpperCase()\n text += `\\nUWAGA: To auto może mieć dwa różne warianty układu klimatyzacji. Drugi wariant używa gazu ${gas2}.\\n`\n }\n\n text += `\\n[INSTRUKCJA: Przekaż klientowi powyższe dane klimatyzacji. Jeśli pyta o produkty do naładowania klimatyzacji, użyj narzędzia get_product_compatibility z: car_brand=\"${car.ek_brand || make}\", car_model=\"${car.ek_model || model}\", car_year=\"${car.ek_year || year}\".]`\n return text\n }\n\n // Błąd z backendu (np. nie znaleziono auta)\n if (result && result.error) {\n return `Informacja z bazy: ${result.error}`\n }\n\n return JSON.stringify(result, null, 2)\n }\n return `Info: ${data.message || JSON.stringify(data)}`\n} catch (error) {\n return `Błąd połączenia: ${error?.message || String(error)}`\n}\n"
  8. }