2025-09-21 12:03:29 +01:00
|
|
|
import { tool } from 'ai';
|
|
|
|
|
import { z } from 'zod';
|
2025-01-23 01:19:48 +05:30
|
|
|
|
|
|
|
|
export const getWeather = tool({
|
2025-09-21 12:03:29 +01:00
|
|
|
description: 'Get the current weather at a location',
|
2025-07-03 02:26:34 -07:00
|
|
|
inputSchema: z.object({
|
2025-01-23 01:19:48 +05:30
|
|
|
latitude: z.number(),
|
|
|
|
|
longitude: z.number(),
|
|
|
|
|
}),
|
|
|
|
|
execute: async ({ latitude, longitude }) => {
|
|
|
|
|
const response = await fetch(
|
2025-09-21 12:03:29 +01:00
|
|
|
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m&hourly=temperature_2m&daily=sunrise,sunset&timezone=auto`,
|
2025-01-23 01:19:48 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const weatherData = await response.json();
|
|
|
|
|
return weatherData;
|
|
|
|
|
},
|
|
|
|
|
});
|