src / toolsProvider.ts
import { Tool, tool, ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
import { configSchematics } from "./configSchematics";
export async function toolsProvider(ctl: ToolsProviderController) {
const config = ctl.getPluginConfig(configSchematics);
const tools: Tool[] = [];
if (config.get("enableAdditionTool")) {
tools.push(
tool({
name: "add",
description: "Given two numbers a and b. Returns the sum of them.",
parameters: { a: z.number(), b: z.number() },
implementation: ({ a, b }) => a + b,
}),
);
}
tools.push(
tool({
name: "isPrime",
description: "Given a number n. Returns true if n is a prime number.",
parameters: { n: z.number() },
implementation: async ({ n }, ctx) => {
if (n < 2) return false;
const sqrt = Math.sqrt(n);
for (let i = 2; i <= sqrt; i++) {
if (n % i === 0) return false;
}
return true;
},
}),
);
return tools;
}