src / toolsProvider.ts
import { text, tool, type ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
import { configSchematics } from "./configSchematics";
import { describeTime, isValidTimezone, type DateFormat } from "./timeHelpers";
const formatEnum = z.enum(["iso", "human", "unix"]);
export async function toolsProvider(ctl: ToolsProviderController) {
const config = ctl.getPluginConfig(configSchematics);
const getCurrentTime = tool({
name: "get_current_time",
description: text`
Returns the current date and time in the user's configured timezone (or system timezone if
none is set). Use this whenever the user asks what time or date it is, or needs the current
timestamp without specifying a location.
`,
parameters: {},
implementation: async () => {
const tz = config.get("defaultTimezone");
const loc = config.get("defaultLocale");
const fmt = config.get("dateFormat") as DateFormat;
return describeTime(new Date(), tz, loc, fmt);
},
});
const getDateIn = tool({
name: "get_date_in",
description: text`
Returns the current date and time in a specific timezone. Use this when the user asks about
the time in a place other than their own (e.g. "what time is it in Tokyo", "what's the date
in New York right now"). The \`timezone\` argument MUST be an IANA timezone name like
"Asia/Tokyo", "America/New_York", "Europe/London", or "Australia/Sydney" — never a city
name on its own and never an abbreviation like "EST" or "CET".
`,
parameters: {
timezone: z
.string()
.min(1)
.describe("IANA timezone name, e.g. Asia/Tokyo, America/New_York, Europe/London"),
format: formatEnum
.optional()
.describe("Optional output format override; defaults to the plugin's configured format"),
},
implementation: async ({ timezone, format }) => {
if (!isValidTimezone(timezone)) {
return {
error: `Unknown timezone "${timezone}". Use a valid IANA name like "Asia/Tokyo" or "America/New_York".`,
};
}
const loc = config.get("defaultLocale");
const fmt = (format ?? config.get("dateFormat")) as DateFormat;
return describeTime(new Date(), timezone, loc, fmt);
},
});
return [getCurrentTime, getDateIn];
}