{
	"$schema": "https://ui.shadcn.com/schema/registry-item.json",
	"name": "get-weather",
	"type": "registry:lib",
	"description": "A tool for getting the weather.",
	"dependencies": ["ai", "zod"],
	"files": [
		{
			"path": "./src/registry/ai/tools/get-weather.ts",
			"content": "import { type InferUITool, tool } from \"ai\";\nimport { z } from \"zod\";\n\nconst getWeatherParamsSchema = z.object({\n\tcity: z.string().describe(\"The city to get the weather for\"),\n\tunit: z.enum([\"fahrenheit\", \"celsius\"]).describe(\"The unit of temperature\"),\n});\n\nexport type GetWeatherParams = z.infer<typeof getWeatherParamsSchema>;\n\nconst getWeatherResultSchema = z.union([\n\tz.object({\n\t\tsuccess: z.literal(true),\n\t\tmessage: z.string(),\n\t\ttemperature: z.number(),\n\t\twindSpeed: z.number(),\n\t\tweatherCode: z.number(),\n\t}),\n\tz.object({\n\t\tsuccess: z.literal(false),\n\t\terror: z.string(),\n\t}),\n]);\n\nexport type GetWeatherResult = z.infer<typeof getWeatherResultSchema>;\n\nexport const getWeatherTool = tool({\n\tname: \"get-weather\",\n\tdescription: \"Get the current weather in a location\",\n\tinputSchema: getWeatherParamsSchema,\n\toutputSchema: getWeatherResultSchema,\n\texecute: async (params) => {\n\t\ttry {\n\t\t\tconst geocodeUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(params.city)}&count=1&language=en&format=json`;\n\t\t\tconst geocodeResponse = await fetch(geocodeUrl);\n\t\t\tconst geocodeData = await geocodeResponse.json();\n\n\t\t\tif (!geocodeData.results || geocodeData.results.length === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: `Could not find location: ${params.city}`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { latitude, longitude } = geocodeData.results[0];\n\n\t\t\tconst tempUnit =\n\t\t\t\tparams.unit === \"celsius\" ? \"celsius\" : \"fahrenheit\";\n\t\t\tconst weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m,weathercode,windspeed_10m&temperature_unit=${tempUnit}`;\n\t\t\tconst weatherResponse = await fetch(weatherUrl);\n\t\t\tconst weatherData = await weatherResponse.json();\n\n\t\t\tconst temperature = weatherData.current.temperature_2m;\n\t\t\tconst windSpeed = weatherData.current.windspeed_10m;\n\t\t\tconst weatherCode = weatherData.current.weathercode;\n\n\t\t\tconst weatherDescriptions: Record<number, string> = {\n\t\t\t\t0: \"Clear sky\",\n\t\t\t\t1: \"Mainly clear\",\n\t\t\t\t2: \"Partly cloudy\",\n\t\t\t\t3: \"Overcast\",\n\t\t\t\t45: \"Foggy\",\n\t\t\t\t48: \"Depositing rime fog\",\n\t\t\t\t51: \"Light drizzle\",\n\t\t\t\t53: \"Moderate drizzle\",\n\t\t\t\t55: \"Dense drizzle\",\n\t\t\t\t61: \"Slight rain\",\n\t\t\t\t63: \"Moderate rain\",\n\t\t\t\t65: \"Heavy rain\",\n\t\t\t\t71: \"Slight snow\",\n\t\t\t\t73: \"Moderate snow\",\n\t\t\t\t75: \"Heavy snow\",\n\t\t\t\t77: \"Snow grains\",\n\t\t\t\t80: \"Slight rain showers\",\n\t\t\t\t81: \"Moderate rain showers\",\n\t\t\t\t82: \"Violent rain showers\",\n\t\t\t\t85: \"Slight snow showers\",\n\t\t\t\t86: \"Heavy snow showers\",\n\t\t\t\t95: \"Thunderstorm\",\n\t\t\t\t96: \"Thunderstorm with slight hail\",\n\t\t\t\t99: \"Thunderstorm with heavy hail\",\n\t\t\t};\n\n\t\t\tconst weatherDescription =\n\t\t\t\tweatherDescriptions[weatherCode] || \"Unknown\";\n\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tmessage: `The weather in ${params.city} is ${temperature}°${params.unit === \"celsius\" ? \"C\" : \"F\"} with ${weatherDescription.toLowerCase()}. Wind speed: ${windSpeed} km/h`,\n\t\t\t\ttemperature,\n\t\t\t\twindSpeed,\n\t\t\t\tweatherCode,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: `Failed to fetch weather data: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n\t\t\t};\n\t\t}\n\t},\n});\n\nexport type GetWeatherTool = InferUITool<typeof getWeatherTool>;\n",
			"type": "registry:lib",
			"target": "lib/ai/tools/get-weather.ts"
		}
	]
}
