src / tools / openFileTool.ts
import { tool, Tool, ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
import { exec } from "child_process";
import { promisify } from "util";
const execPromise = promisify(exec);
export const getOpenFileTool = (ctl: ToolsProviderController) => {
return tool({
name: "openFile",
description: "Open a file or directory with the default application on macOS.",
parameters: { path: z.string() },
implementation: async ({ path }) => {
try {
await execPromise(`open "${path}"`);
return "File opened successfully.";
} catch (err) {
return `Error opening file: ${err.message}`;
}
},
});
};