import { tool } from '@strands-agents/sdk' import { z } from 'zod' export const getLocationTool = tool({ name: 'get_location', description: 'Get current device geolocation (lat/lng). Requires user permission.', inputSchema: z.object({ highAccuracy: z.boolean().optional(), timeout: z.number().optional().describe('ms, default 10000'), }), callback: async (input) => { try { if (!navigator.geolocation) return JSON.stringify({ status: 'error', error: 'Geolocation unsupported' }) return await new Promise((resolve) => { navigator.geolocation.getCurrentPosition( (pos) => resolve(JSON.stringify({ status: 'success', latitude: pos.coords.latitude, longitude: pos.coords.longitude, accuracy: pos.coords.accuracy, altitude: pos.coords.altitude, speed: pos.coords.speed, timestamp: pos.timestamp, })), (err: GeolocationPositionError) => resolve(JSON.stringify({ status: 'error', error: err.message, code: err.code })), { enableHighAccuracy: input.highAccuracy, timeout: input.timeout || 10000 } ) }) } catch (err: unknown) { return JSON.stringify({ status: 'error', error: (err as Error).message }) } }, }) export const GEOLOCATION_TOOLS = [getLocationTool]