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): adopt sectioned editor menus (#16471)

Innei99e42327966e
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index cf9695eaac9..dd66a044ab3 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -372,6 +372,7 @@
"memory.on.title": "Enable Memory Tool",
"memory.title": "Memory",
"mention.category.agents": "Agents",
+ "mention.category.files": "Files",
"mention.category.members": "Members",
"mention.category.skills": "Skills",
"mention.category.tools": "Tools",
diff --git a/locales/en-US/editor.json b/locales/en-US/editor.json
index 680ac327e12..3844a519cbf 100644
--- a/locales/en-US/editor.json
+++ b/locales/en-US/editor.json
@@ -58,11 +58,13 @@
"skillFrontmatter.saveFailed": "Metadata was not saved. Retry, or keep editing.",
"skillFrontmatter.title": "Skill metadata",
"slash.compact": "Compact context",
+ "slash.compact.desc": "Compress this conversation's context",
"slash.h1": "Heading 1",
"slash.h2": "Heading 2",
"slash.h3": "Heading 3",
"slash.hr": "Divider",
"slash.newTopic": "Send in new topic",
+ "slash.newTopic.desc": "Start a new topic with this message",
"slash.rewrite": "Rewrite",
"slash.summarize": "Summarize",
"slash.table": "Table",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 68a8c510aff..546cb1cba38 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -372,6 +372,7 @@
"memory.on.title": "启用记忆工具",
"memory.title": "记忆",
"mention.category.agents": "助理",
+ "mention.category.files": "文件",
"mention.category.members": "成员",
"mention.category.skills": "技能",
"mention.category.tools": "工具",
diff --git a/locales/zh-CN/editor.json b/locales/zh-CN/editor.json
index b9c4a226fa8..7871cb7c649 100644
--- a/locales/zh-CN/editor.json
+++ b/locales/zh-CN/editor.json
@@ -58,11 +58,13 @@
"skillFrontmatter.saveFailed": "元信息未保存。请重试,或继续编辑。",
"skillFrontmatter.title": "技能元信息",
"slash.compact": "压缩上下文",
+ "slash.compact.desc": "压缩此会话的上下文",
"slash.h1": "一级标题",
"slash.h2": "二级标题",
"slash.h3": "三级标题",
"slash.hr": "分割线",
"slash.newTopic": "在新话题中发送",
+ "slash.newTopic.desc": "用这条消息开始新话题",
"slash.rewrite": "重写",
"slash.summarize": "总结",
"slash.table": "表格",
diff --git a/package.json b/package.json
index 954b863174e..e152d760622 100644
--- a/package.json
+++ b/package.json
@@ -291,7 +291,7 @@
"@lobehub/analytics": "^1.6.2",
"@lobehub/charts": "^5.0.0",
"@lobehub/desktop-ipc-typings": "workspace:*",
- "@lobehub/editor": "^4.18.1",
+ "@lobehub/editor": "^4.19.1",
"@lobehub/icons": "^5.0.0",
"@lobehub/market-sdk": "0.39.1",
"@lobehub/tts": "^5.1.2",
diff --git a/src/features/ChatInput/InputEditor/ActionTag/types.ts b/src/features/ChatInput/InputEditor/ActionTag/types.ts
index 98265c6ac1a..98132d76f61 100644
--- a/src/features/ChatInput/InputEditor/ActionTag/types.ts
+++ b/src/features/ChatInput/InputEditor/ActionTag/types.ts
@@ -23,6 +23,7 @@ export type ActionTagType = CommandType | SkillType;
export interface ActionTagData {
category: ActionTagCategory;
+ description?: string;
icon?: string;
label: string;
type: ActionTagType;
diff --git a/src/features/ChatInput/InputEditor/ActionTag/useInstalledSkillsAndTools.ts b/src/features/ChatInput/InputEditor/ActionTag/useInstalledSkillsAndTools.ts
index 1f6d91fbd3f..4b2f90b6b93 100644
--- a/src/features/ChatInput/InputEditor/ActionTag/useInstalledSkillsAndTools.ts
+++ b/src/features/ChatInput/InputEditor/ActionTag/useInstalledSkillsAndTools.ts
@@ -29,10 +29,14 @@ export const useInstalledSkillsAndTools = (): ActionTagData[] => {
const items: ActionTagData[] = [];
// --- Build skill set (identifier → { label, icon }) ---
- const skillMap = new Map<string, { icon?: string; label: string }>();
+ const skillMap = new Map<string, { description?: string; icon?: string; label: string }>();
for (const item of builtinSkills) {
- skillMap.set(item.identifier, { icon: item.avatar, label: item.name || item.identifier });
+ skillMap.set(item.identifier, {
+ description: item.description,
+ icon: item.avatar,
+ label: item.title || item.name || item.identifier,
+ });
}
for (const item of lobehubSkillServers) {
if (!skillMap.has(item.identifier)) {
@@ -41,12 +45,18 @@ export const useInstalledSkillsAndTools = (): ActionTagData[] => {
}
for (const item of marketAgentSkills) {
if (!skillMap.has(item.identifier)) {
- skillMap.set(item.identifier, { label: item.name || item.identifier });
+ skillMap.set(item.identifier, {
+ description: item.description || item.manifest?.description,
+ label: item.name || item.identifier,
+ });
}
}
for (const item of userAgentSkills) {
if (!skillMap.has(item.identifier)) {
- skillMap.set(item.identifier, { label: item.name || item.identifier });
+ skillMap.set(item.identifier, {
+ description: item.description || item.manifest?.description,
+ label: item.name || item.identifier,
+ });
}
}
@@ -71,8 +81,8 @@ export const useInstalledSkillsAndTools = (): ActionTagData[] => {
}
// --- Merge into output ---
- for (const [id, { icon, label }] of skillMap) {
- items.push({ category: 'skill', icon, label, type: id });
+ for (const [id, { description, icon, label }] of skillMap) {
+ items.push({ category: 'skill', description, icon, label, type: id });
}
for (const [id, { icon, label }] of toolMap) {
items.push({ category: 'tool', icon, label, type: id });
diff --git a/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts b/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts
index af412627605..82b4af5852b 100644
--- a/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts
+++ b/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts
@@ -112,7 +112,11 @@ export const useSlashActionItems = (): SlashOptions['items'] => {
icon: COMMAND_ICONS[action.type],
key: `action-${action.type}`,
label: t(`slash.${action.type}` as any),
- metadata: { category: action.category, type: action.type },
+ metadata: {
+ category: action.category,
+ description: t(`slash.${action.type}.desc` as any, { defaultValue: '' }),
+ type: action.type,
+ },
onSelect: (editor: IEditor) => {
const payload: InsertActionTagPayload = {
category: action.category,
@@ -148,7 +152,7 @@ export const useSlashActionItems = (): SlashOptions['items'] => {
icon: SkillsIcon,
key: `skill-${skill.type}`,
label: skill.label,
- metadata: { category: 'skill', type: skill.type },
+ metadata: { category: 'skill', description: skill.description, type: skill.type },
onSelect: (editor: IEditor) => {
const payload: InsertActionTagPayload = {
category: 'skill',
@@ -250,7 +254,10 @@ export const useSlashActionItems = (): SlashOptions['items'] => {
// Fuzzy filtering
if (search?.matchingString && search.matchingString.length > 0) {
- const fuse = new Fuse(allItems, { keys: ['key', 'label'], threshold: 0.4 });
+ const fuse = new Fuse(allItems, {
+ keys: ['key', 'label', 'metadata.description'],
+ threshold: 0.4,
+ });
return fuse.search(search.matchingString).map((r) => r.item);
}
diff --git a/src/features/ChatInput/InputEditor/index.test.tsx b/src/features/ChatInput/InputEditor/index.test.tsx
index a6cb067ba32..db75ef5620c 100644
--- a/src/features/ChatInput/InputEditor/index.test.tsx
+++ b/src/features/ChatInput/InputEditor/index.test.tsx
@@ -174,6 +174,7 @@ vi.mock('@/store/user/selectors', () => ({
systemAgentSelectors: {
inputCompletion: () => mocks.inputCompletionConfig,
},
+ userProfileSelectors: { userId: () => 'user-id' },
}));
vi.mock('../hooks/useAgentId', () => ({ useAgentId: () => 'agent-id' }));
diff --git a/src/features/ChatInput/InputEditor/index.tsx b/src/features/ChatInput/InputEditor/index.tsx
index 327fdb1e385..8a19fd21cb5 100644
--- a/src/features/ChatInput/InputEditor/index.tsx
+++ b/src/features/ChatInput/InputEditor/index.tsx
@@ -8,7 +8,7 @@ import {
INPUT_COMPLETION_SCHEMA_NAME,
} from '@lobechat/prompts';
import { isCommandPressed } from '@lobechat/utils';
-import type { IEditor } from '@lobehub/editor';
+import type { IEditor, ISlashMenuOption, ISlashSectionOption } from '@lobehub/editor';
import { INSERT_MENTION_COMMAND, ReactAutoCompletePlugin } from '@lobehub/editor';
import { Editor, useEditorState } from '@lobehub/editor/react';
import { combineKeys } from '@lobehub/ui';
@@ -17,6 +17,7 @@ import Fuse from 'fuse.js';
import { KEY_ESCAPE_COMMAND } from 'lexical';
import { memo, type ReactNode, useCallback, useEffect, useMemo, useRef } from 'react';
import { useHotkeysContext } from 'react-hotkeys-hook';
+import { useTranslation } from 'react-i18next';
import { usePasteFile, useUploadFiles } from '@/components/DragUploadZone';
import { useEnterToSend } from '@/hooks/useEnterToSend';
@@ -60,11 +61,14 @@ const className = cx(
mentionFilledClassName,
);
+type MentionOption = ISlashMenuOption | ISlashSectionOption;
+
const InputEditor = memo<{
defaultRows?: number;
placeholder?: ReactNode;
placeholderVariant?: PlaceholderVariant;
}>(({ defaultRows = 2, placeholder, placeholderVariant }) => {
+ const { t } = useTranslation('chat');
const [
editor,
slashMenuRef,
@@ -128,6 +132,16 @@ const InputEditor = memo<{
const { enableLocalFileMention, searchLocalFiles } = useLocalFileMention();
const allMentionItems = useMemo(() => categories.flatMap((c) => c.items), [categories]);
+ const mentionSections = useMemo<ISlashSectionOption[]>(
+ () =>
+ categories.map((category) => ({
+ items: category.items,
+ key: `mention-section-${category.id}`,
+ label: category.label,
+ type: 'section',
+ })),
+ [categories],
+ );
const fuse = useMemo(
() =>
@@ -148,11 +162,43 @@ const InputEditor = memo<{
Promise.resolve(fuse.search(search.matchingString).map((r) => r.item)),
]);
- return [...localFileItems, ...mentionItems];
+ const rankByKey = new Map(mentionItems.map((item, index) => [String(item.key), index]));
+ const matchedSections = categories
+ .map((category): ISlashSectionOption => {
+ const items = category.items
+ .filter((item) => rankByKey.has(String(item.key)))
+ .sort(
+ (a, b) =>
+ (rankByKey.get(String(a.key)) ?? Number.MAX_SAFE_INTEGER) -
+ (rankByKey.get(String(b.key)) ?? Number.MAX_SAFE_INTEGER),
+ );
+
+ return {
+ items,
+ key: `mention-section-${category.id}`,
+ label: category.label,
+ type: 'section',
+ };
+ })
+ .filter((section) => section.items.length > 0);
+
+ if (localFileItems.length > 0) {
+ return [
+ {
+ items: localFileItems,
+ key: 'mention-section-local-file',
+ label: t('mention.category.files' as any),
+ type: 'section',
+ },
+ ...matchedSections,
+ ] satisfies MentionOption[];
+ }
+
+ return matchedSections;
}
- return [...allMentionItems];
+ return mentionSections;
},
- [allMentionItems, fuse, searchLocalFiles],
+ [categories, fuse, mentionSections, searchLocalFiles, t],
);
const enableMention = isMentionEnabled && (allMentionItems.length > 0 || enableLocalFileMention);
diff --git a/src/features/ChatInput/InputEditor/useMentionCategories.tsx b/src/features/ChatInput/InputEditor/useMentionCategories.tsx
index 06a6dfadbac..d549f5d8bdd 100644
--- a/src/features/ChatInput/InputEditor/useMentionCategories.tsx
+++ b/src/features/ChatInput/InputEditor/useMentionCategories.tsx
@@ -137,6 +137,7 @@ export const useMentionCategories = (): MentionCategory[] => {
metadata: {
actionCategory: item.category,
actionType: item.type,
+ description: item.description,
timestamp: 0,
type: 'skill' as const,
},
@@ -158,6 +159,7 @@ export const useMentionCategories = (): MentionCategory[] => {
metadata: {
actionCategory: item.category,
actionType: item.type,
+ description: item.description,
timestamp: 0,
type: 'tool' as const,
},