Skip to content

🤯 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.

♻️ refactor(skills): manage sidebar skills in agent settings (#23405)

AmAzing-e25b0e967a30
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 69e3839ab8e..42174bc95bc 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -3997,15 +3997,8 @@
"workingPanel.skills.convert.titlePlaceholder": "e.g. Weekly Report",
"workingPanel.skills.detail.title": "Skill details",
"workingPanel.skills.empty": "No skills available",
- "workingPanel.skills.manage.noPermission": "You do not have permission to change skills for this agent.",
- "workingPanel.skills.manage.noneEnabled": "No skills selected. Use the settings icon to choose skills.",
- "workingPanel.skills.manage.save": "Save",
- "workingPanel.skills.manage.saveFailed": "Could not save changes. Your selections are kept; try saving again.",
- "workingPanel.skills.manage.selectResults": "Select all results ({{count}})",
- "workingPanel.skills.manage.selected": "Selected skills: {{count}}",
- "workingPanel.skills.manage.title": "Choose the skills this agent can use",
- "workingPanel.skills.manage.unsaved": "Unsaved changes",
- "workingPanel.skills.manualOnly": "Manual only",
+ "workingPanel.skills.manage.noneEnabled": "No user skills enabled.",
+ "workingPanel.skills.manage.title": "Open agent skill settings",
"workingPanel.skills.noSearchResults": "No matching skills",
"workingPanel.skills.searchPlaceholder": "Filter skills...",
"workingPanel.skills.section.agent": "Agent skills",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 9e8d8f48f70..20f3a7be9a0 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -3997,15 +3997,8 @@
"workingPanel.skills.convert.titlePlaceholder": "例如 周报",
"workingPanel.skills.detail.title": "技能详情",
"workingPanel.skills.empty": "暂无可用技能",
- "workingPanel.skills.manage.noPermission": "你没有修改此助理技能的权限。",
- "workingPanel.skills.manage.noneEnabled": "暂无已选技能,点击设置图标进行选择。",
- "workingPanel.skills.manage.save": "保存",
- "workingPanel.skills.manage.saveFailed": "保存失败,已保留选择,请重试保存。",
- "workingPanel.skills.manage.selectResults": "全选搜索结果({{count}} 项)",
- "workingPanel.skills.manage.selected": "已选 {{count}} 个技能",
- "workingPanel.skills.manage.title": "选择当前助理可以使用的技能",
- "workingPanel.skills.manage.unsaved": "尚未保存",
- "workingPanel.skills.manualOnly": "仅手动",
+ "workingPanel.skills.manage.noneEnabled": "暂无已启用的用户技能。",
+ "workingPanel.skills.manage.title": "打开助理技能设置",
"workingPanel.skills.noSearchResults": "没有匹配的技能",
"workingPanel.skills.searchPlaceholder": "筛选技能...",
"workingPanel.skills.section.agent": "智能体技能",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index 32b239da5b7..d4eb8a27cf5 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -4208,24 +4208,14 @@ export default {
'workingPanel.skills.convert.titlePlaceholder': 'e.g. Weekly Report',
'workingPanel.skills.detail.title': 'Skill details',
'workingPanel.skills.empty': 'No skills available',
- 'workingPanel.skills.manualOnly': 'Manual only',
'workingPanel.skills.noSearchResults': 'No matching skills',
'workingPanel.skills.searchPlaceholder': 'Filter skills...',
'workingPanel.skills.section.agent': 'Agent skills',
'workingPanel.skills.section.device': 'Device skills',
'workingPanel.skills.section.project': 'Project skills',
'workingPanel.skills.section.user': 'User skills',
- 'workingPanel.skills.manage.noneEnabled':
- 'No skills selected. Use the settings icon to choose skills.',
- 'workingPanel.skills.manage.noPermission':
- 'You do not have permission to change skills for this agent.',
- 'workingPanel.skills.manage.save': 'Save',
- 'workingPanel.skills.manage.saveFailed':
- 'Could not save changes. Your selections are kept; try saving again.',
- 'workingPanel.skills.manage.selected': 'Selected skills: {{count}}',
- 'workingPanel.skills.manage.selectResults': 'Select all results ({{count}})',
- 'workingPanel.skills.manage.title': 'Choose the skills this agent can use',
- 'workingPanel.skills.manage.unsaved': 'Unsaved changes',
+ 'workingPanel.skills.manage.noneEnabled': 'No user skills enabled.',
+ 'workingPanel.skills.manage.title': 'Open agent skill settings',
'workingPanel.skills.title': 'Skills',
'workingPanel.files.openNeedsTopic':
'Send a message first — this environment’s files open once the conversation has a session.',
diff --git a/src/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.test.tsx b/src/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.test.tsx
index e5f5cc8fdc3..2a08f812772 100644
--- a/src/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.test.tsx
+++ b/src/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.test.tsx
@@ -153,11 +153,6 @@ vi.mock('@/store/tool/selectors', () => ({
})),
},
}));
-vi.mock('./UserSkillsManagement', () => ({
- UserSkillsManagement: ({ onClose }: { onClose: () => void }) => (
- <button onClick={onClose}>Cancel skill changes</button>
- ),
-}));
vi.mock('@/features/ChatInput/InputEditor/ActionTag/skillDragData', () => ({
startSkillDrag: () => undefined,
}));
@@ -324,17 +319,14 @@ describe('AgentDocumentsGroup', () => {
userSkillInventory.canManage = true;
});
- it('keeps management reachable with every user skill disabled and returns after cancelling', () => {
+ it('opens the agent skills settings even when every user skill is disabled', () => {
documentListMock.mockReturnValue({ data: [] });
userSkillInventory.items = [{ id: 'disabled-skill', name: 'Disabled skill' }];
render(<AgentDocumentsGroup />);
fireEvent.click(screen.getByRole('button', { name: 'Manage user skills' }));
- expect(
- screen.queryByPlaceholderText('workingPanel.skills.searchPlaceholder'),
- ).not.toBeInTheDocument();
- fireEvent.click(screen.getByRole('button', { name: 'Cancel skill changes' }));
- expect(screen.getByRole('button', { name: 'Manage user skills' })).toBeInTheDocument();
+ expect(navigateMock).toHaveBeenCalledWith('/agent/agent-1/skills');
+ expect(screen.queryByText('Disabled skill')).not.toBeInTheDocument();
});
it('keeps the user skills collapsible with an independently clickable settings action', () => {
@@ -354,7 +346,7 @@ describe('AgentDocumentsGroup', () => {
expect(header).toHaveAttribute('aria-expanded', 'true');
fireEvent.click(header);
fireEvent.click(settings);
- expect(screen.getByRole('button', { name: 'Cancel skill changes' })).toBeInTheDocument();
+ expect(navigateMock).toHaveBeenCalledWith('/agent/agent-1/skills');
});
it('does not offer management to a read-only viewer', () => {
diff --git a/src/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.tsx b/src/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.tsx
index 9cd97c7ee34..462fdd15600 100644
--- a/src/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.tsx
+++ b/src/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.tsx
@@ -24,6 +24,7 @@ import {
type AgentDocumentListMutator,
DocumentExplorerTree,
} from '@/features/AgentDocumentsExplorer';
+import { buildAgentProfileTabPath } from '@/features/AgentProfileTabs/tabOptions';
import { startSkillDrag } from '@/features/ChatInput/InputEditor/ActionTag/skillDragData';
import { startDocumentDrag } from '@/features/ChatInput/InputEditor/ReferDocument/documentDragData';
import {
@@ -50,7 +51,6 @@ import DeviceLevelSkills from './DeviceLevelSkills';
import ProjectLevelSkills from './ProjectLevelSkills';
import { useCanManageUserSkills } from './useCanManageUserSkills';
import UserLevelSkills, { useUserSkills } from './UserLevelSkills';
-import { UserSkillsManagement } from './UserSkillsManagement';
import { useSelectSkill } from './useSelectSkill';
dayjs.extend(relativeTime);
@@ -305,7 +305,6 @@ const AgentDocumentsGroup = memo<AgentDocumentsGroupProps>(
isDocumentMode ? 'documents' : 'skills',
);
const [skillSearchQuery, setSkillSearchQuery] = useState('');
- const [managingSkillsFor, setManagingSkillsFor] = useState<string>();
const activeDocumentIdentifier = docId ? standardizeIdentifier(docId) : undefined;
const filterOptions = isDocumentMode ? DOCUMENT_MODE_FILTER_OPTIONS : FILTER_OPTIONS;
const resolvedFilter = controlledFilter ?? filter;
@@ -493,19 +492,6 @@ const AgentDocumentsGroup = memo<AgentDocumentsGroupProps>(
);
const renderSkills = () => {
- if (agentId && managingSkillsFor === agentId) {
- return (
- <UserSkillsManagement
- agentId={agentId}
- items={userSkillItems}
- key={agentId}
- onClose={() =>
- setManagingSkillsFor((current) => (current === agentId ? undefined : current))
- }
- />
- );
- }
-
// This is an invocation picker for agent/project/device/user skills, not a
// full capability inventory. Builtin bundles intentionally keep their existing
// slash/profile entry points instead of being copied into this sidebar.
@@ -598,7 +584,11 @@ const AgentDocumentsGroup = memo<AgentDocumentsGroupProps>(
<UserLevelSkills
hideHeader={flat}
searchQuery={skillSearchQuery}
- onManage={canManageSkills ? () => setManagingSkillsFor(agentId) : undefined}
+ onManage={
+ canManageSkills
+ ? () => navigate(buildAgentProfileTabPath(agentId, 'skills'))
+ : undefined
+ }
/>
)}
</Flexbox>
diff --git a/src/features/Conversation/WorkingSidebar/ResourcesSection/UserSkillsManagement.tsx b/src/features/Conversation/WorkingSidebar/ResourcesSection/UserSkillsManagement.tsx
deleted file mode 100644
index c59d15afa28..00000000000
--- a/src/features/Conversation/WorkingSidebar/ResourcesSection/UserSkillsManagement.tsx
+++ /dev/null
@@ -1,138 +0,0 @@
-import { Alert, Button, Checkbox, Flexbox, Icon, Text } from '@lobehub/ui';
-import { SkillsIcon } from '@lobehub/ui/icons';
-import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
-import * as stylex from '@stylexjs/stylex';
-import { useTranslation } from 'react-i18next';
-import { Virtuoso } from 'react-virtuoso';
-
-import AsyncError from '@/components/AsyncError';
-import { type SkillListItem, SkillsSearchBar } from '@/features/SkillsList';
-import { normalizeAsyncError } from '@/libs/swr/normalizeError';
-
-import { useCanManageUserSkills } from './useCanManageUserSkills';
-import { useUserSkillsManagement } from './useUserSkillsManagement';
-
-const SKILL_ROW_HEIGHT = 36;
-
-const styles = stylex.create({
- row: {
- display: 'flex',
- boxSizing: 'border-box',
- height: SKILL_ROW_HEIGHT,
- width: '100%',
- minWidth: 0,
- paddingBlock: '8px',
- paddingInline: '4px',
- borderRadius: '6px',
- backgroundColor: { 'default': 'transparent', ':hover': cssVar.colorFillTertiary },
- },
- rowText: { flex: '1', minWidth: 0 },
- footer: {
- paddingBlock: '12px',
- borderBlockStartWidth: '1px',
- borderBlockStartStyle: 'solid',
- borderBlockStartColor: cssVar.colorSplit,
- },
-});
-
-interface UserSkillsManagementProps {
- agentId: string;
- items: SkillListItem[];
- onClose: () => void;
-}
-
-export const UserSkillsManagement = ({ agentId, items, onClose }: UserSkillsManagementProps) => {
- const { t } = useTranslation(['chat', 'common']);
- const canEdit = useCanManageUserSkills(agentId);
- const selection = useUserSkillsManagement(agentId, items, canEdit);
- const selectedResults = selection.filteredItems.filter(({ id }) =>
- selection.isSelected(id),
- ).length;
- const disabled = !canEdit || selection.saving;
-
- return (
- <Flexbox gap={12}>
- <Text weight={500}>{t('workingPanel.skills.manage.title')}</Text>
- <SkillsSearchBar onSearch={selection.setQuery} />
- <Checkbox
- disabled={disabled || selection.filteredItems.length === 0}
- indeterminate={selectedResults > 0 && selectedResults < selection.filteredItems.length}
- checked={
- selection.filteredItems.length > 0 && selectedResults === selection.filteredItems.length
- }
- onChange={(checked) =>
- selection.setSelected(
- selection.filteredItems.map(({ id }) => id),
- checked,
- )
- }
- >
- {t('workingPanel.skills.manage.selectResults', { count: selection.filteredItems.length })}
- </Checkbox>
- {selection.filteredItems.length === 0 ? (
- <Text type="secondary">{t('workingPanel.skills.noSearchResults')}</Text>
- ) : (
- <Virtuoso
- computeItemKey={(_, item) => item.id}
- data={selection.filteredItems}
- fixedItemHeight={SKILL_ROW_HEIGHT}
- itemContent={(_, item) => (
- <Checkbox
- aria-label={item.name}
- checked={selection.isSelected(item.id)}
- disabled={disabled}
- classNames={{
- text: stylex.props(styles.rowText).className,
- wrapper: stylex.props(styles.row).className,
- }}
- onChange={(checked) => selection.setSelected([item.id], checked)}
- >
- <Flexbox horizontal align="center" gap={8} style={{ minWidth: 0 }}>
- <Icon icon={SkillsIcon} size={16} />
- <Text ellipsis fontSize={13} title={item.name}>
- {item.name}
- </Text>
- </Flexbox>
- </Checkbox>
- )}
- style={{
- height: Math.min(selection.filteredItems.length * SKILL_ROW_HEIGHT, 360),
- maxHeight: '45vh',
- }}
- />
- )}
- {!canEdit && <Alert title={t('workingPanel.skills.manage.noPermission')} type="warning" />}
- {selection.saveFailure && (
- <AsyncError
- align="start"
- details={normalizeAsyncError(selection.saveFailure.error).rawMessage}
- error={selection.saveFailure.error}
- title={t('workingPanel.skills.manage.saveFailed')}
- variant="inline"
- />
- )}
- <Flexbox gap={8} {...stylex.props(styles.footer)}>
- <Text fontSize={12} type="secondary">
- {t('workingPanel.skills.manage.selected', { count: selection.selectedCount })}
- {selection.dirty && ` · ${t('workingPanel.skills.manage.unsaved')}`}
- </Text>
- <Flexbox horizontal gap={8} justify="flex-end">
- <Button disabled={selection.saving} size="small" onClick={onClose}>
- {t('cancel', { ns: 'common' })}
- </Button>
- <Button
- disabled={disabled || !selection.dirty}
- loading={selection.saving}
- size="small"
- type="primary"
- onClick={async () => {
- if (await selection.save()) onClose();
- }}
- >
- {t('workingPanel.skills.manage.save')}
- </Button>
- </Flexbox>
- </Flexbox>
- </Flexbox>
- );
-};
diff --git a/src/features/Conversation/WorkingSidebar/ResourcesSection/useUserSkillsManagement.test.ts b/src/features/Conversation/WorkingSidebar/ResourcesSection/useUserSkillsManagement.test.ts
deleted file mode 100644
index 519e9ee94a9..00000000000
--- a/src/features/Conversation/WorkingSidebar/ResourcesSection/useUserSkillsManagement.test.ts
+++ /dev/null
@@ -1,228 +0,0 @@
-import { type AgentPluginEntry } from '@lobechat/types';
-import { act, renderHook } from '@testing-library/react';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
-
-import { applyUserSkillChanges, useUserSkillsManagement } from './useUserSkillsManagement';
-
-const mocks = vi.hoisted(() => ({
- agents: {} as Record<string, { plugins: AgentPluginEntry[] }>,
- refresh: vi.fn(),
- update: vi.fn(),
-}));
-
-vi.mock('@/store/agent', () => ({
- useAgentStore: {
- getState: () => ({
- agentMap: mocks.agents,
- internal_refreshAgentConfig: mocks.refresh,
- updateAgentConfigById: mocks.update,
- }),
- },
-}));
-vi.mock('@/store/agent/selectors', () => ({
- agentByIdSelectors: {
- getAgentConfigById: (id: string) => (state: { agentMap: typeof mocks.agents }) =>
- state.agentMap[id],
- },
-}));
-
-const items = [
- { id: 'writing', name: 'Writing' },
- { id: 'analysis', name: 'Analysis', description: 'Spreadsheets' },
- { id: 'review', name: 'Review' },
-];
-
-beforeEach(() => {
- mocks.agents = {
- 'agent-a': { plugins: ['writing', { identifier: 'analysis', mode: 'auto' }, 'mcp-tool'] },
- 'agent-b': { plugins: [] },
- };
- mocks.update.mockReset().mockResolvedValue(undefined);
- mocks.refresh.mockReset().mockResolvedValue(undefined);
-});
-
-describe('applyUserSkillChanges', () => {
- it('preserves untouched legacy entries, auto mode, tools, and builtin skills', () => {
- const plugins: AgentPluginEntry[] = [
- 'writing',
- { identifier: 'analysis', mode: 'auto' },
- 'mcp-tool',
- 'lobehub',
- ];
- expect(applyUserSkillChanges(plugins, { review: true, writing: false })).toEqual([
- { identifier: 'analysis', mode: 'auto' },
- 'mcp-tool',
- 'lobehub',
- { identifier: 'review', mode: 'pinned' },
- ]);
- expect(plugins[0]).toBe('writing');
- });
-
- it('does not turn an already enabled auto skill into pinned', () => {
- const plugins: AgentPluginEntry[] = [{ identifier: 'analysis', mode: 'auto' }];
- expect(applyUserSkillChanges(plugins, { analysis: true })).toBe(plugins);
- });
-
- it('persists a newly enabled skill explicitly and removes disabled opt-in skills', () => {
- expect(applyUserSkillChanges(undefined, { review: true })).toEqual([
- { identifier: 'review', mode: 'pinned' },
- ]);
- expect(applyUserSkillChanges(['review'], { review: false })).toEqual([]);
- });
-});
-
-describe('useUserSkillsManagement', () => {
- it('keeps edits local and discards them on cancel/unmount', () => {
- const { result, unmount } = renderHook(() => useUserSkillsManagement('agent-a', items, true));
- expect(result.current.selectedCount).toBe(2);
- act(() => result.current.setSelected(['review'], true));
- expect(result.current.selectedCount).toBe(3);
- expect(result.current.dirty).toBe(true);
- unmount();
- expect(mocks.update).not.toHaveBeenCalled();
- expect(mocks.agents['agent-a'].plugins).not.toContain('review');
- });
-
- it('keeps checked and unchecked skills visible and preserves selections across search', () => {
- const { result } = renderHook(() => useUserSkillsManagement('agent-a', items, true));
- expect(result.current.filteredItems).toEqual(items);
- act(() => result.current.setSelected(['review'], true));
- act(() => result.current.setSelected(['writing'], false));
- expect(result.current.filteredItems).toEqual(items);
- act(() => result.current.setQuery('spreadsheets'));
- expect(result.current.filteredItems.map(({ id }) => id)).toEqual(['analysis']);
- act(() => result.current.setQuery(''));
- expect(result.current.filteredItems).toEqual(items);
- expect(result.current.isSelected('review')).toBe(true);
- expect(result.current.isSelected('writing')).toBe(false);
- });
-
- it('applies bulk selection only to the matching results', () => {
- const { result } = renderHook(() => useUserSkillsManagement('agent-a', items, true));
- act(() => result.current.setQuery('writing'));
- act(() =>
- result.current.setSelected(
- result.current.filteredItems.map(({ id }) => id),
- false,
- ),
- );
- expect(result.current.isSelected('writing')).toBe(false);
- expect(result.current.isSelected('analysis')).toBe(true);
- expect(result.current.isSelected('review')).toBe(false);
- });
-
- it('saves one patch to the bound agent, merging only edited skills into the latest config', async () => {
- const { result } = renderHook(() => useUserSkillsManagement('agent-a', items, true));
- act(() => result.current.setSelected(['review'], true));
- mocks.agents['agent-a'].plugins.push('new-connector');
- await act(async () => {
- expect(await result.current.save()).toBe(true);
- });
- expect(mocks.update).toHaveBeenCalledExactlyOnceWith(
- 'agent-a',
- {
- plugins: [
- 'writing',
- { identifier: 'analysis', mode: 'auto' },
- 'mcp-tool',
- 'new-connector',
- { identifier: 'review', mode: 'pinned' },
- ],
- },
- { rethrow: true, showErrorMessage: false },
- );
- expect(mocks.agents['agent-b'].plugins).toEqual([]);
- });
-
- it('does not change modes when a selection is toggled off and back on', async () => {
- const { result } = renderHook(() => useUserSkillsManagement('agent-a', items, true));
- act(() => result.current.setSelected(['analysis'], false));
- act(() => result.current.setSelected(['analysis'], true));
- expect(result.current.dirty).toBe(false);
- await act(async () => {
- await result.current.save();
- });
- expect(mocks.update).not.toHaveBeenCalled();
- });
-
- it('prevents edits and writes without permission', async () => {
- const { result } = renderHook(() => useUserSkillsManagement('agent-a', items, false));
- act(() => result.current.setSelected(['review'], true));
- expect(result.current.dirty).toBe(false);
- await act(async () => {
- expect(await result.current.save()).toBe(false);
- });
- expect(mocks.update).not.toHaveBeenCalled();
- });
-
- it('locks edits and duplicate submissions while saving', async () => {
- const deferred = Promise.withResolvers<void>();
- mocks.update.mockReturnValueOnce(deferred.promise);
- const { result } = renderHook(() => useUserSkillsManagement('agent-a', items, true));
- act(() => result.current.setSelected(['review'], true));
- let pending = Promise.resolve(false);
- act(() => {
- pending = result.current.save();
- });
- expect(result.current.saving).toBe(true);
- act(() => result.current.setSelected(['writing'], false));
- expect(result.current.isSelected('writing')).toBe(true);
- expect(await result.current.save()).toBe(false);
- await act(async () => {
- deferred.resolve();
- await pending;
- });
- expect(result.current.saving).toBe(false);
- expect(mocks.update).toHaveBeenCalledOnce();
- });
-
- it.each([
- new Error('Network error'),
- { message: 'Forbidden', data: { httpStatus: 403 } },
- undefined,
- ])('retains the draft and failure details, then permits retry: %j', async (error) => {
- mocks.update.mockRejectedValueOnce(error);
- const { result } = renderHook(() => useUserSkillsManagement('agent-a', items, true));
- act(() => result.current.setSelected(['review'], true));
- await act(async () => {
- expect(await result.current.save()).toBe(false);
- });
- expect(result.current.saveFailure).toEqual({ error });
- expect(result.current.saving).toBe(false);
- expect(result.current.isSelected('review')).toBe(true);
- expect(result.current.dirty).toBe(true);
- expect(mocks.refresh).toHaveBeenCalledWith('agent-a');
- await act(async () => {
- expect(await result.current.save()).toBe(true);
- });
- expect(result.current.saveFailure).toBeUndefined();
- });
-
- it('keeps the original save failure when refreshing confirmed config also fails', async () => {
- const error = new Error('Save failed');
- mocks.update.mockRejectedValueOnce(error);
- mocks.refresh.mockRejectedValueOnce(new Error('Refresh failed'));
- const { result } = renderHook(() => useUserSkillsManagement('agent-a', items, true));
- act(() => result.current.setSelected(['review'], true));
- await act(async () => {
- expect(await result.current.save()).toBe(false);
- });
- expect(result.current.saveFailure?.error).toBe(error);
- expect(result.current.saving).toBe(false);
- expect(result.current.isSelected('review')).toBe(true);
- });
-
- it('does not re-enable a skill uninstalled while the editor is open', async () => {
- const { result, rerender } = renderHook(
- ({ inventory }) => useUserSkillsManagement('agent-a', inventory, true),
- { initialProps: { inventory: items } },
- );
- act(() => result.current.setSelected(['review'], true));
- rerender({ inventory: items.filter(({ id }) => id !== 'review') });
- expect(result.current.dirty).toBe(false);
- await act(async () => {
- await result.current.save();
- });
- expect(mocks.update).not.toHaveBeenCalled();
- });
-});
diff --git a/src/features/Conversation/WorkingSidebar/ResourcesSection/useUserSkillsManagement.ts b/src/features/Conversation/WorkingSidebar/ResourcesSection/useUserSkillsManagement.ts
deleted file mode 100644
index 4a7933bf2bd..00000000000
--- a/src/features/Conversation/WorkingSidebar/ResourcesSection/useUserSkillsManagement.ts
+++ /dev/null
@@ -1,108 +0,0 @@
-import {
- type AgentPluginEntry,
- getLibrarySkillMode,
- LIBRARY_SKILL_IMPLICIT_MODE,
- upsertPluginMode,
-} from '@lobechat/types';
-import { useRef, useState } from 'react';
-
-import { filterSkillItems, type SkillListItem } from '@/features/SkillsList';
-import { useAgentStore } from '@/store/agent';
-import { agentByIdSelectors } from '@/store/agent/selectors';
-
-/** Apply only edited skills to the latest config, preserving tools and untouched modes. */
-export const applyUserSkillChanges = (
- plugins: AgentPluginEntry[] | undefined,
- changes: Record<string, boolean>,
-): AgentPluginEntry[] => {
- let next = plugins ?? [];
- for (const [id, enabled] of Object.entries(changes)) {
- if ((getLibrarySkillMode(next, id) !== 'disabled') === enabled) continue;
- next = upsertPluginMode(next, id, enabled ? 'pinned' : 'disabled', LIBRARY_SKILL_IMPLICIT_MODE);
- }
- return next;
-};
-
-export const useUserSkillsManagement = (
- agentId: string,
- items: SkillListItem[],
- canEdit: boolean,
-) => {
- const [baseline] = useState(() => {
- const plugins = agentByIdSelectors.getAgentConfigById(agentId)(
- useAgentStore.getState(),
- )?.plugins;
- return Object.fromEntries(
- items.map(({ id }) => [id, getLibrarySkillMode(plugins, id) !== 'disabled']),
- );
- });
- const [changes, setChanges] = useState<Record<string, boolean>>({});
- const [query, setQuery] = useState('');
- const [saving, setSaving] = useState(false);
- const [saveFailure, setSaveFailure] = useState<{ error: unknown }>();
- const savingRef = useRef(false);
- const isSelected = (id: string) => changes[id] ?? baseline[id] ?? false;
- const filteredItems = filterSkillItems(items, query);
- const installedIds = new Set(items.map(({ id }) => id));
- const pendingChanges = Object.fromEntries(
- Object.entries(changes).filter(([id]) => installedIds.has(id)),
- );
-
- const setSelected = (ids: string[], selected: boolean) => {
- if (!canEdit || savingRef.current) return;
- setChanges((current) => {
- const next = { ...current };
- for (const id of ids) {
- if (!installedIds.has(id)) continue;
- if (selected === Boolean(baseline[id])) delete next[id];
- else next[id] = selected;
- }
- return next;
- });
- };
-
- const save = async () => {
- if (!canEdit || !agentId || savingRef.current) return false;
- if (Object.keys(pendingChanges).length === 0) return true;
- const state = useAgentStore.getState();
- const config = agentByIdSelectors.getAgentConfigById(agentId)(state);
- if (!config) return false;
- savingRef.current = true;
- setSaving(true);
- setSaveFailure(undefined);
- try {
- await state.updateAgentConfigById(
- agentId,
- { plugins: applyUserSkillChanges(config.plugins, pendingChanges) },
- { rethrow: true, showErrorMessage: false },
- );
- return true;
- } catch (error) {
- setSaveFailure({ error });
- // Config writes are optimistic. Restore the confirmed config after failure,
- // while keeping this editor's draft intact for Retry or Cancel.
- try {
- await useAgentStore.getState().internal_refreshAgentConfig(agentId);
- } catch {
- // The inline save error stays visible even if the refresh also fails.
- }
- return false;
- } finally {
- savingRef.current = false;
- setSaving(false);
- }
- };
-
- return {
- dirty: Object.keys(pendingChanges).length > 0,
- filteredItems,
- isSelected,
- query,
- save,
- saveFailure,
- saving,
- selectedCount: items.filter(({ id }) => isSelected(id)).length,
- setQuery,
- setSelected,
- };
-};
diff --git a/src/features/SkillsList/SkillsList.tsx b/src/features/SkillsList/SkillsList.tsx
index 33cc2813936..5c9cea59e0c 100644
--- a/src/features/SkillsList/SkillsList.tsx
+++ b/src/features/SkillsList/SkillsList.tsx
@@ -1,15 +1,12 @@
import { EMPTY_ARRAY } from '@lobechat/const';
-import { createStaticStyles, Flexbox, Icon, Tag, Text, Tooltip } from '@lobehub/ui';
+import { createStaticStyles, Flexbox, Icon, Text, Tooltip } from '@lobehub/ui';
import { SkillsIcon } from '@lobehub/ui/icons';
import { ChevronRightIcon, FileIcon, FolderIcon } from 'lucide-react';
import type React from 'react';
import { memo, useCallback, useMemo, useState } from 'react';
-import { useTranslation } from 'react-i18next';
export interface SkillListItem {
description?: string;
- /** Manual invocation only, as declared by the skill; not a disabled state. */
- disableModelInvocation?: boolean;
/**
* Optional file tree for skills that bundle markdown/script assets. When
* empty or omitted the row stays atomic (no chevron, no expansion).
@@ -239,7 +236,6 @@ const SkillRow = memo<SkillRowProps>(
onToggle,
reserveChevronSlot,
}) => {
- const { t } = useTranslation('chat');
const activateSkill = onSelectSkill ?? onOpenSkill;
const files = onSelectSkill ? EMPTY_ARRAY : (item.files ?? EMPTY_ARRAY);
const hasFiles = files.length > 0;
@@ -315,11 +311,6 @@ const SkillRow = memo<SkillRowProps>(
) : (
nameNode
)}
- {item.disableModelInvocation && (
- <Tag size={'small'} style={{ flexShrink: 0 }}>
- {t('workingPanel.skills.manualOnly')}
- </Tag>
- )}
</Flexbox>
);
diff --git a/src/features/SkillsList/useProjectSkills.test.ts b/src/features/SkillsList/useProjectSkills.test.ts
index c13d71fe790..5f0f5df9d3e 100644
--- a/src/features/SkillsList/useProjectSkills.test.ts
+++ b/src/features/SkillsList/useProjectSkills.test.ts
@@ -82,7 +82,6 @@ describe('useProjectSkills after a reload', () => {
const initialScan = scan('alpha', 'beta');
initialScan.skills[0].disableModelInvocation = true;
initialScan.skills[1].scope = 'device';
- initialScan.skills[1].disableModelInvocation = false;
listProjectSkills().mockResolvedValue(initialScan);
const first = renderHook(() => useProjectSkills('/repo'), { wrapper });
await waitFor(() =>
@@ -105,12 +104,9 @@ describe('useProjectSkills after a reload', () => {
expect(reloaded.result.current.items.map((i) => i.name)).toEqual(['alpha', 'beta']),
);
expect(reloaded.result.current.isLoading).toBe(false);
- expect(reloaded.result.current.projectItems).toMatchObject([
- { disableModelInvocation: true, name: 'alpha' },
- ]);
- expect(reloaded.result.current.deviceItems).toMatchObject([
- { disableModelInvocation: false, name: 'beta' },
- ]);
+ expect(reloaded.result.current.projectItems).toMatchObject([{ name: 'alpha' }]);
+ expect(reloaded.result.current.projectItems[0]).not.toHaveProperty('disableModelInvocation');
+ expect(reloaded.result.current.deviceItems).toMatchObject([{ name: 'beta' }]);
await act(async () => release(scan('alpha', 'beta', 'gamma')));
await waitFor(() =>
diff --git a/src/features/SkillsList/useProjectSkills.ts b/src/features/SkillsList/useProjectSkills.ts
index 5a728cadff6..e43a8b99330 100644
--- a/src/features/SkillsList/useProjectSkills.ts
+++ b/src/features/SkillsList/useProjectSkills.ts
@@ -60,7 +60,6 @@ export const useProjectSkills = (
() =>
(data?.skills ?? []).map((skill) => ({
description: skill.description,
- disableModelInvocation: skill.disableModelInvocation,
files: skill.files,
id: skill.skillDir,
name: skill.name,