🤯 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: Improve CMDK (#11229)
René Wange08c8109bbce
diff --git a/src/app/[variants]/(main)/image/features/PromptInput/index.tsx b/src/app/[variants]/(main)/image/features/PromptInput/index.tsxindex 5f68a742f0f..bc2cd7c17d8 100644--- a/src/app/[variants]/(main)/image/features/PromptInput/index.tsx+++ b/src/app/[variants]/(main)/image/features/PromptInput/index.tsx@@ -5,11 +5,13 @@ import { Button, Flexbox, TextArea } from '@lobehub/ui';import { createStaticStyles, cx } from 'antd-style';import { Sparkles } from 'lucide-react';import type { KeyboardEvent } from 'react';+import { useEffect, useRef } from 'react';import { useTranslation } from 'react-i18next';import { loginRequired } from '@/components/Error/loginRequiredNotification';import { useGeminiChineseWarning } from '@/hooks/useGeminiChineseWarning';import { useIsDark } from '@/hooks/useIsDark';+import { useQueryState } from '@/hooks/useQueryParam';import { useImageStore } from '@/store/image';import { createImageSelectors } from '@/store/image/selectors';import { useGenerationConfigParam } from '@/store/image/slices/generationConfig/hooks';@@ -49,6 +51,10 @@ const PromptInput = ({ showTitle = false }: PromptInputProps) => {const isLogin = useUserStore(authSelectors.isLogin);const checkGeminiChineseWarning = useGeminiChineseWarning();+ // Read prompt from query parameter+ const [promptParam, setPromptParam] = useQueryState('prompt');+ const hasProcessedPrompt = useRef(false);+const handleGenerate = async () => {if (!isLogin) {loginRequired.redirect({ timeout: 2000 });@@ -66,6 +72,44 @@ const PromptInput = ({ showTitle = false }: PromptInputProps) => {await createImage();};+ // Auto-fill and auto-send when prompt query parameter is present+ useEffect(() => {+ if (promptParam && !hasProcessedPrompt.current && isLogin) {+ // Decode the prompt parameter+ const decodedPrompt = decodeURIComponent(promptParam);++ // Set the prompt value in the store+ setValue(decodedPrompt);++ // Mark as processed to avoid running this effect again+ hasProcessedPrompt.current = true;++ // Clear the query parameter+ setPromptParam(null);++ // Auto-trigger generation after a short delay to ensure state is updated+ setTimeout(async () => {+ const shouldContinue = await checkGeminiChineseWarning({+ model: currentModel,+ prompt: decodedPrompt,+ scenario: 'image',+ });++ if (shouldContinue) {+ await createImage();+ }+ }, 100);+ }+ }, [+ promptParam,+ isLogin,+ setValue,+ setPromptParam,+ checkGeminiChineseWarning,+ currentModel,+ createImage,+ ]);+const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {e.preventDefault();diff --git a/src/features/CommandMenu/AskAIMenu.tsx b/src/features/CommandMenu/AskAIMenu.tsxindex f4121ec5c46..61b35beadb1 100644--- a/src/features/CommandMenu/AskAIMenu.tsx+++ b/src/features/CommandMenu/AskAIMenu.tsx@@ -1,7 +1,8 @@import { DEFAULT_AVATAR, DEFAULT_INBOX_AVATAR } from '@lobechat/const';import { Avatar } from '@lobehub/ui';+import { GroupBotSquareIcon } from '@lobehub/ui/icons';import { Command } from 'cmdk';-import { Image } from 'lucide-react';+import { Bot, Image } from 'lucide-react';import { memo } from 'react';import { useTranslation } from 'react-i18next';import { useNavigate } from 'react-router-dom';@@ -10,11 +11,12 @@ import { useHomeStore } from '@/store/home';import { homeAgentListSelectors } from '@/store/home/selectors';import { useCommandMenuContext } from './CommandMenuContext';+import { CommandItem } from './components';import { styles } from './styles';import { useCommandMenu } from './useCommandMenu';const AskAIMenu = memo(() => {- const { t } = useTranslation('common');+ const { t } = useTranslation(['common', 'chat', 'home']);const navigate = useNavigate();const { handleAskLobeAI, handleAIPainting, closeCommandMenu } = useCommandMenu();const { search } = useCommandMenuContext();@@ -27,6 +29,24 @@ const AskAIMenu = memo(() => {? t('cmdk.askAIHeading', { query: `"${search.trim()}"` }): t('cmdk.askAIHeadingEmpty');+ const handleAgentBuilder = () => {+ const trimmedSearch = search.trim();+ closeCommandMenu(); // Close immediately+ if (trimmedSearch) {+ // Use sendAsAgent to create a blank agent and open agent builder+ useHomeStore.getState().sendAsAgent(trimmedSearch);+ }+ };++ const handleGroupBuilder = () => {+ const trimmedSearch = search.trim();+ closeCommandMenu(); // Close immediately+ if (trimmedSearch) {+ // Use sendAsGroup to create a blank group and open group builder+ useHomeStore.getState().sendAsGroup(trimmedSearch);+ }+ };+const handleAgentSelect = (agentId: string) => {if (search.trim()) {const message = encodeURIComponent(search.trim());@@ -45,6 +65,18 @@ const AskAIMenu = memo(() => {<div className={styles.itemLabel}>Lobe AI</div></div></Command.Item>+ <Command.Item onSelect={handleAgentBuilder} value="agent-builder">+ <Bot className={styles.icon} />+ <div className={styles.itemContent}>+ <div className={styles.itemLabel}>{t('agentBuilder.title', { ns: 'chat' })}</div>+ </div>+ </Command.Item>+ <Command.Item onSelect={handleGroupBuilder} value="group-builder">+ <GroupBotSquareIcon className={styles.icon} />+ <div className={styles.itemContent}>+ <div className={styles.itemLabel}>{t('starter.createGroup', { ns: 'home' })}</div>+ </div>+ </Command.Item><Command.Item onSelect={handleAIPainting} value="ai-painting"><Image className={styles.icon} /><div className={styles.itemContent}>@@ -53,21 +85,22 @@ const AskAIMenu = memo(() => {</Command.Item>{agents.map((agent) => (- <Command.Item+ <CommandItem+ icon={+ <Avatar+ avatar={typeof agent.avatar === 'string' ? agent.avatar : DEFAULT_AVATAR}+ emojiScaleWithBackground+ shape="square"+ size={18}+ />+ }key={agent.id}onSelect={() => handleAgentSelect(agent.id)}+ title={agent.title || t('defaultAgent')}+ trailingLabel={t('cmdk.search.agent')}value={`agent-${agent.id}`}- >- <Avatar- avatar={typeof agent.avatar === 'string' ? agent.avatar : DEFAULT_AVATAR}- emojiScaleWithBackground- shape="square"- size={18}- />- <div className={styles.itemContent}>- <div className={styles.itemLabel}>{agent.title || t('defaultAgent')}</div>- </div>- </Command.Item>+ variant="detailed"+ />))}</Command.Group>);diff --git a/src/features/ModelSwitchPanel/index.tsx b/src/features/ModelSwitchPanel/index.tsxindex 3d59e6982b8..56ae676130f 100644--- a/src/features/ModelSwitchPanel/index.tsx+++ b/src/features/ModelSwitchPanel/index.tsx@@ -165,7 +165,7 @@ const styles = createStaticStyles(({ css, cssVar }) => ({display: flex;align-items: center;- justify-content: flex-end;+ justify-content: space-between;padding-block: 6px;padding-inline: 8px;@@ -173,6 +173,13 @@ const styles = createStaticStyles(({ css, cssVar }) => ({background: ${cssVar.colorBgElevated};`,+ toolbarModelName: css`+ overflow: hidden;+ font-size: 12px;+ color: ${cssVar.colorTextSecondary};+ text-overflow: ellipsis;+ white-space: nowrap;+ `,}));const menuKey = (provider: string, model: string) => `${provider}-${model}`;@@ -381,6 +388,17 @@ const ModelSwitchPanel = memo<ModelSwitchPanelProps>(const activeKey = menuKey(provider, model);+ // Find current model's display name+ const currentModelName = useMemo(() => {+ for (const providerItem of enabledList) {+ const modelItem = providerItem.children.find((m) => m.id === model);+ if (modelItem) {+ return modelItem.displayName || modelItem.id;+ }+ }+ return model;+ }, [enabledList, model]);+const renderVirtualItem = useCallback((item: VirtualItem) => {switch (item.type) {@@ -661,6 +679,7 @@ const ModelSwitchPanel = memo<ModelSwitchPanelProps>(style={{ position: 'relative' }}><div className={styles.toolbar}>+ <div className={styles.toolbarModelName}>{currentModelName}</div><SegmentedonChange={(value) => {const mode = value as GroupMode;