π€― 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
β¨ feat(tool): surface memory and web search in the tools popover (#20591)
Arvin Xubcfad9d58155
diff --git a/src/features/ChatInput/ActionBar/Memory/Controls.tsx b/src/features/ChatInput/ActionBar/Memory/Controls.tsxindex 78065689e7f..015d038dbe1 100644--- a/src/features/ChatInput/ActionBar/Memory/Controls.tsx+++ b/src/features/ChatInput/ActionBar/Memory/Controls.tsx@@ -94,7 +94,14 @@ const ToggleItem = memo<ToggleOption>(({ value, description, icon, label }) => {);});-const Controls = memo(() => {+/**+ * Agent-level memory effort override. Rendered next to the Pinned/Auto/Disable+ * policy of the memory capability row in the chat-input Tools popover, so moving+ * the memory entry out of the "+" menu keeps its tuning reachable. It owns the+ * separator above itself and disappears entirely while memory is off, so a host+ * panel never ends up with a divider that separates nothing.+ */+export const MemoryEffortControl = memo(() => {const { t } = useTranslation('chat');const agentId = useAgentId();const { updateAgentChatConfig } = useUpdateAgentConfig();@@ -102,6 +109,48 @@ const Controls = memo(() => {const { allowed: canCreate } = usePermission('create_content');const effort = useAgentStore((s) => chatConfigByIdSelectors.getMemoryToolEffortById(agentId)(s));+ if (!isEnabled) return null;++ return (+ <>+ <Divider style={{ margin: 0 }} />+ <Flexbox horizontal align={'center'} gap={16} padding={8}>+ <Flexbox flex={1} gap={4} style={{ minWidth: 100 }}>+ <div className={styles.title}>{t('memory.effort.title')}</div>+ <div className={styles.description}>{t('memory.effort.desc')}</div>+ </Flexbox>+ <Flexbox+ flex={1}+ style={{+ opacity: canCreate ? undefined : 0.5,+ pointerEvents: canCreate ? undefined : 'none',+ }}+ >+ <LevelSlider<UserMemoryEffort>+ defaultValue="medium"+ levels={MEMORY_EFFORT_LEVELS}+ value={effort}+ marks={{+ 0: t('memory.effort.low.title'),+ 1: t('memory.effort.medium.title'),+ 2: t('memory.effort.high.title'),+ }}+ onChange={async (value) => {+ if (!canCreate) return;+ await updateAgentChatConfig({ memory: { effort: value, enabled: true } });+ }}+ />+ </Flexbox>+ </Flexbox>+ </>+ );+});++MemoryEffortControl.displayName = 'MemoryEffortControl';++const Controls = memo(() => {+ const { t } = useTranslation('chat');+const toggleOptions: ToggleOption[] = [{description: t('memory.off.desc'),@@ -122,39 +171,7 @@ const Controls = memo(() => {{toggleOptions.map((option) => (<ToggleItem {...option} key={option.value} />))}- {isEnabled && (- <>- <Divider style={{ margin: 0 }} />- <Flexbox horizontal align={'center'} gap={16} padding={8}>- <Flexbox flex={1} gap={4} style={{ minWidth: 100 }}>- <div className={styles.title}>{t('memory.effort.title')}</div>- <div className={styles.description}>{t('memory.effort.desc')}</div>- </Flexbox>- <Flexbox- flex={1}- style={{- opacity: canCreate ? undefined : 0.5,- pointerEvents: canCreate ? undefined : 'none',- }}- >- <LevelSlider<UserMemoryEffort>- defaultValue="medium"- levels={MEMORY_EFFORT_LEVELS}- value={effort}- marks={{- 0: t('memory.effort.low.title'),- 1: t('memory.effort.medium.title'),- 2: t('memory.effort.high.title'),- }}- onChange={async (value) => {- if (!canCreate) return;- await updateAgentChatConfig({ memory: { effort: value, enabled: true } });- }}- />- </Flexbox>- </Flexbox>- </>- )}+ <MemoryEffortControl /></Flexbox>);});diff --git a/src/features/ChatInput/ActionBar/Plus/index.tsx b/src/features/ChatInput/ActionBar/Plus/index.tsxindex 21b00d81c6c..409c9764ccb 100644--- a/src/features/ChatInput/ActionBar/Plus/index.tsx+++ b/src/features/ChatInput/ActionBar/Plus/index.tsx@@ -1,22 +1,17 @@'use client';import { validateVideoFileSize } from '@lobechat/utils/client';-import type { IconProps } from '@lobehub/ui';import { Icon, Popover } from '@lobehub/ui';import { toast, Upload } from '@lobehub/ui/base-ui';-import { GlobeOffIcon, SkillsIcon } from '@lobehub/ui/icons';+import { SkillsIcon } from '@lobehub/ui/icons';import { css, cssVar, cx } from 'antd-style';import {- Brain,CheckIcon,ChevronRight,Cloud,- CloudCog,FileUp,- Globe,LibraryBig,PlusIcon,- SearchCheck,Settings2Icon,TargetIcon,TypeIcon,@@ -31,7 +26,6 @@ import { useMediaUploadAbility } from '@/hooks/useMediaUploadAbility';import { useModelSupportToolUse } from '@/hooks/useModelSupportToolUse';import { useAgentStore } from '@/store/agent';import { agentSelectors, chatConfigByIdSelectors } from '@/store/agent/selectors';-import { aiModelSelectors, aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';import { useFileStore } from '@/store/file';import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';@@ -54,7 +48,6 @@ import { type ActionDropdownMenuItems } from '../components/ActionDropdown';import { ChatInputAction } from '../components/ChatInputAction';import { useDetailPopoverState } from '../components/useDetailPopoverState';import { useControls as useKnowledgeControls } from '../Knowledge/useControls';-import { useMemoryEnabled } from '../Memory/useMemoryEnabled';import { useControls as useToolsControls } from '../Tools/useControls';const hotArea = css`@@ -84,43 +77,6 @@ const activeLabel = css`}`;-const searchOptionRow = css`- display: flex;- gap: 10px;- align-items: center;-- width: 100%;- min-width: 220px;- max-width: 320px;-- .title {- line-height: 1.25;- }-- .desc {- margin-block-start: 3px;-- font-size: 12px;- line-height: 1.35;- color: ${cssVar.colorTextDescription};- white-space: normal;- }-`;--const searchIconBox = css`- display: flex;- flex: none;- align-items: center;- justify-content: center;-- width: 36px;- height: 36px;- border: 1px solid ${cssVar.colorBorderSecondary};- border-radius: 8px;-- background: ${cssVar.colorBgContainer};-`;-const labelWithChip = css`display: inline-flex;gap: 8px;@@ -178,9 +134,6 @@ const gatewayModeInfoCard = css`}`;-const activeIcon = (icon: IconProps['icon'], active?: boolean): IconProps['icon'] =>- active ? <Icon color={cssVar.colorInfo} icon={icon} size={16} /> : icon;-type DropdownItemWithPopover = NonNullable<ActionDropdownMenuItems>[number] & {label?: ReactNode;popoverContent?: unknown;@@ -307,14 +260,11 @@ const usePlusMenuItems = ({ close }: { close: () => void }): ActionDropdownMenuIconst skillActivateMode = useAgentStore((s) =>chatConfigByIdSelectors.getSkillActivateModeById(agentId)(s),);- const [searchMode, useModelBuiltinSearch, disableGatewayMode] = useAgentStore((s) => [- chatConfigByIdSelectors.getSearchModeById(agentId)(s),- chatConfigByIdSelectors.getUseModelBuiltinSearchById(agentId)(s),- chatConfigByIdSelectors.getChatConfigById(agentId)(s).disableGatewayMode,- ]);+ const disableGatewayMode = useAgentStore(+ (s) => chatConfigByIdSelectors.getChatConfigById(agentId)(s).disableGatewayMode,+ );const isGatewayModeEnabled = (disableGatewayMode ?? defaultDisableGatewayMode) !== true;- const isMemoryEnabled = useMemoryEnabled(agentId);const [showTypoBar, setShowTypoBar] = useChatInputStore((s) => [s.showTypoBar, s.setShowTypoBar]);const editor = useChatInputStore((s) => s.editor);const routeLargeFilesToLocalPaths = useLargeFileLocalPath(agentId, editor);@@ -343,42 +293,6 @@ const usePlusMenuItems = ({ close }: { close: () => void }): ActionDropdownMenuIpinnedCount: skillPinnedCount,} = useToolsControls({ closeDropdown });- const isModelBuiltinSearchInternal = useAiInfraStore(- aiModelSelectors.isModelBuiltinSearchInternal(model, provider),- );- const isModelHasBuiltinSearch = useAiInfraStore(- aiModelSelectors.isModelHasBuiltinSearchConfig(model, provider),- );- const isProviderHasBuiltinSearch = useAiInfraStore(- aiProviderSelectors.isProviderHasBuiltinSearchConfig(provider),- );- const showProviderSearch =- !isModelBuiltinSearchInternal && (isModelHasBuiltinSearch || isProviderHasBuiltinSearch);-- // Derived active search option- const activeSearchOption: 'off' | 'app' | 'provider' =- searchMode === 'off' ? 'off' : useModelBuiltinSearch ? 'provider' : 'app';-- const handleToggleMemory = useCallback(- async (enabled: boolean) => {- await updateAgentChatConfig({ memory: { enabled } });- },- [updateAgentChatConfig],- );-- const handleSelectSearch = useCallback(- async (option: 'off' | 'app' | 'provider') => {- if (option === 'off') {- await updateAgentChatConfig({ searchMode: 'off', useModelBuiltinSearch: false });- } else if (option === 'app') {- await updateAgentChatConfig({ searchMode: 'auto', useModelBuiltinSearch: false });- } else {- await updateAgentChatConfig({ searchMode: 'auto', useModelBuiltinSearch: true });- }- },- [updateAgentChatConfig],- );-const handleToggleGatewayMode = useCallback(async (checked: boolean) => {await updateAgentChatConfig({ disableGatewayMode: checked ? false : true });@@ -406,22 +320,6 @@ const usePlusMenuItems = ({ close }: { close: () => void }): ActionDropdownMenuIlabel);- const renderSearchOption = (- icon: ReactNode,- title: string,- description: string,- active: boolean,- ) => (- <div className={cx(searchOptionRow)}>- <div className={cx(searchIconBox)}>{icon}</div>- <div style={{ flex: 1, minWidth: 0 }}>- <div className="title">{title}</div>- {description && <div className="desc">{description}</div>}- </div>- {active && <Icon icon={CheckIcon} size={14} />}- </div>- );-const renderLabelWithCount = (label: string, count: number, prefix?: string) =>count > 0 || prefix ? (<span className={cx(labelWithChip)}>@@ -541,88 +439,10 @@ const usePlusMenuItems = ({ close }: { close: () => void }): ActionDropdownMenuI]: [];- // Memory / Web Search / Skills form one group (no dividers between them),- // hidden entirely when the user can't configure resources.- const coreItems: ActionDropdownMenuItems = canConfigureResource- ? [- // Memory toggle β trailing switch; toggle by clicking the switch or the whole row- {- checked: Boolean(isMemoryEnabled),- icon: Brain,- key: 'memory',- label: t('memory.title'),- onCheckedChange: handleToggleMemory,- type: 'switch',- },- // Web search: simple toggle when 2 options, submenu when 3- ...(showProviderSearch- ? [- {- children: [- {- key: 'search-off',- label: renderSearchOption(- <Icon icon={GlobeOffIcon} size={18} />,- t('plus.search.off'),- t('plus.search.offDesc'),- activeSearchOption === 'off',- ),- onClick: () => handleSelectSearch('off'),- },- {- key: 'search-app',- label: renderSearchOption(- <Icon- color={activeSearchOption === 'app' ? cssVar.colorInfo : undefined}- icon={SearchCheck}- size={18}- />,- t('plus.search.appSearch'),- t('plus.search.appSearchDesc'),- activeSearchOption === 'app',- ),- onClick: () => handleSelectSearch('app'),- },- {- key: 'search-provider',- label: renderSearchOption(- <Icon- color={activeSearchOption === 'provider' ? cssVar.colorInfo : undefined}- icon={CloudCog}- size={18}- />,- t('plus.search.modelSearch'),- t('plus.search.modelSearchDesc'),- activeSearchOption === 'provider',- ),- onClick: () => handleSelectSearch('provider'),- },- ],- extra: <Icon className="lobe-submenu-chevron" icon={ChevronRight} size={16} />,- icon: activeIcon(- activeSearchOption === 'off' ? GlobeOffIcon : Globe,- activeSearchOption !== 'off',- ),- key: 'search-group',- label: t('search.title'),- } as ActionDropdownMenuItems[number],- ]- : [- // Web search toggle β trailing switch; toggle by clicking the switch or the whole row- {- checked: activeSearchOption !== 'off',- icon: Globe,- key: 'search-toggle',- label: t('search.title'),- onCheckedChange: (checked: boolean) =>- handleSelectSearch(checked ? 'app' : 'off'),- type: 'switch',- } as ActionDropdownMenuItems[number],- ]),- // Skills (with "Add Skills..." merged in) stays in the same group.- ...toolsItems,- ]- : [];+ // Memory and web search are activation entries of the Tools popover now: they+ // live in its "Auto" group, can be disabled there, and carry their own settings,+ // so this menu only owns the route to them.+ const coreItems: ActionDropdownMenuItems = canConfigureResource ? [...toolsItems] : [];// Formatting toolbar is always available; Agent Gateway + advanced params// only when the user can configure resources.@@ -715,7 +535,6 @@ const usePlusMenuItems = ({ close }: { close: () => void }): ActionDropdownMenuI.flatMap((group, index) => (index === 0 ? group : [{ type: 'divider' as const }, ...group]));}, [agentId,- activeSearchOption,canConfigureResource,enableGoals,canUploadImage,@@ -725,19 +544,15 @@ const usePlusMenuItems = ({ close }: { close: () => void }): ActionDropdownMenuIenableFC,enableGatewayMode,enableKnowledgeBase,- handleSelectSearch,handleToggleGatewayMode,- handleToggleMemory,handleToggleParams,isAgentModeEnabled,isDark,isGatewayModeEnabled,- isMemoryEnabled,isParamsPanelActive,isSkillPolicyMenuOpen,knowledgeEnabledCount,setShowTypoBar,- showProviderSearch,showTypoBar,skillActivateMode,skillAutoCount,diff --git a/src/features/ChatInput/ActionBar/Search/Controls.tsx b/src/features/ChatInput/ActionBar/Search/Controls.tsxindex 422f066ab41..76127bc2f70 100644--- a/src/features/ChatInput/ActionBar/Search/Controls.tsx+++ b/src/features/ChatInput/ActionBar/Search/Controls.tsx@@ -99,10 +99,14 @@ const Item = memo<NetworkOption>(({ value, description, icon, label }) => {);});-const Controls = memo(() => {- const { t } = useTranslation('chat');+/**+ * Search settings that are only meaningful once web search is on: which engine+ * answers (app tool vs the model's built-in search) and which model runs the+ * function-calling search. Extracted so the search capability row in the+ * chat-input Tools popover can host it beside the Auto/Disable policy.+ */+export const SearchAdvancedControls = memo(() => {const agentId = useAgentId();- const { updateAgentChatConfig } = useUpdateAgentConfig();const { allowed: canCreate } = usePermission('create_content');const { model, provider } = useEffectiveModel(agentId);@@ -125,6 +129,43 @@ const Controls = memo(() => {aiModelSelectors.modelBuiltinSearchImpl(model, provider),);+ const showModelBuiltinSearch =+ searchMode !== 'off' &&+ !isModelBuiltinSearchInternal &&+ (isModelHasBuiltinSearchConfig || isProviderHasBuiltinSearchConfig);++ const showFCSearchModel =+ !supportFC &&+ (!modelBuiltinSearchImpl || (!isModelBuiltinSearchInternal && !useModelBuiltinSearch));++ if (!showModelBuiltinSearch && !showFCSearchModel) return null;++ return (+ <>+ <Divider style={{ margin: 0 }} />+ {showModelBuiltinSearch && <ModelBuiltinSearch disabled={!canCreate} />}+ {showFCSearchModel && <FCSearchModel disabled={!canCreate} />}+ </>+ );+});++SearchAdvancedControls.displayName = 'SearchAdvancedControls';++const Controls = memo(() => {+ const { t } = useTranslation('chat');+ const agentId = useAgentId();+ const { updateAgentChatConfig } = useUpdateAgentConfig();+ const { allowed: canCreate } = usePermission('create_content');++ const { model, provider } = useEffectiveModel(agentId);+ const searchMode = useAgentStore(+ (s) => chatConfigByIdSelectors.getChatConfigById(agentId)(s).searchMode,+ );++ const isModelBuiltinSearchInternal = useAiInfraStore(+ aiModelSelectors.isModelBuiltinSearchInternal(model, provider),+ );+useEffect(() => {if (!canCreate) return;if (isModelBuiltinSearchInternal && (searchMode ?? 'auto') === 'off') {@@ -159,25 +200,12 @@ const Controls = memo(() => {},];- const showModelBuiltinSearch =- searchMode !== 'off' &&- !isModelBuiltinSearchInternal &&- (isModelHasBuiltinSearchConfig || isProviderHasBuiltinSearchConfig);-- const showFCSearchModel =- !supportFC &&- (!modelBuiltinSearchImpl || (!isModelBuiltinSearchInternal && !useModelBuiltinSearch));-- const showDivider = showModelBuiltinSearch || showFCSearchModel;-return (<Flexbox gap={4}>{options.map((option) => (<Item {...option} key={option.value} />))}- {showDivider && <Divider style={{ margin: 0 }} />}- {showModelBuiltinSearch && <ModelBuiltinSearch disabled={!canCreate} />}- {showFCSearchModel && <FCSearchModel disabled={!canCreate} />}+ <SearchAdvancedControls /></Flexbox>);});diff --git a/src/features/ChatInput/ActionBar/Tools/capabilityTools.test.ts b/src/features/ChatInput/ActionBar/Tools/capabilityTools.test.tsnew file mode 100644index 00000000000..866091b00f0--- /dev/null+++ b/src/features/ChatInput/ActionBar/Tools/capabilityTools.test.ts@@ -0,0 +1,71 @@+import { MemoryManifest } from '@lobechat/builtin-tool-memory';+import { WebBrowsingManifest } from '@lobechat/builtin-tool-web-browsing';+import { describe, expect, it } from 'vitest';++import {+ isCapabilityTool,+ resolveCapabilityConfigPatch,+ resolveCapabilityMode,+} from './capabilityTools';++describe('capabilityTools', () => {+ describe('resolveCapabilityMode', () => {+ it('reports an enabled capability as Auto', () => {+ expect(resolveCapabilityMode(true)).toBe('auto');+ });++ it('reports a disabled capability as Disabled', () => {+ expect(resolveCapabilityMode(false)).toBe('disabled');+ });++ it('reports a pinned capability as Pinned, whether or not it is enabled', () => {+ expect(resolveCapabilityMode(true, true)).toBe('pinned');+ expect(resolveCapabilityMode(false, true)).toBe('pinned');+ });+ });++ describe('isCapabilityTool', () => {+ it('recognises memory and web browsing', () => {+ expect(isCapabilityTool(MemoryManifest.identifier)).toBe(true);+ expect(isCapabilityTool(WebBrowsingManifest.identifier)).toBe(true);+ });++ it('leaves ordinary skills on the plugin policy', () => {+ expect(isCapabilityTool('some-mcp-plugin')).toBe(false);+ });+ });++ describe('resolveCapabilityConfigPatch', () => {+ it('turns memory off through chatConfig while keeping it on for Auto', () => {+ expect(resolveCapabilityConfigPatch(MemoryManifest.identifier, 'disabled')).toEqual({+ memory: { enabled: false },+ });+ expect(resolveCapabilityConfigPatch(MemoryManifest.identifier, 'auto')).toEqual({+ memory: { enabled: true },+ });+ });++ it('maps web browsing Auto/Disable onto the search mode', () => {+ expect(resolveCapabilityConfigPatch(WebBrowsingManifest.identifier, 'disabled')).toEqual({+ searchMode: 'off',+ });+ expect(resolveCapabilityConfigPatch(WebBrowsingManifest.identifier, 'auto')).toEqual({+ searchMode: 'auto',+ });+ });++ it('keeps the capability on when it is Pinned, like Auto', () => {+ expect(resolveCapabilityConfigPatch(MemoryManifest.identifier, 'pinned')).toEqual({+ memory: { enabled: true },+ });+ expect(resolveCapabilityConfigPatch(WebBrowsingManifest.identifier, 'pinned')).toEqual({+ searchMode: 'auto',+ });+ });++ it('returns no patch for a tool that is not a capability', () => {+ expect(resolveCapabilityConfigPatch('some-mcp-plugin', 'disabled')).toBeUndefined();+ expect(resolveCapabilityConfigPatch('some-mcp-plugin', 'pinned')).toBeUndefined();+ });+ });+});diff --git a/src/features/ChatInput/ActionBar/Tools/capabilityTools.ts b/src/features/ChatInput/ActionBar/Tools/capabilityTools.tsnew file mode 100644index 00000000000..a91478005a7--- /dev/null+++ b/src/features/ChatInput/ActionBar/Tools/capabilityTools.ts@@ -0,0 +1,62 @@+import { MemoryManifest } from '@lobechat/builtin-tool-memory';+import { WebBrowsingManifest } from '@lobechat/builtin-tool-web-browsing';+import { type AgentPluginMode } from '@lobechat/types';++import { type LobeAgentChatConfig } from '@/types/agent';++/**+ * Memory and web browsing are runtime-managed builtin tools: the shared engine+ * rules (`resolveToolRules`) enable them from chatConfig β `memory.enabled` for+ * memory, `searchMode` for web browsing β instead of from `agents.plugins`.+ *+ * The Tools popover still gives them the same Pinned/Auto/Disable policy as every+ * other row, so the on/off half of that policy is translated into a chatConfig+ * patch here. Keeping a single source of truth for on/off means the row, the+ * memory injection and the search wiring can never disagree about whether the+ * capability is on. The optional pin is recorded in `agents.plugins` like every+ * other skill β chatConfig only carries on/off β so Pinned and Auto share a patch.+ */+const CAPABILITY_CONFIG_PATCHES: Record<+ string,+ { off: Partial<LobeAgentChatConfig>; on: Partial<LobeAgentChatConfig> }+> = {+ [MemoryManifest.identifier]: {+ off: { memory: { enabled: false } },+ on: { memory: { enabled: true } },+ },+ [WebBrowsingManifest.identifier]: {+ off: { searchMode: 'off' },+ on: { searchMode: 'auto' },+ },+};++/**+ * Activation label a capability row shows. On/off comes from chatConfig rather than+ * from the plugin list, while `pinned` additionally records the explicit pin in+ * `agents.plugins` β that is what moves the row into the Pinned group.+ */+export const resolveCapabilityMode = (enabled: boolean, pinned = false): AgentPluginMode => {+ if (pinned) return 'pinned';++ return enabled ? 'auto' : 'disabled';+};++/** Whether `identifier`'s activation is backed by chatConfig rather than only `agents.plugins`. */+export const isCapabilityTool = (identifier: string): boolean =>+ identifier in CAPABILITY_CONFIG_PATCHES;++/**+ * chatConfig patch that applies `mode` to a capability tool, or `undefined` when the+ * identifier is not a capability tool (callers then fall back to the plugin policy).+ * Pinned and Auto both mean "on" β the difference is only where the explicit choice+ * is recorded β while Disabled means "off".+ */+export const resolveCapabilityConfigPatch = (+ identifier: string,+ mode: AgentPluginMode,+): Partial<LobeAgentChatConfig> | undefined => {+ const patches = CAPABILITY_CONFIG_PATCHES[identifier];+ if (!patches) return undefined;++ return mode === 'disabled' ? patches.off : patches.on;+};diff --git a/src/features/ChatInput/ActionBar/Tools/useControls.tsx b/src/features/ChatInput/ActionBar/Tools/useControls.tsxindex 5af08eb191d..2cecdee2d69 100644--- a/src/features/ChatInput/ActionBar/Tools/useControls.tsx+++ b/src/features/ChatInput/ActionBar/Tools/useControls.tsx@@ -1,3 +1,5 @@+import { MemoryManifest } from '@lobechat/builtin-tool-memory';+import { WebBrowsingManifest } from '@lobechat/builtin-tool-web-browsing';import { getConnectorCatalog, RECOMMENDED_SKILLS, RecommendedSkillType } from '@lobechat/const';import { type AgentPluginMode, getDisabledPluginIds } from '@lobechat/types';import type { ItemType } from '@lobehub/ui';@@ -34,6 +36,7 @@ import { useFetchInstalledPlugins } from '@/hooks/useFetchInstalledPlugins';import { usePermission } from '@/hooks/usePermission';import { useAgentStore } from '@/store/agent';import { agentByIdSelectors, chatConfigByIdSelectors } from '@/store/agent/selectors';+import { aiModelSelectors, useAiInfraStore } from '@/store/aiInfra';import { serverConfigSelectors, useServerConfigStore } from '@/store/serverConfig';import { useToolStore } from '@/store/tool';import {@@ -48,8 +51,17 @@ import { connectorSelectors } from '@/store/tool/slices/connector';import { LobehubSkillStatus } from '@/store/tool/slices/lobehubSkillStore/types';import { useAgentId } from '../../hooks/useAgentId';+import { useEffectiveModel } from '../../hooks/useEffectiveModel';import { useUpdateAgentConfig } from '../../hooks/useUpdateAgentConfig';import { closeToolDetailPopovers } from '../components/useDetailPopoverState';+import { MemoryEffortControl } from '../Memory/Controls';+import { useMemoryEnabled } from '../Memory/useMemoryEnabled';+import { SearchAdvancedControls } from '../Search/Controls';+import {+ isCapabilityTool,+ resolveCapabilityConfigPatch,+ resolveCapabilityMode,+} from './capabilityTools';import ComposioServerItem from './ComposioServerItem';import ComposioSkillIcon from './ComposioSkillIcon';import { SKILL_ICON_GAP, SKILL_ICON_SIZE, SKILL_TRAILING_CONTROL_SIZE } from './constants';@@ -69,6 +81,12 @@ const officialTag = (type SkillPolicyMode = AgentPluginMode;+// Capability rows offer the same three states as any other skill row. A model whose+// built-in search can never be turned off has no Disabled state to offer β the write+// would be overridden by the runtime β so its search row keeps Pinned/Auto only.+const CAPABILITY_MODES: SkillPolicyMode[] = ['pinned', 'auto', 'disabled'];+const CAPABILITY_MODES_WITHOUT_DISABLE: SkillPolicyMode[] = ['pinned', 'auto'];+interface SkillDeleteConfig {displayName: string;onDelete: () => Promise<void> | void;@@ -78,6 +96,39 @@ interface SkillConfigureConfig {onConfigure: () => void;}+interface SkillPolicyMenuOptions {+ configureConfig?: SkillConfigureConfig;+ /**+ * @default 'auto'+ */+ defaultMode?: SkillPolicyMode;+ deleteConfig?: SkillDeleteConfig;+ /**+ * Hide the activation options and show only the configure/delete actions. Used+ * for integrations that exist but aren't connected yet (pending auth /+ * re-authorize), where activation is meaningless but the user still needs a way+ * to remove the entry.+ */+ deleteOnly?: boolean;+ /**+ * Activation state for rows whose on/off is NOT stored in `agents.plugins` β+ * memory and web search derive it from chatConfig, so reading the plugin list+ * would report the wrong state for them.+ */+ modeOverride?: SkillPolicyMode;+ /**+ * Capability settings rendered under the activation options (e.g. the memory+ * effort level), so a capability row keeps its tuning after leaving the "+"+ * menu. The block owns the separator above itself and renders nothing when it+ * has nothing to show, so the panel never keeps a divider over empty space.+ */+ panelExtra?: ReactNode;+ /**+ * @default ['pinned', 'auto', 'disabled']+ */+ supportedModes?: SkillPolicyMode[];+}+type SkillMenuItem = NonNullable<ItemType> & {extra?: ReactNode;popoverContent?: ReactNode;@@ -316,6 +367,12 @@ const styles = createStaticStyles(({ css }) => ({0 0 15px 0 #00000008,0 2px 30px 0 #00000014;`,+ /* Capability rows (memory / web search) host their own settings under the+ activation policy, so the panel takes the width those settings had as+ standalone popovers instead of the compact 132px policy list. */+ policyPanelWide: css`+ width: 320px;+ `,policyText: css`flex: 1;text-align: start;@@ -497,9 +554,53 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =);const plugins = useAgentStore((s) => agentByIdSelectors.getAgentPluginsById(agentId)(s));+ // Memory and web browsing are runtime-managed builtin tools: `hidden` keeps them+ // out of `metaList`, and the shared engine rules force their enabled state from+ // chatConfig rather than from `agents.plugins`. They still belong in the Tools+ // popover's activation list, so their policy is derived from β and written back+ // to β that same chatConfig. One source of truth keeps every other reader of it+ // (memory injection, the search wiring) in agreement with this list.+ const isMemoryCapabilityEnabled = useMemoryEnabled(agentId);+ const { model, provider } = useEffectiveModel(agentId);+ const searchMode = useAgentStore((s) => chatConfigByIdSelectors.getSearchModeById(agentId)(s));+ const isModelBuiltinSearchInternal = useAiInfraStore(+ aiModelSelectors.isModelBuiltinSearchInternal(model, provider),+ );+ // A model whose built-in search can never be turned off has no Disabled state to+ // offer β the action would write a config the runtime keeps overriding.+ const isSearchCapabilityEnabled = isModelBuiltinSearchInternal || searchMode !== 'off';+ const searchCapabilityModes = isModelBuiltinSearchInternal+ ? CAPABILITY_MODES_WITHOUT_DISABLE+ : CAPABILITY_MODES;+ const disabledCapabilityIds = useMemo(() => {+ const ids = new Set<string>();+ if (!isMemoryCapabilityEnabled) ids.add(MemoryManifest.identifier);+ if (!isSearchCapabilityEnabled) ids.add(WebBrowsingManifest.identifier);+ return ids;+ }, [isMemoryCapabilityEnabled, isSearchCapabilityEnabled]);+const updateSkillPolicy = useCallback(async (id: string, mode: SkillPolicyMode) => {if (!canEdit) return;++ // A capability has two homes. chatConfig carries the on/off state the engine+ // reads (`resolveToolRules`), so the row, the injection and the wiring can never+ // disagree; `agents.plugins` carries the explicit Pinned/Disabled choice, which+ // is what puts the row in the Pinned or Disabled group.+ if (isCapabilityTool(id)) {+ const currentMode: SkillPolicyMode = checkedSet.has(id)+ ? 'pinned'+ : disabledIdSet.has(id)+ ? 'disabled'+ : 'auto';+ if (currentMode === mode) return;++ const patch = resolveCapabilityConfigPatch(id, mode);+ if (patch) await updateAgentChatConfig(patch);+ await setPluginMode(id, mode);+ return;+ }+const currentMode: SkillPolicyMode = checkedSet.has(id)? 'pinned': disabledIdSet.has(id)@@ -509,7 +610,7 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =await setPluginMode(id, mode);},- [canEdit, checkedSet, disabledIdSet, setPluginMode],+ [canEdit, checkedSet, disabledIdSet, setPluginMode, updateAgentChatConfig],);const openSkillPolicyMenu = useCallback((id: string) => {@@ -518,23 +619,19 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =}, []);const renderPolicyMenu = useCallback(- (- id: string,- deleteConfig?: SkillDeleteConfig,- configureConfig?: SkillConfigureConfig,- // When true, hide the Pinned/Auto activation options and show only the- // configure/delete actions. Used for integrations that exist but aren't- // connected yet (pending auth / re-authorize), where activation is- // meaningless but the user still needs a way to remove the entry.- deleteOnly = false,- supportedModes: SkillPolicyMode[] = ['pinned', 'auto', 'disabled'],- defaultMode: SkillPolicyMode = 'auto',- ) => {- const mode: SkillPolicyMode = checkedSet.has(id)- ? 'pinned'- : disabledIdSet.has(id)- ? 'disabled'- : defaultMode;+ (id: string, options: SkillPolicyMenuOptions = {}) => {+ const {+ configureConfig,+ defaultMode = 'auto',+ deleteConfig,+ deleteOnly = false,+ modeOverride,+ panelExtra,+ supportedModes = ['pinned', 'auto', 'disabled'],+ } = options;+ const mode: SkillPolicyMode =+ modeOverride ??+ (checkedSet.has(id) ? 'pinned' : disabledIdSet.has(id) ? 'disabled' : defaultMode);const renderCheck = (value: SkillPolicyMode) =>mode === value ? (<span className={cx(styles.policyCheck)}>@@ -573,7 +670,7 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =const content = (<div- className={cx(styles.policyPanel)}+ className={cx(styles.policyPanel, Boolean(panelExtra) && styles.policyPanelWide)}onClick={(event) => event.stopPropagation()}onContextMenu={(event) => event.stopPropagation()}>@@ -657,6 +754,7 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =<span className={cx(styles.policyText)}>{t('tools.builtins.uninstall')}</span></button>)}+ {panelExtra}</div>);@@ -743,14 +841,16 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =({badge,configureConfig,+ defaultMode,deleteConfig,extraTag,icon,id,+ modeOverride,+ panelExtra,popoverContent,- defaultMode,- supportedModes,searchText,+ supportedModes,title,}: {badge?: ReactNode;@@ -760,9 +860,11 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =extraTag?: ReactNode;icon: ReactNode;id: string;+ modeOverride?: SkillPolicyMode;+ panelExtra?: ReactNode;popoverContent?: ReactNode;- supportedModes?: SkillPolicyMode[];searchText?: string;+ supportedModes?: SkillPolicyMode[];title: ReactNode;}): SkillMenuItem =>({@@ -771,7 +873,14 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =label: renderToolLabel(id,title,- renderPolicyMenu(id, deleteConfig, configureConfig, false, supportedModes, defaultMode),+ renderPolicyMenu(id, {+ configureConfig,+ defaultMode,+ deleteConfig,+ modeOverride,+ panelExtra,+ supportedModes,+ }),badge,icon,extraTag,@@ -1003,15 +1112,13 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =const removableId = server?.identifier ?? type.identifier;if (server || checkedSet.has(type.identifier) || disabledIdSet.has(type.identifier)) {return {- extra: renderPolicyMenu(- removableId,- {+ extra: renderPolicyMenu(removableId, {+ deleteConfig: {displayName: type.label,onDelete: () => removeComposioServer(removableId),},- undefined,- true,- ),+ deleteOnly: true,+ }),key: removableId,label: (<span@@ -1166,6 +1273,73 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =[filteredBuiltinList, t, createManagedSkillItem, uninstallBuiltinTool],);+ // Memory / web browsing rows. Both are builtin tools the engine turns on from+ // chatConfig, so their on/off state is derived from β and written back to β that+ // same config, while the optional pin is recorded in `agents.plugins` like every+ // other skill: they get the full Pinned/Auto/Disable policy. Their own settings+ // travel with the row (`panelExtra`), because the "+" menu no longer hosts them.+ const capabilityItems: SkillMenuItem[] = useMemo(+ () =>+ [+ {+ enabled: isMemoryCapabilityEnabled,+ manifest: MemoryManifest,+ panelExtra: <MemoryEffortControl />,+ supportedModes: CAPABILITY_MODES,+ },+ {+ enabled: isSearchCapabilityEnabled,+ manifest: WebBrowsingManifest,+ panelExtra: <SearchAdvancedControls />,+ supportedModes: searchCapabilityModes,+ },+ ].map(({ enabled, manifest, panelExtra, supportedModes }) => {+ const { identifier } = manifest;+ const avatar = manifest.meta?.avatar;+ const title = t(`tools.builtins.${identifier}.title` as any, { defaultValue: identifier });++ return createManagedSkillItem({+ extraTag: officialTag,+ icon: avatar ? (+ <Avatar avatar={avatar} shape={'square'} size={SKILL_ICON_SIZE} />+ ) : (+ <Icon icon={SkillsIcon} size={SKILL_ICON_SIZE} />+ ),+ id: identifier,+ modeOverride: resolveCapabilityMode(enabled, checkedSet.has(identifier)),+ panelExtra,+ popoverContent: (+ <ToolItemDetailPopover+ identifier={identifier}+ sourceLabel={t('skillStore.tabs.lobehub')}+ title={title}+ description={t(`tools.builtins.${identifier}.description` as any, {+ defaultValue: '',+ })}+ icon={+ avatar ? (+ <Avatar avatar={avatar} shape={'square'} size={36} />+ ) : (+ <Icon icon={SkillsIcon} size={36} />+ )+ }+ />+ ),+ searchText: `${title} ${identifier}`,+ supportedModes,+ title,+ });+ }),+ [+ checkedSet,+ createManagedSkillItem,+ isMemoryCapabilityEnabled,+ isSearchCapabilityEnabled,+ searchCapabilityModes,+ t,+ ],+ );+// Builtin runtime tools support an explicit pinned/disabled policy. They intentionally// do not support "auto": when enabled, these foundational capabilities stay pinned.const fixedItems = useMemo(@@ -1525,15 +1699,45 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =);};const allPinnedItems = allSkillItems.filter((item) => checkedSet.has(String(item.key)));- const allAutoItems = allSkillItems.filter(+ // Capability rows split on the same two states as every other row: Pinned (the+ // explicit pin, stored in `plugins`) and the on/off half that lives in chatConfig.+ const capabilityPinnedItems = capabilityItems.filter((item) => checkedSet.has(String(item.key)));+ const capabilityAutoItems = capabilityItems.filter(+ (item) => !checkedSet.has(String(item.key)) && !disabledCapabilityIds.has(String(item.key)),+ );+ const capabilityDisabledItems = capabilityItems.filter(+ (item) => !checkedSet.has(String(item.key)) && disabledCapabilityIds.has(String(item.key)),+ );+ // LobeHub's own Agent Skills (Artifacts, β¦) β the rows the capability rows follow.+ const builtinAgentSkillIds = useMemo(+ () => new Set(installedBuiltinSkills.map((skill) => skill.identifier)),+ [installedBuiltinSkills],+ );+ const activeSkillItems = allSkillItems.filter((item) => !checkedSet.has(String(item.key)) && !disabledIdSet.has(String(item.key)),);- const allDisabledItems = allSkillItems.filter((item) => disabledIdSet.has(String(item.key)));+ const isAgentSkillItem = (item: SkillMenuItem) => builtinAgentSkillIds.has(String(item.key));+ // Capability rows sit after LobeHub's Agent Skills and before the remaining+ // integrations, so the group still opens with the skills the user installed.+ const allAutoItems = [+ ...activeSkillItems.filter((item) => isAgentSkillItem(item)),+ ...capabilityAutoItems,+ ...activeSkillItems.filter((item) => !isAgentSkillItem(item)),+ ];+ const allDisabledItems = [+ ...capabilityDisabledItems,+ ...allSkillItems.filter((item) => disabledIdSet.has(String(item.key))),+ ];const fixedPinnedItems = fixedItems.filter((item) => !disabledIdSet.has(String(item.key)));const fixedDisabledItems = fixedItems.filter((item) => disabledIdSet.has(String(item.key)));- // Enabled builtin tools lead the pinned section. All disabled tools and skills live in- // their own section so "Auto" remains semantically accurate.- const pinnedItems = filterBySearch([...fixedPinnedItems, ...allPinnedItems]);+ // Fixed tools lead the pinned section, then pinned capabilities, then every pinned+ // skill. All disabled tools and skills live in their own section so "Auto" remains+ // semantically accurate.+ const pinnedItems = filterBySearch([+ ...fixedPinnedItems,+ ...capabilityPinnedItems,+ ...allPinnedItems,+ ]);const autoItems = filterBySearch(allAutoItems);const disabledItems = filterBySearch([...fixedDisabledItems, ...allDisabledItems]);@@ -1659,7 +1863,7 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =children: pinnedOpen ? pinnedItems : [],key: 'pinned',label: renderActivationGroupLabel({- count: fixedPinnedItems.length + allPinnedItems.length,+ count: fixedPinnedItems.length + capabilityPinnedItems.length + allPinnedItems.length,icon: <Icon icon={Pin} size={14} />,open: pinnedOpen,title: t('tools.activation.pinned'),@@ -2054,6 +2258,6 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =marketFooter,marketHeader,marketItems,- pinnedCount: allPinnedItems.length + fixedPinnedItems.length,+ pinnedCount: allPinnedItems.length + fixedPinnedItems.length + capabilityPinnedItems.length,};};