|
147 | 147 | authType: 'none', |
148 | 148 | badge: 'Free · No key', |
149 | 149 | configFields: [ |
| 150 | + { key: 'city', label: 'City name', placeholder: 'Tokyo', hint: 'Name of your city (appears in weather report header)' }, |
150 | 151 | { key: 'lat', label: 'Latitude', placeholder: '35.6762', hint: 'Your city latitude (e.g. Tokyo: 35.6762, NYC: 40.7128, London: 51.5074)' }, |
151 | 152 | { key: 'lon', label: 'Longitude', placeholder: '139.6503', hint: 'Your city longitude (e.g. Tokyo: 139.6503, NYC: -74.0060, London: -0.1278)' } |
152 | 153 | ], |
|
422 | 423 | async function fetchWeatherContext(config) { |
423 | 424 | var lat = parseFloat(config.lat) || 35.6762; // default Tokyo |
424 | 425 | var lon = parseFloat(config.lon) || 139.6503; |
| 426 | + var city = config.city || 'Tokyo'; |
425 | 427 | try { |
426 | 428 | var url = 'https://api.open-meteo.com/v1/forecast?latitude=' + lat + '&longitude=' + lon + |
427 | 429 | '¤t=temperature_2m,relative_humidity_2m,apparent_temperature,precipitation,weather_code,wind_speed_10m' + |
|
437 | 439 | 95:'Thunderstorm', 96:'Thunderstorm with hail', 99:'Thunderstorm with heavy hail' |
438 | 440 | }; |
439 | 441 | var condition = wmo[cur.weather_code] || ('Code ' + cur.weather_code); |
| 442 | + var fetchTime = new Date().toUTCString(); |
440 | 443 | var lines = [ |
441 | | - '[Weather — Open-Meteo (lat:' + lat + ', lon:' + lon + ')]', |
442 | | - ' Condition: ' + condition, |
| 444 | + '[Live Weather Report — ' + city + ' (via Open-Meteo API)]', |
| 445 | + 'Fetched: ' + fetchTime, |
| 446 | + 'Location: ' + city + ' (lat:' + lat + ', lon:' + lon + ')', |
| 447 | + '', |
| 448 | + 'Current Conditions:', |
| 449 | + ' Weather: ' + condition, |
443 | 450 | ' Temperature: ' + cur.temperature_2m + '°C (feels like ' + cur.apparent_temperature + '°C)', |
444 | 451 | ' Humidity: ' + cur.relative_humidity_2m + '%', |
445 | | - ' Wind: ' + cur.wind_speed_10m + ' km/h', |
446 | | - ' Precipitation: ' + cur.precipitation + ' mm' |
| 452 | + ' Wind Speed: ' + cur.wind_speed_10m + ' km/h', |
| 453 | + ' Precipitation: ' + cur.precipitation + ' mm', |
447 | 454 | ]; |
| 455 | + // Add hourly forecast if available |
| 456 | + if (data.hourly && data.hourly.temperature_2m) { |
| 457 | + lines.push(''); |
| 458 | + lines.push('Hourly Forecast (next 24h):'); |
| 459 | + var hours = data.hourly.time || []; |
| 460 | + var temps = data.hourly.temperature_2m || []; |
| 461 | + for (var i = 0; i < Math.min(hours.length, 24); i += 3) { |
| 462 | + var hr = hours[i] ? hours[i].split('T')[1] || hours[i] : '??'; |
| 463 | + lines.push(' ' + hr + ' → ' + temps[i] + '°C'); |
| 464 | + } |
| 465 | + } |
448 | 466 | return lines.join('\n'); |
449 | 467 | } catch (e) { |
450 | 468 | return '[Weather] Failed to fetch: ' + e.message; |
451 | 469 | } |
452 | 470 | } |
453 | 471 |
|
| 472 | + |
454 | 473 | // --- Get Combined Context from All Enabled Connectors --- |
455 | 474 | async function getActiveContext(query) { |
456 | 475 | var parts = []; |
457 | 476 | var promises = []; |
| 477 | + var enabledIds = []; |
458 | 478 |
|
459 | 479 | Object.keys(REGISTRY).forEach(function (id) { |
460 | 480 | if (!isEnabled(id)) return; |
| 481 | + enabledIds.push(id); |
461 | 482 | var token = getToken(id); |
462 | 483 | var config = getConfig(id); |
463 | 484 |
|
|
474 | 495 | default: fetchPromise = Promise.resolve(null); |
475 | 496 | } |
476 | 497 |
|
477 | | - promises.push(fetchPromise.catch(function (e) { return null; })); |
| 498 | + promises.push(fetchPromise.catch(function (e) { |
| 499 | + console.error('[Connectors] Fetch failed for', id, ':', e.message); |
| 500 | + return null; |
| 501 | + })); |
478 | 502 | }); |
479 | 503 |
|
| 504 | + console.log('[Connectors] Enabled connectors:', enabledIds); |
480 | 505 | var results = await Promise.all(promises); |
481 | | - results.forEach(function (r) { if (r) parts.push(r); }); |
| 506 | + results.forEach(function (r, i) { |
| 507 | + console.log('[Connectors] Result', enabledIds[i], ':', r ? r.substring(0, 100) : 'NULL'); |
| 508 | + if (r) parts.push(r); |
| 509 | + }); |
482 | 510 |
|
483 | 511 | if (parts.length === 0) return null; |
484 | 512 |
|
|
0 commit comments