🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(tools): make image generation opt-in via pinning in chat mode (#17920)
sxjerubb406736fc97
diff --git a/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts b/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.tsindex 72126f82834..0668cb09dcf 100644--- a/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts+++ b/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts@@ -308,7 +308,7 @@ describe('createServerAgentToolsEngine', () => {expect(result.enabledToolIds).not.toContain(WebBrowsingManifest.identifier);});- it('should enable ImageGeneration in chat mode when model lacks native image output', () => {+ it('should not auto-enable ImageGeneration in chat mode', () => {const context = createMockContext();const engine = createServerAgentToolsEngine(context, {agentConfig: {@@ -326,6 +326,27 @@ describe('createServerAgentToolsEngine', () => {toolIds: [],});+ expect(result.enabledToolIds).not.toContain(ImageGenerationManifest.identifier);+ });++ it('should enable ImageGeneration in chat mode when the tool is pinned', () => {+ const context = createMockContext();+ const engine = createServerAgentToolsEngine(context, {+ agentConfig: {+ chatConfig: { enableAgentMode: false },+ plugins: [ImageGenerationManifest.identifier],+ },+ model: 'claude-sonnet',+ modelAbilities: { functionCall: true, imageOutput: false },+ provider: 'anthropic',+ });++ const result = engine.generateToolsDetailed({+ model: 'claude-sonnet',+ provider: 'anthropic',+ toolIds: [ImageGenerationManifest.identifier],+ });+expect(result.enabledToolIds).toContain(ImageGenerationManifest.identifier);});@@ -334,7 +355,7 @@ describe('createServerAgentToolsEngine', () => {const engine = createServerAgentToolsEngine(context, {agentConfig: {chatConfig: { enableAgentMode: false },- plugins: [],+ plugins: [ImageGenerationManifest.identifier],},model: 'gpt-image-chat',modelAbilities: { functionCall: true, imageOutput: true },@@ -344,7 +365,7 @@ describe('createServerAgentToolsEngine', () => {const result = engine.generateToolsDetailed({model: 'gpt-image-chat',provider: 'openai',- toolIds: [],+ toolIds: [ImageGenerationManifest.identifier],});expect(result.enabledToolIds).not.toContain(ImageGenerationManifest.identifier);@@ -357,7 +378,7 @@ describe('createServerAgentToolsEngine', () => {const engine = createServerAgentToolsEngine(context, {agentConfig: {chatConfig: { enableAgentMode: false },- plugins: [],+ plugins: [ImageGenerationManifest.identifier],},model: 'plain-text-model',modelAbilities: { functionCall: false, imageOutput: false },@@ -367,7 +388,7 @@ describe('createServerAgentToolsEngine', () => {const result = engine.generateToolsDetailed({model: 'plain-text-model',provider: 'test',- toolIds: [],+ toolIds: [ImageGenerationManifest.identifier],});expect(result.enabledToolIds).not.toContain(ImageGenerationManifest.identifier);diff --git a/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts b/apps/server/src/modules/Mecha/AgentToolsEngine/index.tsindex efa8437d616..db446c28144 100644--- a/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts+++ b/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts@@ -29,6 +29,7 @@ import { createEnableChecker, type LobeToolManifest } from '@lobechat/context-enimport { ToolsEngine } from '@lobechat/context-engine';import {type BuiltinToolManifest,+ getActivePluginIds,type RuntimeEnvMode,type RuntimePlatform,} from '@lobechat/types';@@ -254,8 +255,13 @@ export const createServerAgentToolsEngine = (const searchMode = agentConfig.chatConfig?.searchMode ?? 'auto';const isSearchEnabled = useApplicationBuiltinSearchTool ?? searchMode !== 'off';- const imageGenerationEnabled =+ // Chat mode no longer auto-injects image generation. Opt in by pinning the+ // tool; native imageOutput models never receive the fallback.+ const pinnedPluginIds = getActivePluginIds(agentConfig.plugins);+ const imageGenerationCapable =context.isModelSupportToolUse(model, provider) && !modelAbilities?.imageOutput;+ const imageGenerationEnabled =+ imageGenerationCapable && pinnedPluginIds.includes(ImageGenerationManifest.identifier);// Tool mode: explicit `toolMode` wins; otherwise derive from `enableAgentMode`// (undefined = agent). `custom` = toolset is exactly the agent's plugins.const toolMode = resolveToolMode(agentConfig.chatConfig ?? undefined);@@ -275,14 +281,12 @@ export const createServerAgentToolsEngine = (isChatMode,);- // Chat mode: strict outer whitelist. Drop user plugins, alwaysOn tools, and- // every other runtime-managed rule. Each entry below still passes through- // its own runtime gate (KB needs enabled bases, memory needs global toggle,- // web-browsing needs search on). `allowExplicitActivation` is off so the- // activator can't smuggle anything else in.+ // Chat mode: strict outer whitelist. Drop alwaysOn tools and every other+ // runtime-managed rule. Each entry still passes through its own gate (KB /+ // memory / search). Image generation is opt-in via a pinned plugin — no+ // automatic injection. `allowExplicitActivation` is off so the activator+ // can't smuggle anything else in.const chatModeRules = {- // Example: Claude can call tools but lacks native imageOutput, so expose the- // image-generation fallback; image-output models should use their native path.[ImageGenerationManifest.identifier]: imageGenerationEnabled,[KnowledgeBaseManifest.identifier]: hasEnabledKnowledgeBases,[MemoryManifest.identifier]: globalMemoryEnabled,diff --git a/locales/en-US/setting.json b/locales/en-US/setting.jsonindex 0192f21c8de..90c592a15e7 100644--- a/locales/en-US/setting.json+++ b/locales/en-US/setting.json@@ -1311,6 +1311,9 @@"tools.builtins.lobe-group-agent-builder.title": "Group Agent Builder","tools.builtins.lobe-group-management.description": "Orchestrate and manage multi-agent group conversations","tools.builtins.lobe-group-management.title": "Group Management",+ "tools.builtins.lobe-image-generation.description": "Generate images through LobeHub providers when the current chat model has no native image output.",+ "tools.builtins.lobe-image-generation.readme": "Opt-in image generation for models without native image output. Pin this tool to enable it in chat or agent mode; leave unpinned to avoid the tool schema cost.",+ "tools.builtins.lobe-image-generation.title": "Image Generation","tools.builtins.lobe-knowledge-base.description": "Search uploaded documents and domain knowledge via semantic vector search — for persistent, reusable reference","tools.builtins.lobe-knowledge-base.title": "Knowledge Base","tools.builtins.lobe-local-system.description": "Access and manage local files, run shell commands on your desktop",diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.jsonindex 51c56105911..a6abf091e13 100644--- a/locales/zh-CN/setting.json+++ b/locales/zh-CN/setting.json@@ -1311,6 +1311,9 @@"tools.builtins.lobe-group-agent-builder.title": "群组助手构建器","tools.builtins.lobe-group-management.description": "编排并管理多助手群组对话","tools.builtins.lobe-group-management.title": "群组管理",+ "tools.builtins.lobe-image-generation.description": "在当前对话模型没有原生出图能力时,通过 LobeHub 的图片生成通道生成图片。",+ "tools.builtins.lobe-image-generation.readme": "可选的图片生成能力,适用于没有原生出图的模型。固定(Pin)后可在对话/Agent 模式使用;不固定则不注入工具 schema,避免额外 token 消耗。",+ "tools.builtins.lobe-image-generation.title": "图片生成","tools.builtins.lobe-knowledge-base.description": "通过语义向量检索搜索已上传的文档与领域知识 — 适用于持久、可复用的参考资料","tools.builtins.lobe-knowledge-base.title": "知识库","tools.builtins.lobe-local-system.description": "访问和管理本地文件,在桌面端运行 Shell 命令",diff --git a/packages/builtin-tools/src/index.ts b/packages/builtin-tools/src/index.tsindex 0efb7831a95..fa2cbedfe08 100644--- a/packages/builtin-tools/src/index.ts+++ b/packages/builtin-tools/src/index.ts@@ -100,11 +100,13 @@ export const manualModeExcludeToolIds = [* (`chatConfig.enableAgentMode === false`). Each one still passes through* its own runtime gate (e.g. knowledge base requires `hasEnabledKnowledgeBases`,* memory requires the global memory setting, web-browsing requires search- * enabled) — this list is the strict outer whitelist.+ * enabled, image-generation requires an explicit pin). This list is the+ * strict outer whitelist.** In chat mode, both the server `createServerAgentToolsEngine` and the* frontend `createAgentToolsEngine` build their rules from ONLY these- * identifiers, drop user plugins / `alwaysOnToolIds` entirely, and disable+ * identifiers, drop user plugins / `alwaysOnToolIds` entirely (except+ * image-generation, which is re-enabled only when pinned), and disable* `allowExplicitActivation` so the activator can't smuggle other tools in.*/export const chatModeAllowedToolIds = [@@ -283,7 +285,8 @@ const builtinToolRegistry: LobeBuiltinTool[] = [type: 'builtin',},{- hidden: true,+ // Opt-in image generation: chat mode no longer auto-injects it, so the+ // Tools popover must expose a pin/disable control.identifier: ImageGenerationManifest.identifier,manifest: ImageGenerationManifest,type: 'builtin',diff --git a/packages/const/src/recommendedSkill.ts b/packages/const/src/recommendedSkill.tsindex ddc4b88825f..8588107d236 100644--- a/packages/const/src/recommendedSkill.ts+++ b/packages/const/src/recommendedSkill.ts@@ -17,6 +17,8 @@ export const RECOMMENDED_SKILLS: RecommendedSkillItem[] = [{ id: 'lobe-task', type: RecommendedSkillType.Builtin },{ id: 'lobe-agent-documents', type: RecommendedSkillType.Builtin },{ id: 'lobe-message', type: RecommendedSkillType.Builtin },+ // Opt-in chat image generation: default-installed so Tools can pin it without Skill Store first.+ { id: 'lobe-image-generation', type: RecommendedSkillType.Builtin },// LobeHub skills{ id: 'notion', type: RecommendedSkillType.Lobehub },{ id: 'posthog', type: RecommendedSkillType.Lobehub },diff --git a/packages/const/src/taskTemplate.test.ts b/packages/const/src/taskTemplate.test.tsindex 806e555cd9e..75a9d8aeb94 100644--- a/packages/const/src/taskTemplate.test.ts+++ b/packages/const/src/taskTemplate.test.ts@@ -26,4 +26,11 @@ describe('taskTemplate constants', () => {type: RecommendedSkillType.Lobehub,});});++ it('keeps image generation default-installed as a recommended builtin', () => {+ expect(RECOMMENDED_SKILLS).toContainEqual({+ id: 'lobe-image-generation',+ type: RecommendedSkillType.Builtin,+ });+ });});diff --git a/packages/locales/src/default/setting.ts b/packages/locales/src/default/setting.tsindex a3003e7f420..140b34bce5b 100644--- a/packages/locales/src/default/setting.ts+++ b/packages/locales/src/default/setting.ts@@ -3155,6 +3155,11 @@ When I am ___, I need ___'tools.builtins.lobe-web-browsing.readme':'Search the web for current information and crawl web pages to extract content. Supports multiple search engines, categories, and time ranges for comprehensive research.','tools.builtins.lobe-web-browsing.title': 'Web Browsing',+ 'tools.builtins.lobe-image-generation.description':+ 'Generate images through LobeHub providers when the current chat model has no native image output.',+ 'tools.builtins.lobe-image-generation.readme':+ 'Opt-in image generation for models without native image output. Pin this tool to enable it in chat or agent mode; leave unpinned to avoid the tool schema cost.',+ 'tools.builtins.lobe-image-generation.title': 'Image Generation','tools.builtins.lobe-web-onboarding.description':'Drive the web onboarding flow with a controlled agent runtime','tools.builtins.lobe-web-onboarding.title': 'Web Onboarding',diff --git a/src/helpers/toolEngineering/index.test.ts b/src/helpers/toolEngineering/index.test.tsindex 2ccefc489fa..c58e3c2da07 100644--- a/src/helpers/toolEngineering/index.test.ts+++ b/src/helpers/toolEngineering/index.test.ts@@ -319,7 +319,7 @@ describe('toolEngineering', () => {});describe('createChatToolsEngine', () => {- it('should enable image generation in chat mode when model lacks native image output', () => {+ it('should not auto-enable image generation in chat mode', () => {mockCurrentChatConfig = { enableAgentMode: false };mockImageOutputSupport = false;@@ -334,11 +334,31 @@ describe('toolEngineering', () => {provider: 'anthropic',});+ expect(result.enabledToolIds).not.toContain('lobe-image-generation');+ });++ it('should enable image generation in chat mode when the tool is pinned', () => {+ mockCurrentChatConfig = { enableAgentMode: false };+ mockCurrentAgentPlugins = ['lobe-image-generation'];+ mockImageOutputSupport = false;++ const toolsEngine = createAgentToolsEngine({+ model: 'claude-sonnet',+ provider: 'anthropic',+ });++ const result = toolsEngine.generateToolsDetailed({+ toolIds: ['lobe-image-generation'],+ model: 'claude-sonnet',+ provider: 'anthropic',+ });+expect(result.enabledToolIds).toContain('lobe-image-generation');});it('should not enable image generation in chat mode when model has native image output', () => {mockCurrentChatConfig = { enableAgentMode: false };+ mockCurrentAgentPlugins = ['lobe-image-generation'];mockImageOutputSupport = true;const toolsEngine = createAgentToolsEngine({@@ -347,7 +367,7 @@ describe('toolEngineering', () => {});const result = toolsEngine.generateToolsDetailed({- toolIds: [],+ toolIds: ['lobe-image-generation'],model: 'gpt-image-chat',provider: 'openai',});@@ -357,6 +377,7 @@ describe('toolEngineering', () => {it('should not enable image generation in chat mode when model cannot call tools', () => {mockCurrentChatConfig = { enableAgentMode: false };+ mockCurrentAgentPlugins = ['lobe-image-generation'];mockIsCanUseFC = false;const toolsEngine = createAgentToolsEngine({@@ -365,7 +386,7 @@ describe('toolEngineering', () => {});const result = toolsEngine.generateToolsDetailed({- toolIds: [],+ toolIds: ['lobe-image-generation'],model: 'plain-text-model',provider: 'test',});diff --git a/src/helpers/toolEngineering/index.ts b/src/helpers/toolEngineering/index.tsindex 23b3dc4cac5..37954cf4a50 100644--- a/src/helpers/toolEngineering/index.ts+++ b/src/helpers/toolEngineering/index.ts@@ -234,16 +234,19 @@ export const createAgentToolsEngine = (agentChatConfigSelectors.currentChatConfig(agentState).memory?.enabled ??settingsSelectors.memoryEnabled(useUserStore.getState());const webBrowsingEnabled = searchConfig.useApplicationBuiltinSearchTool;- const imageGenerationEnabled =+ // Chat mode no longer auto-injects image generation (token cost + unwanted+ // tool calls). Users opt in by pinning `lobe-image-generation`. Models with+ // native imageOutput still skip the fallback tool entirely.+ const imageGenerationCapable =isCanUseFC(workingModel.model, workingModel.provider) &&!aiModelSelectors.isModelSupportImageOutput(workingModel.model,workingModel.provider,)(getAiInfraStoreState());+ const imageGenerationEnabled =+ imageGenerationCapable && userPlugins.includes(ImageGenerationManifest.identifier);const chatModeRules = {- // Example: Claude can call tools but lacks native imageOutput, so expose the- // image-generation fallback; image-output models should use their native path.[ImageGenerationManifest.identifier]: imageGenerationEnabled,[KnowledgeBaseManifest.identifier]: kbEnabled,[MemoryManifest.identifier]: memoryEnabled,