src / toolsProvider.ts
import { tool, Tool, ToolsProviderController } from "@lmstudio/sdk";
const TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
export async function toolsProvider(_ctl: ToolsProviderController) {
const tools: Tool[] = [];
const datetimeTool = tool({
name: "get_current_datetime",
description:
"Returns the current local date, time, day of the week, and timezone. " +
"Call this whenever the user asks about the current date, time, day, " +
"or anything time-sensitive.",
parameters: {},
implementation: async () => {
const now = new Date();
const opts: Intl.DateTimeFormatOptions = { timeZone: TIMEZONE };
const date = now.toLocaleDateString("en-US", {
...opts,
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
});
const time = now.toLocaleTimeString("en-US", {
...opts,
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
timeZoneName: "short",
});
return `${date} at ${time}`;
},
});
tools.push(datetimeTool);
return tools;
}