Skip to content

Commit 1d91ea2

Browse files
committed
fix: Weather connector output + debug tracing
- Weather context now shows city name header, fetch timestamp, hourly forecast - Added city config field to Weather connector registry - Debug logging in getActiveContext() traces enabled connectors and results - Error catch now logs connector ID and error message
1 parent 530fcc0 commit 1d91ea2

2 files changed

Lines changed: 73 additions & 6 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Weather Connector — Enhanced Output & Debug Tracing
2+
3+
- Weather connector now outputs city name in header (`[Live Weather Report — Tokyo]`)
4+
- Added fetch timestamp to weather context for recency verification
5+
- Added hourly forecast (every 3 hours, next 24h) to weather context
6+
- Added `city` config field to Weather connector registry for user-customizable city label
7+
- Added debug logging to `getActiveContext()` — traces which connectors are enabled and their fetch results
8+
- Fixed: error catch in `getActiveContext` now logs failed connector ID and error message instead of silently swallowing
9+
10+
---
11+
12+
## Summary
13+
14+
Improved the Weather connector's context output to be more explicit and model-friendly, added a city name config field, and added debug tracing to diagnose cases where weather data doesn't reach the AI model.
15+
16+
---
17+
18+
## 1. Weather Context Formatting
19+
**Files:** `js/connectors.js`
20+
**What:** Replaced terse `[Weather — Open-Meteo (lat:..., lon:...)]` header with `[Live Weather Report — Tokyo (via Open-Meteo API)]` plus fetch timestamp, location line, and hourly forecast block (8 data points at 3h intervals).
21+
**Impact:** Small models like Gemma 4 E2B can now find and reference weather data in multi-source context thanks to clearer headers.
22+
23+
## 2. City Config Field
24+
**Files:** `js/connectors.js`
25+
**What:** Added `city` config field to the `openmeteo` registry entry. The value (default: `Tokyo`) appears in the weather report header. Users can customize this via the connector config modal.
26+
**Impact:** Weather reports are labeled with the user's city name, making the context more natural for AI grounding.
27+
28+
## 3. Debug Tracing
29+
**Files:** `js/connectors.js`
30+
**What:** `getActiveContext()` now logs `[Connectors] Enabled connectors: [...]` and per-connector result previews (first 100 chars or NULL). Error catches log the connector ID and error message.
31+
**Impact:** Enables diagnosing "weather data missing from context" issues via browser console.
32+
33+
---
34+
35+
## Files Changed (1 total)
36+
37+
| File | Lines Changed | Type |
38+
|------|:---:|------|
39+
| `js/connectors.js` | +34 −6 | Weather output enhancement, city field, debug logging |

js/connectors.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
authType: 'none',
148148
badge: 'Free · No key',
149149
configFields: [
150+
{ key: 'city', label: 'City name', placeholder: 'Tokyo', hint: 'Name of your city (appears in weather report header)' },
150151
{ key: 'lat', label: 'Latitude', placeholder: '35.6762', hint: 'Your city latitude (e.g. Tokyo: 35.6762, NYC: 40.7128, London: 51.5074)' },
151152
{ key: 'lon', label: 'Longitude', placeholder: '139.6503', hint: 'Your city longitude (e.g. Tokyo: 139.6503, NYC: -74.0060, London: -0.1278)' }
152153
],
@@ -422,6 +423,7 @@
422423
async function fetchWeatherContext(config) {
423424
var lat = parseFloat(config.lat) || 35.6762; // default Tokyo
424425
var lon = parseFloat(config.lon) || 139.6503;
426+
var city = config.city || 'Tokyo';
425427
try {
426428
var url = 'https://api.open-meteo.com/v1/forecast?latitude=' + lat + '&longitude=' + lon +
427429
'&current=temperature_2m,relative_humidity_2m,apparent_temperature,precipitation,weather_code,wind_speed_10m' +
@@ -437,27 +439,46 @@
437439
95:'Thunderstorm', 96:'Thunderstorm with hail', 99:'Thunderstorm with heavy hail'
438440
};
439441
var condition = wmo[cur.weather_code] || ('Code ' + cur.weather_code);
442+
var fetchTime = new Date().toUTCString();
440443
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,
443450
' Temperature: ' + cur.temperature_2m + '°C (feels like ' + cur.apparent_temperature + '°C)',
444451
' 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',
447454
];
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+
}
448466
return lines.join('\n');
449467
} catch (e) {
450468
return '[Weather] Failed to fetch: ' + e.message;
451469
}
452470
}
453471

472+
454473
// --- Get Combined Context from All Enabled Connectors ---
455474
async function getActiveContext(query) {
456475
var parts = [];
457476
var promises = [];
477+
var enabledIds = [];
458478

459479
Object.keys(REGISTRY).forEach(function (id) {
460480
if (!isEnabled(id)) return;
481+
enabledIds.push(id);
461482
var token = getToken(id);
462483
var config = getConfig(id);
463484

@@ -474,11 +495,18 @@
474495
default: fetchPromise = Promise.resolve(null);
475496
}
476497

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+
}));
478502
});
479503

504+
console.log('[Connectors] Enabled connectors:', enabledIds);
480505
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+
});
482510

483511
if (parts.length === 0) return null;
484512

0 commit comments

Comments
 (0)