{"version":3,"file":"time.cjs","names":[],"sources":["../../../src/batteries/tools/time/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for current time lookup and timezone-aware time formatting.\n *\n * @module @nhtio/adk/batteries/tools/time\n *\n * @remarks\n * Pre-constructed bundled tools for the `time` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { DateTime, IANAZone } from 'luxon'\nimport { validator } from '@nhtio/validation'\n\n/**\n * Return the current time formatted in a given timezone.\n *\n * @remarks\n * `timezone` defaults to `UTC` when omitted. The ADK has no notion of a \"user local\"\n * timezone, so callers should pass an IANA zone (`America/New_York`, `Europe/London`, ...) for\n * non-UTC formatting.\n */\nexport const getCurrentTimeTool = new Tool({\n  name: 'get_current_time',\n  description: 'Get current time in an IANA timezone (defaults to UTC).',\n  inputSchema: validator.object({\n    timezone: validator\n      .string()\n      .default('UTC')\n      .allow('')\n      .description('IANA timezone. Omit or send an empty string to use UTC.'),\n  }),\n  handler: async (args) => {\n    const { timezone: rawTimezone } = args as { timezone: string }\n    const timezone = rawTimezone || 'UTC'\n    if (!IANAZone.isValidZone(timezone)) {\n      return `Error: Invalid timezone \"${timezone}\".`\n    }\n    const now = DateTime.now().setZone(timezone)\n    return `${timezone}: ${now.toFormat('cccc, LLLL d, yyyy h:mm:ss a ZZZZ')}`\n  },\n})\n\n/**\n * Convert a wall-clock time between two IANA timezones.\n *\n * @remarks\n * `time` must be `HH:MM` in 24-hour format. `target_timezone` defaults to UTC. The conversion\n * uses today's date in the source zone to pick the correct DST offset.\n */\nexport const convertTimeTool = new Tool({\n  name: 'convert_time',\n  description: 'Convert time between timezones.',\n  inputSchema: validator.object({\n    source_timezone: validator.string().required().description('Source IANA timezone'),\n    time: validator.string().required().description('HH:MM (24h)'),\n    target_timezone: validator\n      .string()\n      .default('UTC')\n      .allow('')\n      .description('Target IANA timezone. Omit or send an empty string to use UTC.'),\n  }),\n  handler: async (args) => {\n    const {\n      source_timezone: sourceTimezone,\n      time,\n      target_timezone: rawTargetTimezone,\n    } = args as {\n      source_timezone: string\n      time: string\n      target_timezone: string\n    }\n    const targetTimezone = rawTargetTimezone || 'UTC'\n\n    if (!IANAZone.isValidZone(sourceTimezone)) {\n      return `Error: Invalid source timezone \"${sourceTimezone}\".`\n    }\n    if (!IANAZone.isValidZone(targetTimezone)) {\n      return `Error: Invalid target timezone \"${targetTimezone}\".`\n    }\n\n    const parsed = DateTime.fromFormat(time, 'HH:mm', { zone: sourceTimezone })\n    if (!parsed.isValid) {\n      return `Error: Invalid time \"${time}\". Use HH:MM.`\n    }\n\n    const converted = parsed.setZone(targetTimezone)\n    return `${time} ${sourceTimezone} = ${converted.toFormat('HH:mm')} ${targetTimezone}`\n  },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,qBAAqB,IAAI,yBAAA,KAAK;CACzC,MAAM;CACN,aAAa;CACb,aAAa,kBAAA,UAAU,OAAO,EAC5B,UAAU,kBAAA,UACP,OAAO,EACP,QAAQ,KAAK,EACb,MAAM,EAAE,EACR,YAAY,yDAAyD,EAC1E,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EAAE,UAAU,gBAAgB;EAClC,MAAM,WAAW,eAAe;EAChC,IAAI,CAAC,MAAA,SAAS,YAAY,QAAQ,GAChC,OAAO,4BAA4B,SAAS;EAG9C,OAAO,GAAG,SAAS,IADP,MAAA,SAAS,IAAI,EAAE,QAAQ,QACZ,EAAI,SAAS,mCAAmC;CACzE;AACF,CAAC;;;;;;;;AASD,IAAa,kBAAkB,IAAI,yBAAA,KAAK;CACtC,MAAM;CACN,aAAa;CACb,aAAa,kBAAA,UAAU,OAAO;EAC5B,iBAAiB,kBAAA,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,sBAAsB;EACjF,MAAM,kBAAA,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,aAAa;EAC7D,iBAAiB,kBAAA,UACd,OAAO,EACP,QAAQ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