src / toolsProvider.ts

import { tool, type ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";

export async function toolsProvider(_ctl: ToolsProviderController) {
  const echoNumTool = tool({
    name: "echo_num",
    description: "Echoes back the provided number (or null) with a success message.",
    parameters: {
      num: z.number().nullable().describe("The number to echo back, or null"),
    },
    implementation: async ({ num }) => {
      return `You successfully echoed ${num}`;
    },
  });

  const echoStrTool = tool({
    name: "echo_str",
    description: "Echoes back the provided string with a success message.",
    parameters: {
      str: z.string().describe("The string to echo back"),
    },
    implementation: async ({ str }) => {
      return `You successfully echoed ${str}`;
    },
  });

  const echoBoolTool = tool({
    name: "echo_bool",
    description: "Echoes back the provided boolean with a success message.",
    parameters: {
      bool: z.boolean().describe("The boolean to echo back"),
    },
    implementation: async ({ bool }) => {
      return `You successfully echoed ${bool}`;
    },
  });

  const echoIterTool = tool({
    name: "echo_iter",
    description: "Echoes back the provided list with a success message.",
    parameters: {
      iter: z.array(z.unknown()).describe("The list to echo back"),
    },
    implementation: async ({ iter }) => {
      return `You successfully echoed ${JSON.stringify(iter)}`;
    },
  });

  const echoMapTool = tool({
    name: "echo_map",
    description: "Echoes back the provided mapping with a success message.",
    parameters: {
      map: z.record(z.string(), z.unknown()).describe("The mapping to echo back"),
    },
    implementation: async ({ map }) => {
      return `You successfully echoed ${JSON.stringify(map)}`;
    },
  });

  return [echoNumTool, echoStrTool, echoBoolTool, echoIterTool, echoMapTool];
}