Skip to content

Commit

Permalink
feat(chat): introduce feature flags (Issue #2771) (#2789)
Browse files Browse the repository at this point in the history
  • Loading branch information
Derikyan authored Dec 12, 2024
1 parent 62e3bda commit 643b7e3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/chat/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ DIAL_ROLES_FIELD="dial_roles"


# Application UI settings
ENABLED_FEATURES="conversations-section,prompts-section,top-settings,top-clear-conversation,top-chat-info,top-chat-model-settings,empty-chat-settings,header,footer,request-api-key,report-an-issue,likes,conversations-sharing,prompts-sharing,input-files,attachments-manager,conversations-publishing,prompts-publishing,custom-logo,input-links,custom-applications,message-templates,marketplace,quick-apps,code-apps"
ENABLED_FEATURES="conversations-section,prompts-section,top-settings,top-clear-conversation,top-chat-info,top-chat-model-settings,hide-top-context-menu,empty-chat-settings,hide-empty-chat-change-agent,header,footer,request-api-key,report-an-issue,likes,conversations-sharing,prompts-sharing,input-files,attachments-manager,conversations-publishing,prompts-publishing,custom-logo,input-links,custom-applications,message-templates,marketplace,quick-apps,code-apps,disallow-change-agent"
NEXT_PUBLIC_APP_NAME="Local Development APP Name"
NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT=""
NEXT_PUBLIC_DEFAULT_TEMPERATURE="1"
Expand Down
19 changes: 17 additions & 2 deletions apps/chat/src/components/Chat/ChatHeader/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,19 @@ export const ChatHeader = ({

const screenState = useScreenState();

const isTopContextMenuHidden = useAppSelector((state) =>
SettingsSelectors.isFeatureEnabled(state, Feature.HideTopContextMenu),
);

const isChangeAgentDisallowed = useAppSelector((state) =>
SettingsSelectors.isFeatureEnabled(state, Feature.DisallowChangeAgent),
);

const isContextMenuVisible =
!isIsolatedView && isChatbarEnabled && !isSelectMode;
!isIsolatedView &&
isChatbarEnabled &&
!isSelectMode &&
!isTopContextMenuHidden;

const selectedAddons = useMemo(
() => getSelectedAddons(conversation.selectedAddons, addonsMap, model),
Expand Down Expand Up @@ -215,7 +226,11 @@ export const ChatHeader = ({
!isIsolatedView &&
'cursor-not-allowed',
)}
disabled={isIsolatedView || isMessageStreaming}
disabled={
isIsolatedView ||
isMessageStreaming ||
isChangeAgentDisallowed
}
onClick={() => onModelClick(conversation.id)}
>
<ModelIcon
Expand Down
5 changes: 4 additions & 1 deletion apps/chat/src/components/Chat/EmptyChatDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const EmptyChatDescriptionView = ({
);
const models = useAppSelector(ModelsSelectors.selectModels);
const isIsolatedView = useAppSelector(SettingsSelectors.selectIsIsolatedView);
const isEmptyChatChangeAgentHidden = useAppSelector((state) =>
SettingsSelectors.isFeatureEnabled(state, Feature.HideEmptyChatChangeAgent),
);
const isEmptyChatSettingsEnabled = useAppSelector((state) =>
SettingsSelectors.isFeatureEnabled(state, Feature.EmptyChatSettings),
);
Expand Down Expand Up @@ -156,7 +159,7 @@ const EmptyChatDescriptionView = ({
)}
</div>
</div>
{!isExternal && !isIsolatedView && (
{!isExternal && !isIsolatedView && !isEmptyChatChangeAgentHidden && (
<div className="flex gap-3 divide-x divide-primary leading-4">
<button
className="text-left text-accent-primary"
Expand Down
6 changes: 6 additions & 0 deletions libs/shared/src/types/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export enum Feature {
TopClearConversation = 'top-clear-conversation', // Display clear conversations button in chat top settings
TopChatInfo = 'top-chat-info', // Display conversation info in top chat settings
TopChatModelSettings = 'top-chat-model-settings', // Display change model settings button
HideTopContextMenu = 'hide-top-context-menu', // Hide top context menu button
EmptyChatSettings = 'empty-chat-settings', // Display settings for empty chat
HideEmptyChatChangeAgent = 'hide-empty-chat-change-agent', // Hide empty chat "Change agent" button
Header = 'header', // Display app header
Footer = 'footer', // Display app footer
RequestApiKey = 'request-api-key', // Display request API Key modal
Expand All @@ -25,6 +27,7 @@ export enum Feature {
Marketplace = 'marketplace', // Enable Marketplace
QuickApps = 'quick-apps', // Enable Quick apps
CodeApps = 'code-apps', // Enable Code apps
DisallowChangeAgent = 'disallow-change-agent', //Disallow "Change agent" button
}

export const availableFeatures: Record<Feature, boolean> = {
Expand All @@ -34,7 +37,9 @@ export const availableFeatures: Record<Feature, boolean> = {
[Feature.TopClearConversation]: true,
[Feature.TopChatInfo]: true,
[Feature.TopChatModelSettings]: true,
[Feature.HideTopContextMenu]: false,
[Feature.EmptyChatSettings]: true,
[Feature.HideEmptyChatChangeAgent]: false,
[Feature.Header]: true,
[Feature.Footer]: true,
[Feature.RequestApiKey]: true,
Expand All @@ -54,4 +59,5 @@ export const availableFeatures: Record<Feature, boolean> = {
[Feature.Marketplace]: true,
[Feature.QuickApps]: true,
[Feature.CodeApps]: true,
[Feature.DisallowChangeAgent]: true,
};

0 comments on commit 643b7e3

Please sign in to comment.