src / toolsProvider.ts
import { text, tool, type Tool, type ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
import { configSchematics } from "./config";
import { runCommand } from "./exec";
import { jevAssessor, resolveApiKey } from "./judge";
import { shellRun } from "./shellRun";
import type { Settings } from "./types";
function readSettings(ctl: ToolsProviderController): Settings {
const config = ctl.getPluginConfig(configSchematics);
return {
blockThreshold: config.get("blockThreshold"),
reviewThreshold: config.get("reviewThreshold"),
severityBlock: config.get("severityBlock"),
defaultTimeoutSec: config.get("defaultTimeoutSec"),
maxTimeoutSec: config.get("maxTimeoutSec"),
maxOutputChars: config.get("maxOutputChars"),
};
}
export async function toolsProvider(ctl: ToolsProviderController) {
const assess = jevAssessor(() => resolveApiKey(ctl.getPluginConfig(configSchematics).get("jevApiKey")));
const shellRunTool = tool({
name: "shell_run",
description: text`
Run a shell command and return its combined stdout and stderr. Pipes, redirects and && work.
Every command is safety-checked before it runs. Commands that could delete data, change the
system, send data off the machine or escalate privileges are refused with a "Blocked:" message;
do not retry those, tell the user instead.
Runs in the working directory unless 'cwd' is given. Default timeout is 30 seconds; pass
'timeout' (seconds) to allow longer.
`,
parameters: {
command: z.string(),
cwd: z.string().optional(),
timeout: z.number().int().min(1).optional(),
},
implementation: ({ command, cwd, timeout }, { status, signal }) =>
shellRun(
{ command, cwd, timeoutSec: timeout },
{
defaultCwd: ctl.getWorkingDirectory(),
settings: readSettings(ctl),
assess,
run: runCommand,
status,
signal,
},
),
});
const tools: Tool[] = [shellRunTool];
return tools;
}
src / toolsProvider.ts
import { text, tool, type Tool, type ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
import { configSchematics } from "./config";
import { runCommand } from "./exec";
import { jevAssessor, resolveApiKey } from "./judge";
import { shellRun } from "./shellRun";
import type { Settings } from "./types";
function readSettings(ctl: ToolsProviderController): Settings {
const config = ctl.getPluginConfig(configSchematics);
return {
blockThreshold: config.get("blockThreshold"),
reviewThreshold: config.get("reviewThreshold"),
severityBlock: config.get("severityBlock"),
defaultTimeoutSec: config.get("defaultTimeoutSec"),
maxTimeoutSec: config.get("maxTimeoutSec"),
maxOutputChars: config.get("maxOutputChars"),
};
}
export async function toolsProvider(ctl: ToolsProviderController) {
const assess = jevAssessor(() => resolveApiKey(ctl.getPluginConfig(configSchematics).get("jevApiKey")));
const shellRunTool = tool({
name: "shell_run",
description: text`
Run a shell command and return its combined stdout and stderr. Pipes, redirects and && work.
Every command is safety-checked before it runs. Commands that could delete data, change the
system, send data off the machine or escalate privileges are refused with a "Blocked:" message;
do not retry those, tell the user instead.
Runs in the working directory unless 'cwd' is given. Default timeout is 30 seconds; pass
'timeout' (seconds) to allow longer.
`,
parameters: {
command: z.string(),
cwd: z.string().optional(),
timeout: z.number().int().min(1).optional(),
},
implementation: ({ command, cwd, timeout }, { status, signal }) =>
shellRun(
{ command, cwd, timeoutSec: timeout },
{
defaultCwd: ctl.getWorkingDirectory(),
settings: readSettings(ctl),
assess,
run: runCommand,
status,
signal,
},
),
});
const tools: Tool[] = [shellRunTool];
return tools;
}