weather_openmeteo: 국내 위치는 거부하고 weather_kma로 안내(예외: days>10·hours>240 장기 구간) — 국내 예보는 기상청 단기+중기로 일원화
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
61cfd7ce46
commit
e870c3c7ec
4 files changed
+34
-3
No files matched your search
@@ -919,7 +919,7 @@ export function createBuildTools(isOrchestrationSkillEnabled: () => boolean) {
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'weather_openmeteo',
|
||||
description: 'Forecast tool for locations OUTSIDE Korea. For ANY Korean location ALWAYS call weather_kma FIRST — no exceptions (KMA is the authority domestically); use this tool for a Korean location only in addition to weather_kma, and only for UV index or long hourly detail. This includes "이번 주"/weekend/week-ahead questions: weather_kma now returns days 1-3 from KMA plus days 4-10 from the official KMA mid-range forecast (2026-10-14). Open-Meteo (free, no key): precipitation probability, hourly breakdown, UV index, ECMWF/GFS models, up to 16 days. For a Korean location call weather_kma first (any range up to 10 days) — it is observation-backed and its numbers differ materially (verified 2026-07-29: 20% vs 0% rain, highs 1.5-2.5°C apart for the same day). Never use web_search for weather.',
|
||||
description: 'Forecast tool for locations OUTSIDE Korea. For ANY Korean location use weather_kma — this tool REFUSES Korean locations (error) unless days>10 / hours>240 is requested for a long-range outlook beyond the KMA 10-day forecast. This includes "이번 주"/weekend/week-ahead questions: weather_kma now returns days 1-3 from KMA plus days 4-10 from the official KMA mid-range forecast (2026-10-14). Open-Meteo (free, no key): precipitation probability, hourly breakdown, UV index, ECMWF/GFS models, up to 16 days. For a Korean location call weather_kma first (any range up to 10 days) — it is observation-backed and its numbers differ materially (verified 2026-07-29: 20% vs 0% rain, highs 1.5-2.5°C apart for the same day). Never use web_search for weather.',
|
||||
parameters: {
|
||||
type: 'object', required: ['location'],
|
||||
properties: {
|
||||
|
||||
@@ -912,6 +912,17 @@ async function withKmaMidTerm(text: string, lat: number, lon: number, days: numb
|
||||
}
|
||||
}
|
||||
|
||||
// 국내 위치는 weather_kma가 맡는다(관측망이 촘촘하고 4~10일 중기예보까지 같이 준다). Open-Meteo는 해외용이다.
|
||||
// 예외는 10일을 넘는 구간(days>10 또는 hours>240) — 기상청 예보가 닿지 않는 장기 구간뿐이다.
|
||||
// 2026-10-19 사용자 결정: "weather_openmeteo는 국내 검색에서 제외, 장기예보 외에는".
|
||||
const KOREA_BBOX = { latMin: 33.0, latMax: 38.7, lonMin: 124.5, lonMax: 131.9 };
|
||||
export function isKoreanLatLon(lat: number, lon: number): boolean {
|
||||
return lat >= KOREA_BBOX.latMin && lat <= KOREA_BBOX.latMax && lon >= KOREA_BBOX.lonMin && lon <= KOREA_BBOX.lonMax;
|
||||
}
|
||||
export function openMeteoKoreaBlockMessage(place: string): string {
|
||||
return `${place}은(는) 국내 지역입니다. 국내 날씨·예보(3일 단기 + 4~10일 중기)는 weather_kma로 조회하세요 — 이 도구(weather_openmeteo)는 해외 지역과 10일을 넘는 장기 예보(days>10)에만 씁니다.`;
|
||||
}
|
||||
|
||||
export const weatherOpenMeteoTool = {
|
||||
name: 'weather_openmeteo',
|
||||
description: 'Get weather forecast using Open-Meteo API (free, no API key). Powered by ECMWF, GFS, and other NWP models. Times are returned in the LOCATION\'s local timezone. For "today\'s high/low" use daily variables (temperature_2m_max, temperature_2m_min, precipitation_sum, …) — the hourly series is a rolling window from now and spans two calendar days, so its maximum is NOT the daily high. Hourly variables (temperature_2m, precipitation, wind_speed_10m, uv_index, weather_code, …) are for intra-day detail. Up to 16 days.',
|
||||
@@ -991,15 +1002,18 @@ export const weatherOpenMeteoTool = {
|
||||
};
|
||||
|
||||
try {
|
||||
const longRange = days > 10 || hours > 240;
|
||||
const coords = parseCoords(location);
|
||||
if (coords) {
|
||||
const [lat, lon] = coords;
|
||||
if (!longRange && isKoreanLatLon(lat, lon)) return { success: false, error: openMeteoKoreaBlockMessage(location) };
|
||||
const { text, raw } = await fetchOneCity(lat, lon, location);
|
||||
return { success: true, stdout: await withKmaMidTerm(text, lat, lon, days, hours), data: { location, lat, lon, raw } };
|
||||
}
|
||||
|
||||
const geo = await geocodeCity(location);
|
||||
if (geo) {
|
||||
if (!longRange && isKoreanLatLon(geo.lat, geo.lon)) return { success: false, error: openMeteoKoreaBlockMessage(geo.displayName || location) };
|
||||
const { text, raw } = await fetchOneCity(geo.lat, geo.lon, geo.displayName);
|
||||
return { success: true, stdout: await withKmaMidTerm(text, geo.lat, geo.lon, days, hours), data: { location: geo.displayName, lat: geo.lat, lon: geo.lon, raw } };
|
||||
}
|
||||
@@ -1016,6 +1030,7 @@ export const weatherOpenMeteoTool = {
|
||||
const settled = await Promise.allSettled(cities.map(async (c) => {
|
||||
const g = await geocodeCity(c);
|
||||
if (!g) throw new Error(`${c}: 위치를 찾을 수 없음`);
|
||||
if (!longRange && isKoreanLatLon(g.lat, g.lon)) throw new Error(`${c}: 국내 지역은 weather_kma로 조회`);
|
||||
const { text } = await fetchOneCity(g.lat, g.lon, g.displayName);
|
||||
return { city: c, text };
|
||||
}));
|
||||
|
||||
@@ -80,7 +80,7 @@ describe('배치 입력은 도구가 직접 전부 조회해 하나로 합친다
|
||||
describe('단일 위치는 목록으로 오해하지 않는다', () => {
|
||||
test('"City, Country"는 정상 조회된다', async (t) => {
|
||||
if (!online) return t.skip('offline');
|
||||
assert.equal((await ask('Seoul, Korea')).success, true);
|
||||
assert.equal((await ask('Paris, France')).success, true);
|
||||
});
|
||||
|
||||
test('"City,CountryCode"는 정상 조회된다', async (t) => {
|
||||
@@ -90,7 +90,7 @@ describe('단일 위치는 목록으로 오해하지 않는다', () => {
|
||||
|
||||
test('쉼표가 있는 좌표는 정상 조회된다', async (t) => {
|
||||
if (!online) return t.skip('offline');
|
||||
assert.equal((await ask('37.5,127.0')).success, true);
|
||||
assert.equal((await ask('48.85,2.35')).success, true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { isKoreanLatLon, weatherOpenMeteoTool } from '../src/tools/weather';
|
||||
|
||||
test('국내 좌표 판정', () => {
|
||||
assert.equal(isKoreanLatLon(36.12, 128.34), true); // 구미
|
||||
assert.equal(isKoreanLatLon(33.5, 126.5), true); // 제주
|
||||
assert.equal(isKoreanLatLon(35.68, 139.69), false); // 도쿄
|
||||
assert.equal(isKoreanLatLon(40.71, -74.0), false); // 뉴욕
|
||||
});
|
||||
|
||||
test('국내 좌표는 장기(days>10)가 아니면 거부, 도구 설명에 weather_kma 안내', async () => {
|
||||
const r = await weatherOpenMeteoTool.execute({ location: '36.12,128.34', days: 3 });
|
||||
assert.equal(r.success, false);
|
||||
assert.match(String(r.error), /weather_kma/);
|
||||
});
|
||||
Reference in new issue
Block a user