src / tools / provider.ts
src / tools / provider.ts
import { tool, type Tool, type ToolsProvider } from "@lmstudio/sdk";
import { errorResult } from "../core/result";
import { createRuntime, type PluginRuntime } from "../runtime";
import { createAgentTool } from "./agentTool";
import { createBrowserTool } from "./browserTool";
import { createCommandTool } from "./commandTool";
import { createEditTool } from "./editTool";
import { createNotesTool } from "./notesTool";
import { createPlanTool } from "./planTool";
import { createResearchTool } from "./researchTool";
import { createTaskTool } from "./taskTool";
import { createVcsTool } from "./vcsTool";
import { createWorkspaceTool } from "./workspaceTool";
/** Builds the public tool list for an initialized runtime (testable without an SDK controller). */
export function buildTools(runtime: PluginRuntime): Tool[] {
const tools: Tool[] = [createWorkspaceTool(runtime), createEditTool(runtime)];
if (runtime.settings.permissionMode !== "auto") {
tools.push(createPlanTool(runtime));
}
// Notes are plugin-owned scratch state, never workspace edits: always available, never gated.
tools.push(createNotesTool(runtime));
if (runtime.settings.taskBoardsEnabled) {
tools.push(createTaskTool(runtime));
}
if (runtime.settings.webResearchEnabled) {
tools.push(createResearchTool(runtime));
}
if (runtime.settings.processExecutionEnabled) {
tools.push(createCommandTool(runtime));
}
if (runtime.settings.processExecutionEnabled && runtime.settings.vcsToolsEnabled) {
tools.push(createVcsTool(runtime));
}
if (runtime.settings.browserEnabled) {
tools.push(createBrowserTool(runtime));
}
if (runtime.settings.internalAgentsEnabled) {
tools.push(createAgentTool(runtime));
}
return tools;
}
export const toolsProvider: ToolsProvider = async (ctl) => {
try {
return buildTools(await createRuntime(ctl));
} catch (error) {
try {
(ctl as { createStatus?: (status: { status: string; text: string }) => void }).createStatus?.({
status: "error",
text: error instanceof Error ? error.message : String(error),
});
} catch {
// Status UI is optional; the diagnostic tool below remains available.
}
return [
tool({
name: "agentic_workspace_status",
description: "Report why Agentic Workspace could not initialize.",
parameters: {},
implementation: async () => errorResult("workspace.initialize", error, "critical"),
}),
];
}
};
import { tool, type Tool, type ToolsProvider } from "@lmstudio/sdk";
import { errorResult } from "../core/result";
import { createRuntime, type PluginRuntime } from "../runtime";
import { createAgentTool } from "./agentTool";
import { createBrowserTool } from "./browserTool";
import { createCommandTool } from "./commandTool";
import { createEditTool } from "./editTool";
import { createNotesTool } from "./notesTool";
import { createPlanTool } from "./planTool";
import { createResearchTool } from "./researchTool";
import { createTaskTool } from "./taskTool";
import { createVcsTool } from "./vcsTool";
import { createWorkspaceTool } from "./workspaceTool";
/** Builds the public tool list for an initialized runtime (testable without an SDK controller). */
export function buildTools(runtime: PluginRuntime): Tool[] {
const tools: Tool[] = [createWorkspaceTool(runtime), createEditTool(runtime)];
if (runtime.settings.permissionMode !== "auto") {
tools.push(createPlanTool(runtime));
}
// Notes are plugin-owned scratch state, never workspace edits: always available, never gated.
tools.push(createNotesTool(runtime));
if (runtime.settings.taskBoardsEnabled) {
tools.push(createTaskTool(runtime));
}
if (runtime.settings.webResearchEnabled) {
tools.push(createResearchTool(runtime));
}
if (runtime.settings.processExecutionEnabled) {
tools.push(createCommandTool(runtime));
}
if (runtime.settings.processExecutionEnabled && runtime.settings.vcsToolsEnabled) {
tools.push(createVcsTool(runtime));
}
if (runtime.settings.browserEnabled) {
tools.push(createBrowserTool(runtime));
}
if (runtime.settings.internalAgentsEnabled) {
tools.push(createAgentTool(runtime));
}
return tools;
}
export const toolsProvider: ToolsProvider = async (ctl) => {
try {
return buildTools(await createRuntime(ctl));
} catch (error) {
try {
(ctl as { createStatus?: (status: { status: string; text: string }) => void }).createStatus?.({
status: "error",
text: error instanceof Error ? error.message : String(error),
});
} catch {
// Status UI is optional; the diagnostic tool below remains available.
}
return [
tool({
name: "agentic_workspace_status",
description: "Report why Agentic Workspace could not initialize.",
parameters: {},
implementation: async () => errorResult("workspace.initialize", error, "critical"),
}),
];
}
};