Project Files
src / toolsProvider.ts
// src/toolsProvider.ts
import { type Tool, type ToolsProviderController } from "@lmstudio/sdk";
import { createAnalyseImageTool } from "./tools/analyse_image.js";
import { createDetectObjectTool } from "./tools/detect_object.js";
import { globalConfigSchematics } from "./config.js";
export async function toolsProvider(ctl: ToolsProviderController) {
try {
const getter: any =
(ctl as any).getGlobalPluginConfig || (ctl as any).getGlobalConfig;
const gcfg = getter ? getter.call(ctl, globalConfigSchematics) : null;
if (gcfg) {
const endpoint = gcfg.get("mlxVisionEndpoint");
if (typeof endpoint === "string" && endpoint.trim()) {
process.env.MLX_VISION_ENDPOINT = endpoint.trim();
}
const detectEndpoint = gcfg.get("detectEndpoint");
if (typeof detectEndpoint === "string" && detectEndpoint.trim()) {
process.env.DETECT_ENDPOINT = detectEndpoint.trim();
}
const prompt = gcfg.get("mlxVisionPrompt");
if (typeof prompt === "string") {
process.env.MLX_VISION_PROMPT = prompt;
}
const inclMeta = gcfg.get("includeGenerationMetadata");
if (typeof inclMeta === "boolean") {
process.env.INCLUDE_GENERATION_METADATA = inclMeta ? "true" : "false";
}
const previewInChat = gcfg.get("PREVIEW_IN_CHAT");
if (typeof previewInChat === "boolean") {
process.env.PREVIEW_IN_CHAT = previewInChat ? "true" : "false";
}
const httpPort = gcfg.get("HTTP_SERVER_PORT");
if (typeof httpPort === "number" && Number.isFinite(httpPort) && httpPort > 0) {
process.env.HTTP_SERVER_PORT = String(Math.floor(httpPort));
}
const mlxModelPath = gcfg.get("mlxVisionModelPath");
if (typeof mlxModelPath === "string") {
process.env.MLX_VISION_MODEL_PATH = mlxModelPath;
}
const mlxPort = gcfg.get("mlxVisionPort");
if (typeof mlxPort === "number" && Number.isFinite(mlxPort) && mlxPort > 0) {
process.env.MLX_VISION_PORT = String(Math.floor(mlxPort));
}
const mlxMaxTokens = gcfg.get("mlxVisionMaxTokens");
if (typeof mlxMaxTokens === "number" && Number.isFinite(mlxMaxTokens) && mlxMaxTokens > 0) {
process.env.MLX_VISION_MAX_TOKENS = String(Math.floor(mlxMaxTokens));
}
const mlxTemp = gcfg.get("mlxVisionTemperature");
if (typeof mlxTemp === "number" && Number.isFinite(mlxTemp)) {
process.env.MLX_VISION_TEMPERATURE = String(mlxTemp);
}
const mlxEnabled = gcfg.get("mlxVisionEnabled");
if (typeof mlxEnabled === "boolean") {
process.env.MLX_VISION_ENABLED = mlxEnabled ? "true" : "false";
}
const mlxBackend = gcfg.get("mlxVisionBackend");
if (typeof mlxBackend === "boolean") {
process.env.FASTVLM_BACKEND = mlxBackend ? "ane" : "mlx";
}
const detectModelPath = gcfg.get("detectModelPath");
if (typeof detectModelPath === "string") {
process.env.DETECT_MODEL_PATH = detectModelPath;
process.env.FLORENCE2_MODEL_PATH = detectModelPath;
}
const detectEnabled = gcfg.get("detectEnabled");
if (typeof detectEnabled === "boolean") {
process.env.DETECT_ENABLED = detectEnabled ? "true" : "false";
}
const detectBackend = gcfg.get("detectBackend");
if (typeof detectBackend === "boolean") {
process.env.FASTVLM_DETECT_BACKEND = detectBackend ? "qwen3-vl" : "florence2";
}
const qwen3VlModelPath = gcfg.get("qwen3VlModelPath");
if (typeof qwen3VlModelPath === "string") {
process.env.FASTVLM_QWEN3_VL_MODEL_PATH = qwen3VlModelPath;
}
const qwen3VlOdPrompt = gcfg.get("qwen3VlOdPrompt");
if (typeof qwen3VlOdPrompt === "string") {
process.env.DETECT_OD_PROMPT = qwen3VlOdPrompt;
}
const serverTTL = gcfg.get("serverTTL");
if (typeof serverTTL === "number" && Number.isFinite(serverTTL) && serverTTL >= 0) {
process.env.SERVER_TTL = String(Math.floor(serverTTL));
}
}
} catch {}
const tools: Tool[] = [];
tools.push(createAnalyseImageTool(ctl));
tools.push(createDetectObjectTool(ctl));
return tools;
}