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(feature-flags): add ai_image flag to control AI painting UI (#8797)

YuTengjinga1c66c81fc56
diff --git a/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.test.tsx b/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.test.tsx
index 8491344847a..192f4b4008f 100644
--- a/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.test.tsx
+++ b/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.test.tsx
@@ -13,7 +13,7 @@ import { useSessionStore } from '@/store/session';
import TopActions, { TopActionProps } from './TopActions';
beforeAll(() => {
- initServerConfigStore({ featureFlags: { market: true } });
+ initServerConfigStore({ featureFlags: { market: true, ai_image: true } });
});
beforeEach(() => {
@@ -21,7 +21,7 @@ beforeEach(() => {
});
afterEach(() => {
- createServerConfigStore().setState({ featureFlags: { market: true } });
+ createServerConfigStore().setState({ featureFlags: { market: true, ai_image: true } });
cleanup();
});
@@ -56,10 +56,11 @@ const renderTopActions = (props: TopActionProps = {}) => {
};
describe('TopActions', () => {
- it('should render Chat and Market by default', () => {
+ it('should render Chat, AI Image and Market by default', () => {
renderTopActions();
expect(screen.getByText('tab.chat')).toBeInTheDocument();
+ expect(screen.getByText('tab.aiImage')).toBeInTheDocument();
expect(screen.getByText('tab.discover')).toBeInTheDocument();
});
@@ -85,6 +86,17 @@ describe('TopActions', () => {
expect(screen.queryByText('tab.files')).not.toBeInTheDocument();
});
+ it('should not render AI Image icon when ai_image is disabled', () => {
+ act(() => {
+ createServerConfigStore().setState({ featureFlags: { ai_image: false } });
+ });
+
+ renderTopActions();
+
+ expect(screen.getByText('tab.chat')).toBeInTheDocument();
+ expect(screen.queryByText('tab.aiImage')).not.toBeInTheDocument();
+ });
+
it('should switch back to previous active session', () => {
act(() => {
useSessionStore.setState({ activeId: '1' });
diff --git a/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx b/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx
index 0b7f9ac1eb9..d8754195104 100644
--- a/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx
+++ b/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx
@@ -27,7 +27,8 @@ export interface TopActionProps {
const TopActions = memo<TopActionProps>(({ tab, isPinned }) => {
const { t } = useTranslation('common');
const switchBackToChat = useGlobalStore((s) => s.switchBackToChat);
- const { showMarket, enableKnowledgeBase } = useServerConfigStore(featureFlagsSelectors);
+ const { showMarket, enableKnowledgeBase, showAiImage } =
+ useServerConfigStore(featureFlagsSelectors);
const hotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.NavigateToChat));
const isChatActive = tab === SidebarTabKey.Chat && !isPinned;
@@ -75,15 +76,17 @@ const TopActions = memo<TopActionProps>(({ tab, isPinned }) => {
/>
</Link>
)}
- <Link aria-label={t('tab.aiImage')} href={'/image'}>
- <ActionIcon
- active={isImageActive}
- icon={Palette}
- size={ICON_SIZE}
- title={t('tab.aiImage')}
- tooltipProps={{ placement: 'right' }}
- />
- </Link>
+ {showAiImage && (
+ <Link aria-label={t('tab.aiImage')} href={'/image'}>
+ <ActionIcon
+ active={isImageActive}
+ icon={Palette}
+ size={ICON_SIZE}
+ title={t('tab.aiImage')}
+ tooltipProps={{ placement: 'right' }}
+ />
+ </Link>
+ )}
{showMarket && (
<Link aria-label={t('tab.discover')} href={'/discover'}>
<ActionIcon
diff --git a/src/config/featureFlags/schema.test.ts b/src/config/featureFlags/schema.test.ts
index 2ef60a015e6..f0615d97f46 100644
--- a/src/config/featureFlags/schema.test.ts
+++ b/src/config/featureFlags/schema.test.ts
@@ -12,6 +12,7 @@ describe('FeatureFlagsSchema', () => {
create_session: true,
edit_agent: false,
dalle: true,
+ ai_image: true,
});
expect(result.success).toBe(true);
@@ -36,6 +37,7 @@ describe('mapFeatureFlagsEnvToState', () => {
create_session: true,
edit_agent: false,
dalle: true,
+ ai_image: true,
check_updates: true,
welcome_suggest: true,
};
@@ -48,6 +50,7 @@ describe('mapFeatureFlagsEnvToState', () => {
showOpenAIApiKey: true,
showOpenAIProxyUrl: false,
showDalle: true,
+ showAiImage: true,
enableCheckUpdates: true,
showWelcomeSuggest: true,
};
diff --git a/src/config/featureFlags/schema.ts b/src/config/featureFlags/schema.ts
index 0d1d34cc67f..7186202b8a0 100644
--- a/src/config/featureFlags/schema.ts
+++ b/src/config/featureFlags/schema.ts
@@ -24,6 +24,7 @@ export const FeatureFlagsSchema = z.object({
plugins: z.boolean().optional(),
dalle: z.boolean().optional(),
+ ai_image: z.boolean().optional(),
speech_to_text: z.boolean().optional(),
token_counter: z.boolean().optional(),
@@ -66,6 +67,7 @@ export const DEFAULT_FEATURE_FLAGS: IFeatureFlags = {
plugins: true,
dalle: true,
+ ai_image: true,
check_updates: true,
welcome_suggest: true,
@@ -106,6 +108,7 @@ export const mapFeatureFlagsEnvToState = (config: IFeatureFlags) => {
enablePlugins: config.plugins,
showDalle: config.dalle,
+ showAiImage: config.ai_image,
showChangelog: config.changelog,
enableCheckUpdates: config.check_updates,
diff --git a/src/store/serverConfig/selectors.test.ts b/src/store/serverConfig/selectors.test.ts
index fa378e38d00..e0273a48c08 100644
--- a/src/store/serverConfig/selectors.test.ts
+++ b/src/store/serverConfig/selectors.test.ts
@@ -25,6 +25,7 @@ describe('featureFlagsSelectors', () => {
showChangelog: true,
enableRAGEval: false,
showDalle: true,
+ showAiImage: true,
enableKnowledgeBase: true,
showLLM: false,
showCloudPromotion: false,