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.

✨ feat(chat-input): add installed skills to slash menu with mid-line trigger (#15061)

Inneif8142de9a23f
diff --git a/src/features/ChatInput/InputEditor/ActionTag/ActionTag.tsx b/src/features/ChatInput/InputEditor/ActionTag/ActionTag.tsx
index 9e3d6b4de3f..a1072ed4f90 100644
--- a/src/features/ChatInput/InputEditor/ActionTag/ActionTag.tsx
+++ b/src/features/ChatInput/InputEditor/ActionTag/ActionTag.tsx
@@ -25,7 +25,7 @@ const ActionTag = memo<ActionTagProps>(({ node, editor, label }) => {
}, [editor, onClick]);
return (
- <span ref={spanRef}>
+ <span ref={spanRef} style={{ verticalAlign: -3 }}>
<ActionMention category={node.actionCategory} label={label} />
</span>
);
diff --git a/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts b/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts
index 6857d4b760f..a1c862b1401 100644
--- a/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts
+++ b/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts
@@ -5,7 +5,7 @@ import { SkillsIcon } from '@lobehub/ui/icons';
import Fuse from 'fuse.js';
import { $getSelection, $isRangeSelection } from 'lexical';
import { ArchiveIcon, MessageSquarePlusIcon } from 'lucide-react';
-import { useCallback } from 'react';
+import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useClientDataSWR } from '@/libs/swr';
@@ -19,6 +19,7 @@ import { useAgentId } from '../../hooks/useAgentId';
import { useChatInputStore } from '../../store';
import { INSERT_ACTION_TAG_COMMAND, type InsertActionTagPayload } from './command';
import { type ActionTagData, BUILTIN_COMMANDS } from './types';
+import { useInstalledSkillsAndTools } from './useInstalledSkillsAndTools';
type SlashItem = NonNullable<SlashOptions['items'] extends (infer U)[] ? U : never>;
@@ -60,6 +61,14 @@ export const useSlashActionItems = (): SlashOptions['items'] => {
);
const projectSkills = projectSkillsData?.skills;
+ // Installed skills shared with the @ mention menu (builtin / lobehub / market / user agent skills).
+ // Tools intentionally stay out of slash β€” they remain @-mention only.
+ const installedSkillsAndTools = useInstalledSkillsAndTools();
+ const installedSkills = useMemo(
+ () => installedSkillsAndTools.filter((item) => item.category === 'skill'),
+ [installedSkillsAndTools],
+ );
+
return useCallback(
async (
search: { leadOffset: number; matchingString: string; replaceableString: string } | null,
@@ -102,32 +111,68 @@ export const useSlashActionItems = (): SlashOptions['items'] => {
},
});
- // All action tags are line-start only for now
+ const makeSkillItem = (skill: ActionTagData): SlashMenuOption => ({
+ icon: SkillsIcon,
+ key: `skill-${skill.type}`,
+ label: skill.label,
+ metadata: { category: 'skill', type: skill.type },
+ onSelect: (editor: IEditor) => {
+ const payload: InsertActionTagPayload = {
+ category: 'skill',
+ label: skill.label,
+ type: skill.type,
+ };
+ editor.dispatchCommand(INSERT_ACTION_TAG_COMMAND, payload);
+ },
+ });
+
+ // Trigger position:
+ // - line-start β†’ commands + installed skills + project skills
+ // - mid-line w/ preceding whitespace β†’ installed skills + project skills only (no commands)
+ // - otherwise (e.g. inside http://, a/b) β†’ menu suppressed
let isAtLineStart = search === null;
+ let isMidLineAfterWhitespace = false;
if (!isAtLineStart && editorInstance) {
const lexicalEditor = editorInstance.getLexicalEditor();
if (lexicalEditor) {
lexicalEditor.getEditorState().read(() => {
const selection = $getSelection();
- if ($isRangeSelection(selection)) {
- const node = selection.anchor.getNode();
- const topElement = node.getTopLevelElement();
- if (topElement) {
- const paragraphText = topElement.getTextContent();
- const triggerAndSearch = '/' + (search?.matchingString || '');
- isAtLineStart = paragraphText === triggerAndSearch;
- }
+ if (!$isRangeSelection(selection)) return;
+ const node = selection.anchor.getNode();
+ const topElement = node.getTopLevelElement();
+ if (!topElement) return;
+
+ const paragraphText = topElement.getTextContent();
+ const triggerAndSearch = '/' + (search?.matchingString || '');
+
+ if (paragraphText === triggerAndSearch) {
+ isAtLineStart = true;
+ return;
+ }
+
+ const triggerIndex = paragraphText.lastIndexOf(triggerAndSearch);
+ if (triggerIndex === 0) {
+ isAtLineStart = true;
+ } else if (triggerIndex > 0 && /\s/.test(paragraphText[triggerIndex - 1])) {
+ isMidLineAfterWhitespace = true;
}
});
}
}
- if (!isAtLineStart) return [];
+ if (!isAtLineStart && !isMidLineAfterWhitespace) return [];
+
+ // Built-in commands β€” line-start only
+ if (isAtLineStart) {
+ for (const action of BUILTIN_COMMANDS) {
+ if (action.type === 'newTopic' && !activeTopicId) continue;
+ allItems.push(makeCommandItem(action) as SlashItem);
+ }
+ }
- // Built-in commands (filter newTopic when no active topic)
- for (const action of BUILTIN_COMMANDS) {
- if (action.type === 'newTopic' && !activeTopicId) continue;
- allItems.push(makeCommandItem(action) as SlashItem);
+ // Installed skills β€” shown in both positions
+ for (const skill of installedSkills) {
+ allItems.push(makeSkillItem(skill) as SlashItem);
}
// Hetero-agent project skills (file-system based, resolved by the CLI agent itself)
@@ -145,6 +190,6 @@ export const useSlashActionItems = (): SlashOptions['items'] => {
return allItems;
},
- [t, editorInstance, activeTopicId, projectSkills],
+ [t, editorInstance, activeTopicId, projectSkills, installedSkills],
);
};