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(onboarding): group chat input feature switches (#14943)

Innei2dc812ac9777
diff --git a/src/features/ChatInput/ChatInputProvider.tsx b/src/features/ChatInput/ChatInputProvider.tsx
index 9ad0ea400c9..1f275215f0d 100644
--- a/src/features/ChatInput/ChatInputProvider.tsx
+++ b/src/features/ChatInput/ChatInputProvider.tsx
@@ -3,6 +3,7 @@ import { type ReactNode } from 'react';
import { memo, useRef } from 'react';
import { createStore, Provider } from './store';
+import { DEFAULT_CHAT_INPUT_FEATURE } from './store/initialState';
import { type StoreUpdaterProps } from './StoreUpdater';
import StoreUpdater from './StoreUpdater';
@@ -15,8 +16,7 @@ export const ChatInputProvider = memo<ChatInputProviderProps>(
agentId,
children,
contextWindowMessages,
- disableMention,
- disableSlash,
+ feature = DEFAULT_CHAT_INPUT_FEATURE,
leftActions,
rightActions,
mobile,
@@ -39,9 +39,8 @@ export const ChatInputProvider = memo<ChatInputProviderProps>(
createStore({
allowExpand,
contextWindowMessages,
- disableMention,
- disableSlash,
editor,
+ feature,
leftActions,
mentionItems,
mobile,
@@ -58,8 +57,7 @@ export const ChatInputProvider = memo<ChatInputProviderProps>(
allowExpand={allowExpand}
chatInputEditorRef={chatInputEditorRef}
contextWindowMessages={contextWindowMessages}
- disableMention={disableMention}
- disableSlash={disableSlash}
+ feature={feature}
getMessages={getMessages}
leftActions={leftActions}
mentionItems={mentionItems}
diff --git a/src/features/ChatInput/InputEditor/index.tsx b/src/features/ChatInput/InputEditor/index.tsx
index 4a3543dc75f..b696410f51a 100644
--- a/src/features/ChatInput/InputEditor/index.tsx
+++ b/src/features/ChatInput/InputEditor/index.tsx
@@ -62,8 +62,9 @@ const InputEditor = memo<{
updateMarkdownContent,
expand,
slashPlacement,
- disableMention,
- disableSlash,
+ isInputCompletionEnabled,
+ isMentionEnabled,
+ isSlashEnabled,
] = useChatInputStore((s) => [
s.editor,
s.slashMenuRef,
@@ -71,8 +72,9 @@ const InputEditor = memo<{
s.updateMarkdownContent,
s.expand,
s.slashPlacement ?? 'top',
- s.disableMention,
- s.disableSlash,
+ s.feature?.inputCompletion ?? true,
+ s.feature?.mention ?? true,
+ s.feature?.slash ?? true,
]);
const storeApi = useStoreApi();
@@ -132,13 +134,13 @@ const InputEditor = memo<{
const MentionMenuComp = useMemo(() => createMentionMenu(stateRef, categoriesRef), []);
- const enableMention = !disableMention && (allMentionItems.length > 0 || enableLocalFileMention);
+ const enableMention = isMentionEnabled && (allMentionItems.length > 0 || enableLocalFileMention);
const heterogeneousName = heterogeneousType
? (HETEROGENEOUS_TYPE_LABELS[heterogeneousType] ?? heterogeneousType)
: undefined;
// Heterogeneous agents (e.g. Claude Code) don't yet support @-assigning to other agents
const showAgentAssignmentHint =
- !disableMention && !heterogeneousName && categories.some((category) => category.id === 'agent');
+ isMentionEnabled && !heterogeneousName && categories.some((category) => category.id === 'agent');
const { handleUploadFiles } = useUploadFiles({ model, provider });
// Listen to editor's paste event for file uploads
@@ -175,7 +177,7 @@ const InputEditor = memo<{
// --- Auto-completion ---
const inputCompletionConfig = useUserStore(systemAgentSelectors.inputCompletion);
- const isAutoCompleteEnabled = inputCompletionConfig.enabled;
+ const isAutoCompleteEnabled = isInputCompletionEnabled && inputCompletionConfig.enabled;
const getMessagesRef = useRef(storeApi.getState().getMessages);
useEffect(() => {
@@ -298,10 +300,10 @@ const InputEditor = memo<{
[enableMention, mentionItemsFn, mentionMarkdownWriter, mentionOnSelect, MentionMenuComp],
);
- const slashOption = useMemo(
- () => (disableSlash ? undefined : { items: slashItems }),
- [disableSlash, slashItems],
- );
+ const slashOption = useMemo(() => (isSlashEnabled ? { items: slashItems } : undefined), [
+ isSlashEnabled,
+ slashItems,
+ ]);
const richRenderProps = useMemo(() => {
const basePlugins = !enableRichRender
diff --git a/src/features/ChatInput/StoreUpdater.tsx b/src/features/ChatInput/StoreUpdater.tsx
index 02e12cd90cc..b847a19f941 100644
--- a/src/features/ChatInput/StoreUpdater.tsx
+++ b/src/features/ChatInput/StoreUpdater.tsx
@@ -8,6 +8,7 @@ import { type ChatInputEditor } from './hooks/useChatInputEditor';
import { useChatInputEditor } from './hooks/useChatInputEditor';
import { type PublicState } from './store';
import { useStoreApi } from './store';
+import { DEFAULT_CHAT_INPUT_FEATURE } from './store/initialState';
export interface StoreUpdaterProps extends Partial<PublicState> {
chatInputEditorRef?: ForwardedRef<ChatInputEditor | null>;
@@ -18,8 +19,7 @@ const StoreUpdater = memo<StoreUpdaterProps>(
agentId,
chatInputEditorRef,
contextWindowMessages,
- disableMention,
- disableSlash,
+ feature = DEFAULT_CHAT_INPUT_FEATURE,
mobile,
sendButtonProps,
leftActions,
@@ -43,8 +43,7 @@ const StoreUpdater = memo<StoreUpdaterProps>(
useStoreUpdater('leftActions', leftActions!);
useStoreUpdater('rightActions', rightActions!);
useStoreUpdater('allowExpand', allowExpand);
- useStoreUpdater('disableMention', disableMention);
- useStoreUpdater('disableSlash', disableSlash);
+ useStoreUpdater('feature', feature);
useStoreUpdater('slashPlacement', slashPlacement);
useStoreUpdater('getMessages', getMessages);
diff --git a/src/features/ChatInput/index.ts b/src/features/ChatInput/index.ts
index 9b257f8870b..7d8c58e2a4c 100644
--- a/src/features/ChatInput/index.ts
+++ b/src/features/ChatInput/index.ts
@@ -4,4 +4,4 @@ export { default as DesktopChatInput } from './Desktop';
export type { ChatInputEditor } from './hooks/useChatInputEditor';
export { useChatInputEditor } from './hooks/useChatInputEditor';
export { default as MobileChatInput } from './Mobile';
-export type { SendButtonHandler } from './store/initialState';
+export type { ChatInputFeature, SendButtonHandler } from './store/initialState';
diff --git a/src/features/ChatInput/store/initialState.ts b/src/features/ChatInput/store/initialState.ts
index 56108fc3b03..de9a1879c1f 100644
--- a/src/features/ChatInput/store/initialState.ts
+++ b/src/features/ChatInput/store/initialState.ts
@@ -32,19 +32,24 @@ export interface ContextWindowMessage {
content: string;
}
+export interface ChatInputFeature {
+ inputCompletion?: boolean;
+ mention?: boolean;
+ slash?: boolean;
+}
+
+export const DEFAULT_CHAT_INPUT_FEATURE = {
+ inputCompletion: true,
+ mention: true,
+ slash: true,
+} as const satisfies Required<ChatInputFeature>;
+
export interface PublicState {
agentId?: string;
allowExpand?: boolean;
contextWindowMessages?: ContextWindowMessage[];
- /**
- * Disable @ mention trigger (no menu, no agent-assignment hint in placeholder)
- */
- disableMention?: boolean;
- /**
- * Disable / slash command trigger
- */
- disableSlash?: boolean;
expand?: boolean;
+ feature?: ChatInputFeature;
getMessages?: () => OpenAIChatMessage[];
leftActions: ActionKeys[];
mentionItems?: SlashOptions['items'];
@@ -72,6 +77,7 @@ export interface State extends PublicState {
export const initialState: State = {
allowExpand: true,
expand: false,
+ feature: DEFAULT_CHAT_INPUT_FEATURE,
isContentEmpty: false,
leftActions: [],
markdownContent: '',
diff --git a/src/features/Conversation/ChatInput/index.tsx b/src/features/Conversation/ChatInput/index.tsx
index 0d487da3f70..642fb11b1e8 100644
--- a/src/features/Conversation/ChatInput/index.tsx
+++ b/src/features/Conversation/ChatInput/index.tsx
@@ -8,7 +8,7 @@ import { type ReactNode } from 'react';
import { memo, useCallback, useEffect, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
-import { type ActionKeys } from '@/features/ChatInput';
+import type { ActionKeys, ChatInputFeature } from '@/features/ChatInput';
import { ChatInputProvider, DesktopChatInput } from '@/features/ChatInput';
import {
type SendButtonHandler,
@@ -55,23 +55,19 @@ export interface ChatInputProps {
* follow-up design). When true, placeholder stays in default variant.
*/
disableFollowUpVariant?: boolean;
- /**
- * Disable the @ mention trigger and its placeholder hint
- */
- disableMention?: boolean;
/**
* Disable enqueuing follow-up messages while the agent is streaming.
* Hides the QueueTray and gates handleSend so Enter does not enqueue.
*/
disableQueue?: boolean;
- /**
- * Disable the / slash command trigger
- */
- disableSlash?: boolean;
/**
* Extra action items to append to the ActionBar
*/
extraActionItems?: ChatInputActionsProps['items'];
+ /**
+ * Chat input capability switches. Omitted capabilities keep the default enabled state.
+ */
+ feature?: ChatInputFeature;
/**
* Swap the action bar and send area for skeleton placeholders while
* the underlying agent/session config is still hydrating. The editor
@@ -136,9 +132,8 @@ const ChatInput = memo<ChatInputProps>(
actionBarStyle,
allowExpand,
disableFollowUpVariant,
- disableMention,
disableQueue,
- disableSlash,
+ feature,
leftActions = [],
leftContent,
rightActions = [],
@@ -340,8 +335,7 @@ const ChatInput = memo<ChatInputProps>(
agentId={agentId}
allowExpand={allowExpand}
contextWindowMessages={contextWindowMessages}
- disableMention={disableMention}
- disableSlash={disableSlash}
+ feature={feature}
getMessages={getMessages}
leftActions={leftActions}
mentionItems={mentionItems}
diff --git a/src/features/Onboarding/Agent/Conversation.test.tsx b/src/features/Onboarding/Agent/Conversation.test.tsx
index 1a34e18927a..b6579963617 100644
--- a/src/features/Onboarding/Agent/Conversation.test.tsx
+++ b/src/features/Onboarding/Agent/Conversation.test.tsx
@@ -122,7 +122,7 @@ describe('AgentOnboardingConversation', () => {
);
});
- it('disables / @ triggers, follow-up placeholder, and message queueing', () => {
+ it('disables input completion, / @ triggers, follow-up placeholder, and message queueing', () => {
mockState.displayMessages = [{ id: 'assistant-1', role: 'assistant' }];
render(<AgentOnboardingConversation />);
@@ -130,9 +130,12 @@ describe('AgentOnboardingConversation', () => {
expect(chatInputSpy).toHaveBeenCalledWith(
expect.objectContaining({
disableFollowUpVariant: true,
- disableMention: true,
disableQueue: true,
- disableSlash: true,
+ feature: expect.objectContaining({
+ inputCompletion: false,
+ mention: false,
+ slash: false,
+ }),
}),
);
});
diff --git a/src/features/Onboarding/Agent/Conversation.tsx b/src/features/Onboarding/Agent/Conversation.tsx
index b25f6b526b6..146478f3a30 100644
--- a/src/features/Onboarding/Agent/Conversation.tsx
+++ b/src/features/Onboarding/Agent/Conversation.tsx
@@ -8,7 +8,7 @@ import { Flexbox } from '@lobehub/ui';
import { memo, useEffect, useMemo, useRef, useState } from 'react';
import { flushSync } from 'react-dom';
-import type { ActionKeys } from '@/features/ChatInput';
+import type { ActionKeys, ChatInputFeature } from '@/features/ChatInput';
import {
ChatInput,
ChatList,
@@ -43,6 +43,11 @@ interface AgentOnboardingConversationProps {
const chatInputLeftActions: ActionKeys[] = isDev ? ['model'] : [];
const chatInputRightActions: ActionKeys[] = [];
+const chatInputFeature = {
+ inputCompletion: false,
+ mention: false,
+ slash: false,
+} satisfies ChatInputFeature;
const AgentOnboardingConversation = memo<AgentOnboardingConversationProps>(
({
@@ -212,10 +217,9 @@ const AgentOnboardingConversation = memo<AgentOnboardingConversationProps>(
)}
<ChatInput
disableFollowUpVariant
- disableMention
disableQueue
- disableSlash
allowExpand={false}
+ feature={chatInputFeature}
leftActions={chatInputLeftActions}
rightActions={chatInputRightActions}
showRuntimeConfig={false}