fix(tools): gate generate_image behind setting and tool whitelist

generate_image was registered as a custom tool and force-activated via the alwaysInclude list in createAgentSession, so it survived --no-tools (empty toolNames) and any explicit whitelist that omitted it. There was also no generate_image.enabled setting, so /settings had no toggle.

Add a generate_image.enabled setting and only register the tool when enabled and either no whitelist is given or it names generate_image.

Fixes #5305
This commit is contained in:
roboomp
2026-07-14 18:06:10 +00:00
parent 01d3fc9b6b
commit 5878ed8f49
4 changed files with 105 additions and 4 deletions
@@ -3528,6 +3528,16 @@ export const SETTINGS_SCHEMA = {
description: "Enable the tts tool for on-device (Kokoro) or xAI Grok Voice speech-file synthesis",
},
},
"generate_image.enabled": {
type: "boolean",
default: true,
ui: {
tab: "tools",
group: "Available Tools",
label: "Generate Image",
description: "Enable the generate_image tool for text-to-image generation and editing",
},
},
"inspect_image.enabled": {
type: "boolean",
+11 -4
View File
@@ -1812,10 +1812,17 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
// to mirror the AsyncJobManager ownership rule.
if (mcpManager && !options.parentTaskPrefix) MCPManager.setInstance(mcpManager);
// Add image tools when the active model or configured image providers can generate images.
const imageGenTools = await logger.time("getImageGenTools", () => getImageGenTools(modelRegistry, model));
if (imageGenTools.length > 0) {
customTools.push(...(imageGenTools as unknown as CustomTool[]));
// Add image tools when generation is enabled and either no explicit tool
// whitelist was given or it names `generate_image`. Unlike built-in tools
// (filtered in `createTools`), custom tools are force-activated via
// `alwaysInclude` below, so an explicit `--no-tools`/whitelist must be
// honored here or image-gen would leak past every filter (issue #5305).
const imageGenRequested = !options.toolNames || options.toolNames.includes("generate_image");
if (settings.get("generate_image.enabled") && imageGenRequested) {
const imageGenTools = await logger.time("getImageGenTools", () => getImageGenTools(modelRegistry, model));
if (imageGenTools.length > 0) {
customTools.push(...(imageGenTools as unknown as CustomTool[]));
}
}
if (settings.get("speechgen.enabled")) {