Files
2026-09-09 17:36:25 +08:00

63 lines
1.7 KiB
JavaScript

import { tool } from "langchain"
import lunarLib from "lunar-javascript"
const { Solar } = lunarLib
/**
* 特定日期日历工具
* 基于 lunar-javascript 提供指定日期的完整农历信息
*/
export const getLunarCalendarInfoTool = tool(
async ({ year, month, day }) => {
try {
const solar = Solar.fromYmd(year, month, day)
const lunar = solar.getLunar()
const result = {
solar: solar.toString(),
weekday: `星期${solar.getWeekInChinese()}`,
lunar: lunar.toString(),
ganzhiYear: lunar.getYearInGanZhi(),
zodiac: lunar.getYearShengXiao(),
solarTerms: lunar.getJieQi() || null,
festivals: [...solar.getFestivals(), ...lunar.getFestivals()],
yi: lunar.getDayYi(),
ji: lunar.getDayJi(),
xiShen: lunar.getDayPositionXiDesc(),
caiShen: lunar.getDayPositionCaiDesc()
}
return JSON.stringify(result, null, 2)
} catch (error) {
return JSON.stringify({ error: error.message }, null, 2)
}
},
{
name: "get_lunar_calendar_info",
description: "获取指定日期的日历信息,包括农历信息、老黄历、当年生肖、今日宜忌、喜神方位、财神方位、今日节气、今日节日等",
schema: {
type: "object",
properties: {
year: {
type: "number",
description: "年份",
minimum: 1900,
maximum: 2100
},
month: {
type: "number",
description: "月份",
minimum: 1,
maximum: 12
},
day: {
type: "number",
description: "日期",
minimum: 1,
maximum: 31
}
},
required: ["year", "month", "day"]
}
}
)