fix(weather): 현풍 등 읍 단위 지명 좌표 오류 수정 + 국내 판정을 지오코더로 확장
Open-Meteo 지오코더가 "현풍"을 경주의 무명 지명으로 풀어 70km 떨어진 예보가 나갔다. 달성군 4개 읍을 KR_CITY_COORDS에 추가하고, openmeteo→kma 교정의 국내 판정을 지점표 밖 지명도 지오코더(대한민국)로 확인하도록 비동기로 확장했다. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1bfc60e57f
commit
9473186b0f
4 files changed
+36
-21
No files matched your search
@@ -2573,7 +2573,7 @@ async function handleChat(
|
||||
// 국내 지명의 weather_openmeteo는 weather_kma로 되돌린다(weather-args.ts, 2026-10-14).
|
||||
// call.function을 직접 고쳐 이후 기록·실행·메시지 이력이 모두 kma 호출로 일관되게 한다.
|
||||
{
|
||||
const _r = redirectOpenMeteoToKmaForKorea(
|
||||
const _r = await redirectOpenMeteoToKmaForKorea(
|
||||
String(call.function?.name || ''),
|
||||
normalizeToolArgs(call.function?.arguments),
|
||||
new Set((tools || []).map((t: any) => String(t?.function?.name || ''))),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { lookupKoreanPlace } from '../../tools/weather.js';
|
||||
import { lookupKoreanPlace, geocodeCity, KR_CITY_COORDS } from '../../tools/weather.js';
|
||||
|
||||
/**
|
||||
* weather_kma(및 weather) 호출의 type 보정 — 코드 백스톱(2026-10-10).
|
||||
@@ -39,12 +39,12 @@ export function correctWeatherTypeForFuture(toolName: string, args: any, current
|
||||
*/
|
||||
const OPENMETEO_ONLY_RE = /자외선|\buv\b|시간별|시간대별|hourly/i;
|
||||
|
||||
export function redirectOpenMeteoToKmaForKorea(
|
||||
export async function redirectOpenMeteoToKmaForKorea(
|
||||
toolName: string,
|
||||
args: any,
|
||||
availableToolNames: ReadonlySet<string> | readonly string[],
|
||||
currentMessage: string,
|
||||
): { toolName: string; args: any } {
|
||||
): Promise<{ toolName: string; args: any }> {
|
||||
const same = { toolName, args };
|
||||
if (toolName !== 'weather_openmeteo') return same;
|
||||
if (!args || typeof args !== 'object') return same;
|
||||
@@ -57,7 +57,11 @@ export function redirectOpenMeteoToKmaForKorea(
|
||||
if (/^-?\d+(\.\d+)?\s*[,\s]\s*-?\d+(\.\d+)?$/.test(location)) return same;
|
||||
if (args.variables) return same;
|
||||
if (OPENMETEO_ONLY_RE.test(String(currentMessage || ''))) return same;
|
||||
if (!lookupKoreanPlace(location)) return same;
|
||||
// 지점표에 없는 지명(현풍·읍면 단위 등)은 지오코더로 나라를 확인한다. 한국이 아니면 그대로 둔다.
|
||||
if (!lookupKoreanPlace(location) && !KR_CITY_COORDS[location.toLowerCase()]) {
|
||||
const geo = await geocodeCity(location).catch(() => null);
|
||||
if (!geo || !/대한민국|South Korea/i.test(geo.displayName)) return same;
|
||||
}
|
||||
console.log(`[v2] weather_openmeteo: 국내 지명(${location}) → weather_kma(forecast)로 교정`);
|
||||
return { toolName: 'weather_kma', args: { location, type: 'forecast' } };
|
||||
}
|
||||
@@ -176,6 +176,12 @@ const windDirectionKo = (deg: number) =>
|
||||
// Geocode city name → lat/lon using Open-Meteo geocoding (no API key required)
|
||||
// Falls back to a built-in lookup table for common Korean cities.
|
||||
export const KR_CITY_COORDS: Record<string, [number, number]> = {
|
||||
// 2026-10-14: Open-Meteo 지오코더가 "현풍"을 경주의 무명 지명(36.03, 129.24)으로 풀어 대구 달성군
|
||||
// 현풍읍 대신 70km 떨어진 곳 예보가 나갔다. 사용자가 실제로 쓰는 달성군 읍 단위를 직접 넣는다.
|
||||
'현풍': [35.6955, 128.4477], '현풍읍': [35.6955, 128.4477],
|
||||
'화원': [35.8026, 128.5008], '화원읍': [35.8026, 128.5008],
|
||||
'다사': [35.8542, 128.4533], '다사읍': [35.8542, 128.4533],
|
||||
'논공': [35.7467, 128.4325], '논공읍': [35.7467, 128.4325],
|
||||
'서울': [37.5665, 126.9780], 'seoul': [37.5665, 126.9780],
|
||||
'부산': [35.1796, 129.0756], 'busan': [35.1796, 129.0756],
|
||||
'인천': [37.4563, 126.7052], 'incheon': [37.4563, 126.7052],
|
||||
|
||||
@@ -8,30 +8,35 @@ import { redirectOpenMeteoToKmaForKorea as r } from '../src/gateway/chat/weather
|
||||
const both = new Set(['weather_kma', 'weather_openmeteo']);
|
||||
|
||||
describe('redirectOpenMeteoToKmaForKorea', () => {
|
||||
test('국내 지명은 kma forecast로 바뀐다', () => {
|
||||
const out = r('weather_openmeteo', { hours: 168, location: '구미' }, both, '다음주 구미 날씨');
|
||||
test('국내 지명은 kma forecast로 바뀐다', async () => {
|
||||
const out = await r('weather_openmeteo', { hours: 168, location: '구미' }, both, '다음주 구미 날씨');
|
||||
assert.equal(out.toolName, 'weather_kma');
|
||||
assert.deepEqual(out.args, { location: '구미', type: 'forecast' });
|
||||
});
|
||||
test('해외 도시는 그대로', () => {
|
||||
const out = r('weather_openmeteo', { location: 'Tokyo' }, both, '도쿄 날씨');
|
||||
test('현풍 같은 읍 단위 지명도 kma로 바뀐다', async () => {
|
||||
const out = await r('weather_openmeteo', { location: '현풍' }, both, '이번주 현풍 날씨');
|
||||
assert.equal(out.toolName, 'weather_kma');
|
||||
assert.deepEqual(out.args, { location: '현풍', type: 'forecast' });
|
||||
});
|
||||
test('해외 도시는 그대로', async () => {
|
||||
const out = await r('weather_openmeteo', { location: 'Tokyo' }, both, '도쿄 날씨');
|
||||
assert.equal(out.toolName, 'weather_openmeteo');
|
||||
});
|
||||
test('자외선·시간별 요구는 그대로', () => {
|
||||
assert.equal(r('weather_openmeteo', { location: '구미' }, both, '구미 자외선 지수').toolName, 'weather_openmeteo');
|
||||
assert.equal(r('weather_openmeteo', { location: '구미' }, both, '구미 시간별 날씨').toolName, 'weather_openmeteo');
|
||||
test('자외선·시간별 요구는 그대로', async () => {
|
||||
assert.equal((await r('weather_openmeteo', { location: '구미' }, both, '구미 자외선 지수')).toolName, 'weather_openmeteo');
|
||||
assert.equal((await r('weather_openmeteo', { location: '구미' }, both, '구미 시간별 날씨')).toolName, 'weather_openmeteo');
|
||||
});
|
||||
test('variables를 직접 지정하면 그대로', () => {
|
||||
assert.equal(r('weather_openmeteo', { location: '구미', variables: 'uv_index' }, both, '구미 날씨').toolName, 'weather_openmeteo');
|
||||
test('variables를 직접 지정하면 그대로', async () => {
|
||||
assert.equal((await r('weather_openmeteo', { location: '구미', variables: 'uv_index' }, both, '구미 날씨')).toolName, 'weather_openmeteo');
|
||||
});
|
||||
test('kma가 이번 턴에 없으면 그대로', () => {
|
||||
assert.equal(r('weather_openmeteo', { location: '구미' }, new Set(['weather_openmeteo']), '구미 날씨').toolName, 'weather_openmeteo');
|
||||
test('kma가 이번 턴에 없으면 그대로', async () => {
|
||||
assert.equal((await r('weather_openmeteo', { location: '구미' }, new Set(['weather_openmeteo']), '구미 날씨')).toolName, 'weather_openmeteo');
|
||||
});
|
||||
test('여러 도시·좌표는 그대로', () => {
|
||||
assert.equal(r('weather_openmeteo', { location: '구미, 대구' }, both, '날씨').toolName, 'weather_openmeteo');
|
||||
assert.equal(r('weather_openmeteo', { location: '36.1,128.3' }, both, '날씨').toolName, 'weather_openmeteo');
|
||||
test('여러 도시·좌표는 그대로', async () => {
|
||||
assert.equal((await r('weather_openmeteo', { location: '구미, 대구' }, both, '날씨')).toolName, 'weather_openmeteo');
|
||||
assert.equal((await r('weather_openmeteo', { location: '36.1,128.3' }, both, '날씨')).toolName, 'weather_openmeteo');
|
||||
});
|
||||
test('다른 도구는 건드리지 않는다', () => {
|
||||
assert.equal(r('weather_kma', { location: '구미' }, both, '날씨').toolName, 'weather_kma');
|
||||
test('다른 도구는 건드리지 않는다', async () => {
|
||||
assert.equal((await r('weather_kma', { location: '구미' }, both, '날씨')).toolName, 'weather_kma');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user