UNPKG

@jackhua/mini-langchain

Version:

A lightweight TypeScript implementation of LangChain with cost optimization features

71 lines 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateTimeTool = void 0; const base_1 = require("./base"); /** * Date and time tool */ class DateTimeTool extends base_1.BaseTool { constructor() { super(...arguments); this.name = 'datetime'; this.description = 'Get current date and time information. Input can be "date", "time", "datetime", or a timezone name.'; } async execute(input) { const query = input.toLowerCase().trim(); const now = new Date(); switch (query) { case 'date': return now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); case 'time': return now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: true }); case 'datetime': case '': return now.toLocaleString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: true }); case 'timestamp': return now.toISOString(); case 'unix': return String(Math.floor(now.getTime() / 1000)); default: // Try to interpret as timezone try { const tzDate = now.toLocaleString('en-US', { timeZone: query, weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: true }); return `Time in ${query}: ${tzDate}`; } catch (error) { return `Current datetime: ${now.toLocaleString()}. Supported inputs: "date", "time", "datetime", "timestamp", "unix", or a timezone name.`; } } } } exports.DateTimeTool = DateTimeTool; //# sourceMappingURL=datetime.js.map