The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Gate the AI chat inbox behind a feature flag (#27552)
Félix Malfait5bcb2d694b4a
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphqlindex 617210a1692..111c4b0f8fc 100644--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql@@ -2049,6 +2049,7 @@ type FeatureFlag {}enum FeatureFlagKey {+ IS_AI_CHAT_INBOX_ENABLEDIS_AI_CHAT_SHARING_DROPDOWN_ENABLEDIS_APPLICATION_WORKFLOWS_ENABLEDIS_ASYNC_CSV_EXPORT_ENABLEDdiff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.tsindex a9cab9ac3ce..97fe59d72ad 100644--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts@@ -1318,7 +1318,7 @@ export interface FeatureFlag {__typename: 'FeatureFlag'}-export type FeatureFlagKey = 'IS_AI_CHAT_SHARING_DROPDOWN_ENABLED' | 'IS_APPLICATION_WORKFLOWS_ENABLED' | 'IS_ASYNC_CSV_EXPORT_ENABLED' | 'IS_CALENDAR_SYNC_SKIP_UNCHANGED_RECORDS_ENABLED' | 'IS_CONFIGURABLE_SEARCH_FIELDS_ENABLED' | 'IS_CONVERSATIONS_TAB_ENABLED' | 'IS_DEFERRED_WORKSPACE_MIGRATION_ACTIONS_ENABLED' | 'IS_INITIAL_OBJECT_VIEW_ENABLED' | 'IS_JSON_FILTER_ENABLED' | 'IS_LOGS_SETTINGS_SECTION_ENABLED' | 'IS_MESSAGE_CAMPAIGN_ENABLED' | 'IS_RECORD_CREATION_FORM_ENABLED' | 'IS_RECORD_LEVEL_SHARING_ENABLED' | 'IS_RECORD_SHARE_VISIBILITY_GATING_ENABLED' | 'IS_REST_METADATA_API_NEW_FORMAT_DIRECT' | 'IS_VALIDATION_RULES_ENABLED' | 'IS_WORKFLOW_CORE_INDEX_PAGE_ENABLED' | 'IS_WORKFLOW_SEND_CHAT_MESSAGE_ENABLED'+export type FeatureFlagKey = 'IS_AI_CHAT_INBOX_ENABLED' | 'IS_AI_CHAT_SHARING_DROPDOWN_ENABLED' | 'IS_APPLICATION_WORKFLOWS_ENABLED' | 'IS_ASYNC_CSV_EXPORT_ENABLED' | 'IS_CALENDAR_SYNC_SKIP_UNCHANGED_RECORDS_ENABLED' | 'IS_CONFIGURABLE_SEARCH_FIELDS_ENABLED' | 'IS_CONVERSATIONS_TAB_ENABLED' | 'IS_DEFERRED_WORKSPACE_MIGRATION_ACTIONS_ENABLED' | 'IS_INITIAL_OBJECT_VIEW_ENABLED' | 'IS_JSON_FILTER_ENABLED' | 'IS_LOGS_SETTINGS_SECTION_ENABLED' | 'IS_MESSAGE_CAMPAIGN_ENABLED' | 'IS_RECORD_CREATION_FORM_ENABLED' | 'IS_RECORD_LEVEL_SHARING_ENABLED' | 'IS_RECORD_SHARE_VISIBILITY_GATING_ENABLED' | 'IS_REST_METADATA_API_NEW_FORMAT_DIRECT' | 'IS_VALIDATION_RULES_ENABLED' | 'IS_WORKFLOW_CORE_INDEX_PAGE_ENABLED' | 'IS_WORKFLOW_SEND_CHAT_MESSAGE_ENABLED'export interface Field {applicationId: Scalars['UUID']@@ -11333,6 +11333,7 @@ export const enumEventLogTable = {}export const enumFeatureFlagKey = {+ IS_AI_CHAT_INBOX_ENABLED: 'IS_AI_CHAT_INBOX_ENABLED' as const,IS_AI_CHAT_SHARING_DROPDOWN_ENABLED: 'IS_AI_CHAT_SHARING_DROPDOWN_ENABLED' as const,IS_APPLICATION_WORKFLOWS_ENABLED: 'IS_APPLICATION_WORKFLOWS_ENABLED' as const,IS_ASYNC_CSV_EXPORT_ENABLED: 'IS_ASYNC_CSV_EXPORT_ENABLED' as const,diff --git a/packages/twenty-front/src/generated-admin/graphql.ts b/packages/twenty-front/src/generated-admin/graphql.tsindex 423bb8fcb1e..2103a5bbb53 100644--- a/packages/twenty-front/src/generated-admin/graphql.ts+++ b/packages/twenty-front/src/generated-admin/graphql.ts@@ -475,6 +475,7 @@ export type FeatureFlag = {};export enum FeatureFlagKey {+ IS_AI_CHAT_INBOX_ENABLED = 'IS_AI_CHAT_INBOX_ENABLED',IS_AI_CHAT_SHARING_DROPDOWN_ENABLED = 'IS_AI_CHAT_SHARING_DROPDOWN_ENABLED',IS_APPLICATION_WORKFLOWS_ENABLED = 'IS_APPLICATION_WORKFLOWS_ENABLED',IS_ASYNC_CSV_EXPORT_ENABLED = 'IS_ASYNC_CSV_EXPORT_ENABLED',diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.tsindex d9200a37a9c..6ae097a3647 100644--- a/packages/twenty-front/src/generated-metadata/graphql.ts+++ b/packages/twenty-front/src/generated-metadata/graphql.ts@@ -2166,6 +2166,7 @@ export type FeatureFlag = {};export enum FeatureFlagKey {+ IS_AI_CHAT_INBOX_ENABLED = 'IS_AI_CHAT_INBOX_ENABLED',IS_AI_CHAT_SHARING_DROPDOWN_ENABLED = 'IS_AI_CHAT_SHARING_DROPDOWN_ENABLED',IS_APPLICATION_WORKFLOWS_ENABLED = 'IS_APPLICATION_WORKFLOWS_ENABLED',IS_ASYNC_CSV_EXPORT_ENABLED = 'IS_ASYNC_CSV_EXPORT_ENABLED',diff --git a/packages/twenty-front/src/modules/ai/components/AiChatMessage.tsx b/packages/twenty-front/src/modules/ai/components/AiChatMessage.tsxindex 64742a0175a..13da3379723 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatMessage.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatMessage.tsx@@ -26,6 +26,8 @@ import { themeCssVariables } from 'twenty-ui/theme';import { LabeledDivider } from '@/ui/layout/line/components/LabeledDivider';import { dateLocaleState } from '@/localization/states/dateLocaleState';import { beautifyPastDateRelativeToNow } from '~/utils/date-utils';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';+import { FeatureFlagKey } from '~/generated-metadata/graphql';const StyledMessageBubble = styled.div<{ isUser?: boolean }>`align-items: ${({ isUser }) => (isUser ? 'flex-end' : 'flex-start')};@@ -200,6 +202,9 @@ export const AiChatMessage = ({const firstUnreadMessageId = useAtomComponentSelectorValue(agentChatFirstUnreadMessageIdComponentSelector,);+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );if (!isDefined(agentChatMessage)) {return null;@@ -230,7 +235,7 @@ export const AiChatMessage = ({return (<>- {firstUnreadMessageId === messageId && (+ {isAiChatInboxEnabled && firstUnreadMessageId === messageId && (<LabeledDividertextPosition="end"color={themeCssVariables.tag.text.red}diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadDetailsDropdown.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadDetailsDropdown.tsxindex eb0bca0c706..b5aec2a27d4 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadDetailsDropdown.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadDetailsDropdown.tsx@@ -35,6 +35,8 @@ import { currentWorkspaceMembersState } from '@/auth/states/currentWorkspaceMembimport { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';+import { FeatureFlagKey } from '~/generated-metadata/graphql';const StyledEmptyValue = styled.span`color: ${themeCssVariables.font.color.light};@@ -70,6 +72,9 @@ export const AiChatThreadDetailsDropdown = ({const assignee = currentWorkspaceMembers.find((workspaceMember) => workspaceMember.id === thread?.assigneeId,);+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );const { closeDropdown } = useCloseDropdown();const isAiChatArtifactSurface = useIsAiChatArtifactSurface();const { openRecordTarget } = useChatTargetNavigation();@@ -105,6 +110,10 @@ export const AiChatThreadDetailsDropdown = ({});};+ if (!isAiChatInboxEnabled && !areRecordTargetsAvailable) {+ return null;+ }+return (<><DropdownRoot dropdownId={dropdownId} type="panel">@@ -170,25 +179,36 @@ export const AiChatThreadDetailsDropdown = ({)}</AiChatThreadDetailsRow>)}- <AiChatThreadDetailsRow Icon={IconUsers} label={t`Assignee`}>- {isDefined(assignee) ? (- <RecordChip- objectNameSingular={CoreObjectNameSingular.WorkspaceMember}- record={{ ...assignee, __typename: 'WorkspaceMember' }}- />- ) : (- <StyledEmptyValue>{t`None`}</StyledEmptyValue>- )}- </AiChatThreadDetailsRow>- <AiChatThreadDetailsRow Icon={IconBell} label={t`Following`}>- {followers.map((workspaceMember) => (- <RecordChip- key={workspaceMember.id}- objectNameSingular={CoreObjectNameSingular.WorkspaceMember}- record={{ ...workspaceMember, __typename: 'WorkspaceMember' }}- />- ))}- </AiChatThreadDetailsRow>+ {isAiChatInboxEnabled && (+ <>+ <AiChatThreadDetailsRow Icon={IconUsers} label={t`Assignee`}>+ {isDefined(assignee) ? (+ <RecordChip+ objectNameSingular={+ CoreObjectNameSingular.WorkspaceMember+ }+ record={{ ...assignee, __typename: 'WorkspaceMember' }}+ />+ ) : (+ <StyledEmptyValue>{t`None`}</StyledEmptyValue>+ )}+ </AiChatThreadDetailsRow>+ <AiChatThreadDetailsRow Icon={IconBell} label={t`Following`}>+ {followers.map((workspaceMember) => (+ <RecordChip+ key={workspaceMember.id}+ objectNameSingular={+ CoreObjectNameSingular.WorkspaceMember+ }+ record={{+ ...workspaceMember,+ __typename: 'WorkspaceMember',+ }}+ />+ ))}+ </AiChatThreadDetailsRow>+ </>+ )}</StyledDetails></DropdownContent></DropdownRoot>diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadInboxStateNotice.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadInboxStateNotice.tsxindex 2499541b032..d8d93a6513f 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadInboxStateNotice.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadInboxStateNotice.tsx@@ -9,6 +9,8 @@ import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';import { agentChatThreadInboxStatusFamilySelector } from '@/ai/states/selectors/agentChatThreadInboxStatusFamilySelector';import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';+import { FeatureFlagKey } from '~/generated-metadata/graphql';const StyledNotice = styled.div`align-items: center;@@ -30,7 +32,11 @@ export const AiChatThreadInboxStateNotice = () => {currentAiChatThread ?? '',);- if (!isDefined(event)) {+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );++ if (!isAiChatInboxEnabled || !isDefined(event)) {return null;}diff --git a/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatContent.tsx b/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatContent.tsxindex 3160cd758a4..8e958e3e7d1 100644--- a/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatContent.tsx+++ b/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatContent.tsx@@ -13,6 +13,8 @@ import { agentChatRecentThreadsSelector } from '@/ai/states/selectors/agentChatRimport { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';import { agentChatFavoriteThreadsSelector } from '@/ai/states/selectors/agentChatFavoriteThreadsSelector';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';+import { FeatureFlagKey } from '~/generated-metadata/graphql';const StyledContainer = styled.div`display: flex;@@ -43,10 +45,15 @@ export const NavigationDrawerAiChatContent = () => {const { t } = useLingui();const isExpanded = useIsNavigationDrawerContentExpanded();+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );const currentAiChatThread = useAtomStateValue(currentAiChatThreadState);- const { handleThreadClick } = useAiChatThreadClick({- shouldOpenInFullPage: true,- });+ const { handleThreadClick } = useAiChatThreadClick(+ isAiChatInboxEnabled+ ? { shouldOpenInFullPage: true }+ : { resetNavigationStack: true },+ );const { threads, loading } = useChatThreads(agentChatRecentThreadsSelector);const agentChatFavoriteThreads = useAtomStateValue(@@ -72,7 +79,7 @@ export const NavigationDrawerAiChatContent = () => {<StyledContainer><StyledThreadList><StyledSectionsContainer>- <NavigationDrawerAiChatTriageSection />+ {isAiChatInboxEnabled && <NavigationDrawerAiChatTriageSection />}{agentChatFavoriteThreads.length > 0 && (<NavigationDrawerAiChatThreadSectionsectionId={AI_CHAT_FAVORITES_NAVIGATION_SECTION_ID}diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadDetailsDropdown.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadDetailsDropdown.test.tsxindex 6eb867a5b87..6419c90fd30 100644--- a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadDetailsDropdown.test.tsx+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadDetailsDropdown.test.tsx@@ -174,9 +174,13 @@ const buildWorkspaceMember = (id: string, firstName: string) => ({const renderDetails = async ({permissions = EDITABLE_PERMISSIONS,isConversationsTabEnabled = true,+ isAiChatInboxEnabled = true,+ shouldOpenDetails = true,}: {permissions?: typeof EDITABLE_PERMISSIONS;isConversationsTabEnabled?: boolean;+ isAiChatInboxEnabled?: boolean;+ shouldOpenDetails?: boolean;} = {}) => {const MetadataAndApolloMocksWrapper = getJestMetadataAndApolloMocksWrapper({objectMetadataItems: [@@ -191,6 +195,10 @@ const renderDetails = async ({key: FeatureFlagKey.IS_CONVERSATIONS_TAB_ENABLED,value: isConversationsTabEnabled,},+ {+ key: FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ value: isAiChatInboxEnabled,+ },],});setAgentChatThreadPermissions(store, THREAD_ID, permissions);@@ -223,6 +231,10 @@ const renderDetails = async ({wrapper: Wrapper,});+ if (!shouldOpenDetails) {+ return;+ }+await userEvent.click(await screen.findByRole('button', { name: 'Chat details' }),);@@ -373,6 +385,26 @@ describe('AiChatThreadDetailsDropdown', () => {expect(refetchThread).toHaveBeenCalledTimes(1);});+ it('leaves out the assignee and followers while the inbox feature flag is off', async () => {+ await renderDetails({ isAiChatInboxEnabled: false });++ expect(await screen.findByText('Linked to')).toBeVisible();+ expect(screen.queryByText('Assignee')).not.toBeInTheDocument();+ expect(screen.queryByText('Owner Member')).not.toBeInTheDocument();+ });++ it('hides the chat details with neither the inbox nor the conversations tab enabled', async () => {+ await renderDetails({+ isAiChatInboxEnabled: false,+ isConversationsTabEnabled: false,+ shouldOpenDetails: false,+ });++ expect(+ screen.queryByRole('button', { name: 'Chat details' }),+ ).not.toBeInTheDocument();+ });+it('leaves out the linked records until the conversations tab is enabled', async () => {await renderDetails({ isConversationsTabEnabled: false });diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatContent.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatContent.test.tsxindex 461c4d66bd9..7ce9bc0db12 100644--- a/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatContent.test.tsx+++ b/packages/twenty-front/src/modules/ai/components/__tests__/NavigationDrawerAiChatContent.test.tsx@@ -54,7 +54,13 @@ jest.mock();jest.mock('@/ai/components/NavigationDrawerAiChatTriageSection', () => ({- NavigationDrawerAiChatTriageSection: () => null,+ NavigationDrawerAiChatTriageSection: () => <nav aria-label="Triage" />,+}));++let mockIsAiChatInboxEnabled = true;++jest.mock('@/workspace/hooks/useIsFeatureEnabled', () => ({+ useIsFeatureEnabled: () => mockIsAiChatInboxEnabled,}));jest.mock('@/ai/components/AgentChatThreadsFetchMoreTrigger', () => ({@@ -89,6 +95,7 @@ const renderContent = () =>describe('NavigationDrawerAiChatContent', () => {beforeEach(() => {resetJotaiStore();+ mockIsAiChatInboxEnabled = true;mockThreads = [buildThread('chat-1', 'Pipeline review'),buildThread('chat-2', 'Quarterly plan'),@@ -110,6 +117,21 @@ describe('NavigationDrawerAiChatContent', () => {expect(within(recents).queryByText('Quarterly plan')).toBeNull();});+ it('shows the triage section with the inbox feature flag on', () => {+ const { getByRole } = renderContent();++ expect(getByRole('navigation', { name: 'Triage' })).toBeInTheDocument();+ });++ it('hides the triage section while the inbox feature flag is off', () => {+ mockIsAiChatInboxEnabled = false;++ const { queryByRole } = renderContent();++ expect(queryByRole('navigation', { name: 'Triage' })).toBeNull();+ expect(queryByRole('region', { name: 'Recent' })).toBeInTheDocument();+ });+it('shows no Favorites section without favorite chats', () => {jotaiStore.set(mockFavoriteThreadsAtom, []);diff --git a/packages/twenty-front/src/modules/ai/hooks/useAiChatEditor.ts b/packages/twenty-front/src/modules/ai/hooks/useAiChatEditor.tsindex b49bd21ce99..701a5a400b6 100644--- a/packages/twenty-front/src/modules/ai/hooks/useAiChatEditor.ts+++ b/packages/twenty-front/src/modules/ai/hooks/useAiChatEditor.ts@@ -28,6 +28,8 @@ import { useRemoveFocusItemFromFocusStackById } from '@/ui/utilities/focus/hooksimport { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';+import { FeatureFlagKey } from '~/generated-metadata/graphql';import { turnIntoEmptyStringIfWhitespacesOnly } from '~/utils/string/turnIntoEmptyStringIfWhitespacesOnly';export const useAiChatEditor = () => {@@ -36,6 +38,9 @@ export const useAiChatEditor = () => {useAtomState(agentChatDraftsByThreadIdState);const { searchMentionRecords } = useMentionSearch();const { searchWorkspaceMembers } = useWorkspaceMemberMentionSearch();+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );const { searchSkills } = useSkillSuggestionSearch();const { uploadFiles } = useAiChatFileUpload();const { pushFocusItemToFocusStack } = usePushFocusItemToFocusStack();@@ -46,7 +51,9 @@ export const useAiChatEditor = () => {const initialDraft = agentChatDraftsByThreadId[draftKey] ?? '';const editor = useAdvancedTextEditor({profile: AI_CHAT_EDITOR_PROFILE,- placeholder: t`Ask anything, @ a teammate or record, / a skill...`,+ placeholder: isAiChatInboxEnabled+ ? t`Ask anything, @ a teammate or record, / a skill...`+ : t`Ask anything, @ a record or / a skill...`,readonly: false,defaultValue: initialDraft,editorProps: {@@ -134,7 +141,9 @@ export const useAiChatEditor = () => {searchWorkspaceMembers: typeof searchWorkspaceMembers;};mentionStorage.searchMentionRecords = searchMentionRecords;- mentionStorage.searchWorkspaceMembers = searchWorkspaceMembers;+ mentionStorage.searchWorkspaceMembers = isAiChatInboxEnabled+ ? searchWorkspaceMembers+ : () => [];const skillStorage = storage['skill-suggestion'] as {searchSkills: typeof searchSkills;diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsxindex d4ed5f69ef6..a550cbc8d6e 100644--- a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx+++ b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx@@ -13,8 +13,13 @@ import { useNavigationDrawerModes } from '@/navigation/hooks/useNavigationDrawerimport { useSwitchNavigationDrawerMode } from '@/navigation/hooks/useSwitchNavigationDrawerMode';import { TooltipDelay } from '@/ui/layout/tooltip/constants/TooltipDelay';import { StyledNavigationDrawerUnreadDot } from '@/ui/navigation/navigation-drawer/components/StyledNavigationDrawerUnreadDot';-import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';+import {+ type NavigationDrawerActiveTab,+ NAVIGATION_DRAWER_TABS,+} from '@/ui/navigation/states/navigationDrawerTabs';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';+import { FeatureFlagKey } from '~/generated-metadata/graphql';import { useIsMobile } from 'twenty-ui/utilities';// Expanded, the row matches the page card header so their borders read as one line.@@ -124,6 +129,19 @@ export const MainNavigationDrawerModeSwitcher = () => {const { hasUnreadOpenThread } = useAtomStateValue(agentChatOpenThreadsSummarySelector,);+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );++ const getDisabledModeTooltip = (mode: NavigationDrawerActiveTab) => {+ if (mode === NAVIGATION_DRAWER_TABS.SETTINGS) {+ return t`Finish editing the layout to open Settings`;+ }++ return isAiChatInboxEnabled+ ? t`Finish editing the layout to open Inbox`+ : t`Finish editing the layout to open AI`;+ };if (modes.length === 0) {return null;@@ -141,6 +159,7 @@ export const MainNavigationDrawerModeSwitcher = () => {const isActive = mode === activeNavigationDrawerMode;// Inside the inbox, its Open item already shows what is unreadconst isUnread =+ isAiChatInboxEnabled &&mode === NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY &&hasUnreadOpenThread &&!isActive;@@ -151,13 +170,7 @@ export const MainNavigationDrawerModeSwitcher = () => {return (<Tooltipkey={mode}- content={- isDisabled- ? mode === NAVIGATION_DRAWER_TABS.SETTINGS- ? t`Finish editing the layout to open Settings`- : t`Finish editing the layout to open Inbox`- : label- }+ content={isDisabled ? getDisabledModeTooltip(mode) : label}disabled={!shouldShowTooltips && !isDisabled}delay={TooltipDelay.noDelay}side={isExpanded ? 'bottom' : 'right'}diff --git a/packages/twenty-front/src/modules/navigation/components/__tests__/MainNavigationDrawerModeSwitcher.test.tsx b/packages/twenty-front/src/modules/navigation/components/__tests__/MainNavigationDrawerModeSwitcher.test.tsxindex 7216992906a..d3b34ecabb4 100644--- a/packages/twenty-front/src/modules/navigation/components/__tests__/MainNavigationDrawerModeSwitcher.test.tsx+++ b/packages/twenty-front/src/modules/navigation/components/__tests__/MainNavigationDrawerModeSwitcher.test.tsx@@ -22,6 +22,12 @@ jest.mock(jest.mock('@/navigation/hooks/useNavigationDrawerModes');jest.mock('@/navigation/hooks/useSwitchNavigationDrawerMode');+let mockIsAiChatInboxEnabled = true;++jest.mock('@/workspace/hooks/useIsFeatureEnabled', () => ({+ useIsFeatureEnabled: () => mockIsAiChatInboxEnabled,+}));+jest.mock('twenty-ui/utilities', () => ({...jest.requireActual('twenty-ui/utilities'),useIsMobile: () => false,@@ -80,6 +86,7 @@ const renderModeSwitcher = (isLayoutCustomizationModeEnabled = false) => {describe('MainNavigationDrawerModeSwitcher', () => {beforeEach(() => {jest.clearAllMocks();+ mockIsAiChatInboxEnabled = true;jest.mocked(useNavigationDrawerModes).mockReturnValue([{@@ -184,6 +191,15 @@ describe('MainNavigationDrawerModeSwitcher', () => {expect(screen.getByRole('button', { name: 'AI' })).toBeInTheDocument();});+ it('does not mark unread chats while the inbox feature flag is off', () => {+ mockIsAiChatInboxEnabled = false;+ const { store } = renderModeSwitcher();++ act(() => receiveOpenChat(store, null));++ expect(screen.getByRole('button', { name: 'AI' })).toBeInTheDocument();+ });+it('does not mark the inbox while it is open', () => {jest.mocked(useActiveNavigationDrawerMode)diff --git a/packages/twenty-front/src/modules/navigation/hooks/useNavigationDrawerModes.ts b/packages/twenty-front/src/modules/navigation/hooks/useNavigationDrawerModes.tsindex f2ec6aceab1..3e64ca95ad1 100644--- a/packages/twenty-front/src/modules/navigation/hooks/useNavigationDrawerModes.ts+++ b/packages/twenty-front/src/modules/navigation/hooks/useNavigationDrawerModes.ts@@ -1,6 +1,7 @@import { useLingui } from '@lingui/react/macro';import { WorkspaceActivationStatus } from 'twenty-shared/workspace';import {+ IconComment,type IconComponent,IconHome,IconInbox,@@ -13,8 +14,12 @@ import {type NavigationDrawerActiveTab,NAVIGATION_DRAWER_TABS,} from '@/ui/navigation/states/navigationDrawerTabs';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';import { useIsWorkspaceActivationStatusEqualsTo } from '@/workspace/hooks/useIsWorkspaceActivationStatusEqualsTo';-import { PermissionFlagType } from '~/generated-metadata/graphql';+import {+ FeatureFlagKey,+ PermissionFlagType,+} from '~/generated-metadata/graphql';export type NavigationDrawerMode = {Icon: IconComponent;@@ -26,6 +31,9 @@ export const useNavigationDrawerModes = (): NavigationDrawerMode[] => {const { t } = useLingui();const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );const isWorkspaceSuspended = useIsWorkspaceActivationStatusEqualsTo(WorkspaceActivationStatus.SUSPENDED,);@@ -43,10 +51,9 @@ export const useNavigationDrawerModes = (): NavigationDrawerMode[] => {Icon: IconHome,label: t`Home`,},- [NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY]: {- Icon: IconInbox,- label: t`Inbox`,- },+ [NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY]: isAiChatInboxEnabled+ ? { Icon: IconInbox, label: t`Inbox` }+ : { Icon: IconComment, label: t`AI` },[NAVIGATION_DRAWER_TABS.SETTINGS]: {Icon: IconSettings,label: t`Settings`,diff --git a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentFormContent.tsx b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentFormContent.tsxindex 367ca3de2b4..1925d14fb1b 100644--- a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentFormContent.tsx+++ b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentFormContent.tsx@@ -24,7 +24,11 @@ import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabimport { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';-import { type FindOneAgentQuery } from '~/generated-metadata/graphql';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';+import {+ FeatureFlagKey,+ type FindOneAgentQuery,+} from '~/generated-metadata/graphql';import { CoreAgentRoleTab } from '@/object-core/agents/components/CoreAgentRoleTab';import { CoreAgentRunsTab } from '@/object-core/agents/components/CoreAgentRunsTab';import { CoreAgentSettingsTab } from '@/object-core/agents/components/CoreAgentSettingsTab';@@ -53,6 +57,9 @@ export const CoreAgentFormContent = ({ agent }: CoreAgentFormContentProps) => {const theme = useTheme();const { getIcon } = useIcons();const currentWorkspace = useAtomStateValue(currentWorkspaceState);+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );const isReadonlyMode = isOwnedByInstalledApplication({applicationId: agent.applicationId,@@ -115,16 +122,20 @@ export const CoreAgentFormContent = ({ agent }: CoreAgentFormContentProps) => {title: t`Role`,Icon: IconLock,},- {- id: CORE_AGENT_DETAIL_TABS.TABS_IDS.TRIGGERS,- title: t`Triggers`,- Icon: IconBolt,- },- {- id: CORE_AGENT_DETAIL_TABS.TABS_IDS.RUNS,- title: t`Runs`,- Icon: IconTerminal,- },+ ...(isAiChatInboxEnabled+ ? [+ {+ id: CORE_AGENT_DETAIL_TABS.TABS_IDS.TRIGGERS,+ title: t`Triggers`,+ Icon: IconBolt,+ },+ {+ id: CORE_AGENT_DETAIL_TABS.TABS_IDS.RUNS,+ title: t`Runs`,+ Icon: IconTerminal,+ },+ ]+ : []),];const title = agent.label;@@ -134,8 +145,11 @@ export const CoreAgentFormContent = ({ agent }: CoreAgentFormContentProps) => {const isSettingsTab =activeTabId === CORE_AGENT_DETAIL_TABS.TABS_IDS.SETTINGS;const isTriggersTab =+ isAiChatInboxEnabled &&activeTabId === CORE_AGENT_DETAIL_TABS.TABS_IDS.TRIGGERS;- const isRunsTab = activeTabId === CORE_AGENT_DETAIL_TABS.TABS_IDS.RUNS;+ const isRunsTab =+ isAiChatInboxEnabled &&+ activeTabId === CORE_AGENT_DETAIL_TABS.TABS_IDS.RUNS;const isFormDisabled = isReadonlyMode || !agent.isCustom;diff --git a/packages/twenty-front/src/modules/settings/admin-panel/constants/SettingsAdminFeatureFlagMetadata.ts b/packages/twenty-front/src/modules/settings/admin-panel/constants/SettingsAdminFeatureFlagMetadata.tsindex db774e8772c..84c9cad4d79 100644--- a/packages/twenty-front/src/modules/settings/admin-panel/constants/SettingsAdminFeatureFlagMetadata.ts+++ b/packages/twenty-front/src/modules/settings/admin-panel/constants/SettingsAdminFeatureFlagMetadata.ts@@ -80,4 +80,8 @@ export const SETTINGS_ADMIN_FEATURE_FLAG_METADATA: Record<label: msg`Skip unchanged calendar records`,description: msg`Only write calendar events and participants that changed since the last sync.`,},+ [FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED]: {+ label: msg`AI chat inbox`,+ description: msg`Turn the AI tab into an inbox to triage, assign, snooze and follow chats, and let workflows route agent questions to a member.`,+ },};diff --git a/packages/twenty-front/src/modules/side-panel/pages/workflow/action/components/SidePanelWorkflowSelectAction.tsx b/packages/twenty-front/src/modules/side-panel/pages/workflow/action/components/SidePanelWorkflowSelectAction.tsxindex 2f255887dad..9c97a0568b2 100644--- a/packages/twenty-front/src/modules/side-panel/pages/workflow/action/components/SidePanelWorkflowSelectAction.tsx+++ b/packages/twenty-front/src/modules/side-panel/pages/workflow/action/components/SidePanelWorkflowSelectAction.tsx@@ -18,6 +18,7 @@ import { RECORD_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constimport { useLingui } from '@lingui/react/macro';import { isDefined } from 'twenty-shared/utils';import { WORKFLOW_ACTION_FEATURE_FLAGS } from 'twenty-shared/workflow';+import { FeatureFlagKey } from '~/generated-metadata/graphql';export type WorkflowActionSelection = {type: WorkflowActionType;@@ -49,6 +50,11 @@ export const SidePanelWorkflowSelectAction = ({const featureFlagsMap = useWorkspaceFeatureFlagsMap();const isActionEnabled = ({ type }: { type: WorkflowActionType }) => {+ // Hidden from the picker only, so the AI workflow tools can still add it+ if (type === 'WAIT_FOR_EVENT') {+ return featureFlagsMap[FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED] === true;+ }+const featureFlag = WORKFLOW_ACTION_FEATURE_FLAGS[type];return !isDefined(featureFlag) || featureFlagsMap[featureFlag] === true;diff --git a/packages/twenty-front/src/modules/side-panel/pages/workflow/action/components/__tests__/SidePanelWorkflowSelectAction.test.tsx b/packages/twenty-front/src/modules/side-panel/pages/workflow/action/components/__tests__/SidePanelWorkflowSelectAction.test.tsxnew file mode 100644index 00000000000..33fde49624e--- /dev/null+++ b/packages/twenty-front/src/modules/side-panel/pages/workflow/action/components/__tests__/SidePanelWorkflowSelectAction.test.tsx@@ -0,0 +1,70 @@+import { i18n } from '@lingui/core';+import { I18nProvider } from '@lingui/react';+import { render, screen } from '@testing-library/react';+import { Provider as JotaiProvider } from 'jotai';+import { SOURCE_LOCALE } from 'twenty-shared/translations';++import { SidePanelWorkflowSelectAction } from '@/side-panel/pages/workflow/action/components/SidePanelWorkflowSelectAction';+import {+ jotaiStore,+ resetJotaiStore,+} from '@/ui/utilities/state/jotai/jotaiStore';+import { FeatureFlagKey } from '~/generated-metadata/graphql';+import { messages } from '~/locales/generated/en';++i18n.load({ [SOURCE_LOCALE]: messages });+i18n.activate(SOURCE_LOCALE);++let mockFeatureFlagsMap: Record<string, boolean> = {};++jest.mock('@/workspace/hooks/useWorkspaceFeatureFlagsMap', () => ({+ useWorkspaceFeatureFlagsMap: () => mockFeatureFlagsMap,+}));++jest.mock(+ '@/side-panel/pages/workflow/action/components/WorkflowActionMenuItems',+ () => ({+ WorkflowActionMenuItems: ({+ actions,+ }: {+ actions: { defaultLabel: string }[];+ }) => (+ <>+ {actions.map((action) => (+ <div key={action.defaultLabel}>{action.defaultLabel}</div>+ ))}+ </>+ ),+ }),+);++const renderPicker = () =>+ render(+ <JotaiProvider store={jotaiStore}>+ <I18nProvider i18n={i18n}>+ <SidePanelWorkflowSelectAction onActionSelected={jest.fn()} />+ </I18nProvider>+ </JotaiProvider>,+ );++describe('SidePanelWorkflowSelectAction', () => {+ beforeEach(() => {+ resetJotaiStore();+ mockFeatureFlagsMap = {};+ });++ it('hides Wait for Event while the inbox feature flag is off', () => {+ renderPicker();++ expect(screen.queryByText('Wait for Event')).not.toBeInTheDocument();+ expect(screen.getByText('Delay')).toBeInTheDocument();+ });++ it('offers Wait for Event once the inbox feature flag is on', () => {+ mockFeatureFlagsMap = { [FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED]: true };++ renderPicker();++ expect(screen.getByText('Wait for Event')).toBeInTheDocument();+ });+});diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/ai-agent-action/components/WorkflowAiAgentPromptTab.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/ai-agent-action/components/WorkflowAiAgentPromptTab.tsxindex 4a8fc7db341..6c7cfe6fb82 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/ai-agent-action/components/WorkflowAiAgentPromptTab.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/ai-agent-action/components/WorkflowAiAgentPromptTab.tsx@@ -8,6 +8,7 @@ import { schemaToFields } from '@/ai/utils/schemaToFields';import { FormSingleRecordPicker } from '@/object-record/record-field/ui/form-types/components/FormSingleRecordPicker';import { FormTextFieldInput } from '@/object-record/record-field/ui/form-types/components/FormTextFieldInput';import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';import { type WorkflowAiAgentAction } from '@/workflow/types/Workflow';import { WorkflowConversationFields } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowConversationFields';import { AgentOutputSchemaBuilder } from '@/ai/components/AgentOutputSchemaBuilder';@@ -24,6 +25,7 @@ import { CoreObjectNameSingular } from 'twenty-shared/types';import { type WorkflowConversation } from 'twenty-shared/workflow';import { useDebouncedCallback } from 'use-debounce';import {+ FeatureFlagKey,UpdateOneAgentDocument,type UpdateOneAgentMutationVariables,} from '~/generated-metadata/graphql';@@ -58,6 +60,9 @@ export const WorkflowAiAgentPromptTab = ({const [workflowAiAgentActionAgent, setWorkflowAiAgentActionAgent] =useAtomState(workflowAiAgentActionAgentState);const [updateAgent] = useMutation(UpdateOneAgentDocument);+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );const [outputSchemaFields, setOutputSchemaFields] = useState<OutputSchemaField[]@@ -173,26 +178,30 @@ export const WorkflowAiAgentPromptTab = ({readonly={readonly}/>- <FormSingleRecordPicker- label={t`Recipient`}- objectNameSingulars={[CoreObjectNameSingular.WorkspaceMember]}- defaultValue={recipientWorkspaceMemberId}- onChange={(workspaceMemberId) =>- onRecipientChange(workspaceMemberId ?? undefined)- }- disabled={readonly}- testId="workflow-edit-action-ai-agent-recipient"- VariablePicker={WorkflowVariablePicker}- />-- <WorkflowConversationFields- dropdownId={`workflow-ai-agent-conversation-${action.id}`}- conversation={conversation}- defaultScope="STEP"- description={t`With the recipient, or the workflow creator when empty. It stays out of their inbox until the agent needs them.`}- readonly={readonly}- onChange={onConversationChange}- />+ {isAiChatInboxEnabled && (+ <>+ <FormSingleRecordPicker+ label={t`Recipient`}+ objectNameSingulars={[CoreObjectNameSingular.WorkspaceMember]}+ defaultValue={recipientWorkspaceMemberId}+ onChange={(workspaceMemberId) =>+ onRecipientChange(workspaceMemberId ?? undefined)+ }+ disabled={readonly}+ testId="workflow-edit-action-ai-agent-recipient"+ VariablePicker={WorkflowVariablePicker}+ />++ <WorkflowConversationFields+ dropdownId={`workflow-ai-agent-conversation-${action.id}`}+ conversation={conversation}+ defaultScope="STEP"+ description={t`With the recipient, or the workflow creator when empty. It stays out of their inbox until the agent needs them.`}+ readonly={readonly}+ onChange={onConversationChange}+ />+ </>+ )}<SettingsAgentModelCapabilitiesselectedModelId={agent.modelId}diff --git a/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx b/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsxindex 17042b22038..3aedf17b8e4 100644--- a/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx+++ b/packages/twenty-front/src/pages/ai-chat/AiChatInboxPage.tsx@@ -1,9 +1,9 @@import { styled } from '@linaria/react';import { useLingui } from '@lingui/react/macro';import { type MouseEvent, useId, useRef } from 'react';-import { useParams } from 'react-router-dom';+import { Navigate, useParams } from 'react-router-dom';import { AppPath } from 'twenty-shared/types';-import { isDefined, isValidUuid } from 'twenty-shared/utils';+import { getAppPath, isDefined, isValidUuid } from 'twenty-shared/utils';import { IconButton } from 'twenty-ui/components/input';import { IconChevronLeft } from 'twenty-ui/icon';import { useIsMobile } from 'twenty-ui/utilities';@@ -34,6 +34,8 @@ import { EmptyState } from '@/ui/feedback/empty-state/components/EmptyState';import { PageCardHeader } from '@/ui/layout/page/components/PageCardHeader';import { PageCardLayout } from '@/ui/layout/page/components/PageCardLayout';import { useAtomComponentSelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentSelectorValue';+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';+import { FeatureFlagKey } from '~/generated-metadata/graphql';import { useNavigateApp } from '~/hooks/useNavigateApp';import { AiChatPageEffects } from '~/pages/ai-chat/AiChatPageEffects';import { AiChatThreadPageContent } from '~/pages/ai-chat/AiChatThreadPageContent';@@ -250,6 +252,19 @@ const AiChatInboxPageContent = () => {export const AiChatInboxPage = () => {// A new instance per visit, so a selection does not outlive the inboxconst recordSelectionInstanceId = useId();+ const { threadId } = useParams();+ const isAiChatInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );++ if (!isAiChatInboxEnabled) {+ return (+ <Navigate+ to={getAppPath(AppPath.AiChat, { threadId: threadId ?? null })}+ replace+ />+ );+ }return (<RecordSelectionComponentInstanceContext.Providerdiff --git a/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx b/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsxindex 54a197d0a4f..6a08b379e2a 100644--- a/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx+++ b/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx@@ -168,6 +168,12 @@ jest.mock(() => ({ PinnedCommandMenuItemButtons: () => null }),);+let mockIsAiChatInboxEnabled = true;++jest.mock('@/workspace/hooks/useIsFeatureEnabled', () => ({+ useIsFeatureEnabled: () => mockIsAiChatInboxEnabled,+}));+const [firstThread, secondThread, thirdThread] = THREADS;const renderInbox = (path = `/inbox/${firstThread.id}`) =>@@ -178,6 +184,10 @@ const renderInbox = (path = `/inbox/${firstThread.id}`) =><MemoryRouterAppNavigatorProvider><Routes><Route path={AppPath.AiChatInbox} element={<AiChatInboxPage />} />+ <Route+ path={AppPath.AiChat}+ element={<div>Chat page without the inbox</div>}+ /></Routes></MemoryRouterAppNavigatorProvider></MemoryRouter>@@ -203,6 +213,15 @@ describe('AiChatInboxPage', () => {beforeEach(() => {resetJotaiStore();isMobile = false;+ mockIsAiChatInboxEnabled = true;+ });++ it('sends the inbox to the chat page while the inbox feature flag is off', () => {+ mockIsAiChatInboxEnabled = false;++ renderInbox();++ expect(screen.getByText('Chat page without the inbox')).toBeInTheDocument();});it('opens the clicked chat', () => {diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-46/2-46-workspace-command-1790942019633-add-ai-chat-inbox-command-menu-items.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-46/2-46-workspace-command-1790942019633-add-ai-chat-inbox-command-menu-items.command.tsindex a356e520fc0..ce71a4a419c 100644--- a/packages/twenty-server/src/database/commands/upgrade-version-command/2-46/2-46-workspace-command-1790942019633-add-ai-chat-inbox-command-menu-items.command.ts+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-46/2-46-workspace-command-1790942019633-add-ai-chat-inbox-command-menu-items.command.ts@@ -21,13 +21,11 @@ const AI_CHAT_INBOX_COMMAND_MENU_ITEM_NAMES = ['snoozeAiChat',] as const;-const NEW_AI_CHAT_UNIVERSAL_IDENTIFIER = '604bc9b2-e438-4572-bd35-726fa0fb2ec7';-@RegisteredWorkspaceCommand('2.46.0', 1790942019633)@Command({name: 'upgrade:2-46:add-ai-chat-inbox-command-menu-items',description:- 'Add the Mark as read, Mark as unread, Mark as done, Reopen, Unsnooze and Snooze commands to chats, and unpin New chat from the chat header',+ 'Add the Mark as read, Mark as unread, Mark as done, Reopen, Unsnooze and Snooze commands to chats',})export class AddAiChatInboxCommandMenuItemsCommand extends ProvisionedWorkspaceCommandRunner {constructor(@@ -81,33 +79,15 @@ export class AddAiChatInboxCommandMenuItemsCommand extends ProvisionedWorkspaceC).filter(isDefined): [];- const newAiChat =- flatCommandMenuItemMaps.byUniversalIdentifier[- NEW_AI_CHAT_UNIVERSAL_IDENTIFIER- ];- const isNewAiChatPinned = direction === 'down';- const commandMenuItemsToUpdate =- isDefined(newAiChat) && newAiChat.isPinned !== isNewAiChatPinned- ? [- {- ...newAiChat,- isPinned: isNewAiChatPinned,- updatedAt: new Date().toISOString(),- },- ]- : [];-if (- commandMenuItemsToCreate.length +- commandMenuItemsToDelete.length +- commandMenuItemsToUpdate.length ===+ commandMenuItemsToCreate.length + commandMenuItemsToDelete.length ===0) {return;}this.logger.log(- `${options.dryRun ? '[DRY RUN] ' : ''}Workspace ${workspaceId} (${direction}): creating ${commandMenuItemsToCreate.length}, deleting ${commandMenuItemsToDelete.length} and updating ${commandMenuItemsToUpdate.length} chat command menu item(s)`,+ `${options.dryRun ? '[DRY RUN] ' : ''}Workspace ${workspaceId} (${direction}): creating ${commandMenuItemsToCreate.length} and deleting ${commandMenuItemsToDelete.length} chat command menu item(s)`,);if (options.dryRun) {@@ -125,7 +105,7 @@ export class AddAiChatInboxCommandMenuItemsCommand extends ProvisionedWorkspaceCcommandMenuItem: {flatEntityToCreate: commandMenuItemsToCreate,flatEntityToDelete: commandMenuItemsToDelete,- flatEntityToUpdate: commandMenuItemsToUpdate,+ flatEntityToUpdate: [],},},},diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-47/2-47-upgrade-version-command.module.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-47/2-47-upgrade-version-command.module.tsnew file mode 100644index 00000000000..d0ee2b5973a--- /dev/null+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-47/2-47-upgrade-version-command.module.ts@@ -0,0 +1,16 @@+import { Module } from '@nestjs/common';++import { WorkspaceIteratorModule } from 'src/database/commands/command-runners/workspace-iterator.module';+import { UnpinNewAiChatCommand } from 'src/database/commands/upgrade-version-command/2-47/2-47-workspace-command-1791405719721-unpin-new-ai-chat.command';+import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';+import { WorkspaceMigrationModule } from 'src/engine/workspace-manager/workspace-migration/workspace-migration.module';++@Module({+ imports: [+ WorkspaceCacheModule,+ WorkspaceIteratorModule,+ WorkspaceMigrationModule,+ ],+ providers: [UnpinNewAiChatCommand],+})+export class V2_47_UpgradeVersionCommandModule {}diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-47/2-47-workspace-command-1791405719721-unpin-new-ai-chat.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-47/2-47-workspace-command-1791405719721-unpin-new-ai-chat.command.tsnew file mode 100644index 00000000000..726f6df0ee3--- /dev/null+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-47/2-47-workspace-command-1791405719721-unpin-new-ai-chat.command.ts@@ -0,0 +1,96 @@+import { Command } from 'nest-commander';+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';+import { isDefined } from 'twenty-shared/utils';++import { ProvisionedWorkspaceCommandRunner } from 'src/database/commands/command-runners/provisioned-workspace.command-runner';+import { WorkspaceIteratorService } from 'src/database/commands/command-runners/workspace-iterator.service';+import { type RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspace.command-runner';+import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';+import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';+import { WorkspaceMigrationBuilderException } from 'src/engine/workspace-manager/workspace-migration/exceptions/workspace-migration-builder-exception';+import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';++const NEW_AI_CHAT_UNIVERSAL_IDENTIFIER = '604bc9b2-e438-4572-bd35-726fa0fb2ec7';++// The inbox triage commands take over the chat header once the inbox ships+// to every workspace+@RegisteredWorkspaceCommand('2.47.0', 1791405719721)+@Command({+ name: 'upgrade:2-47:unpin-new-ai-chat',+ description: 'Unpin New chat from the chat header',+})+export class UnpinNewAiChatCommand extends ProvisionedWorkspaceCommandRunner {+ constructor(+ protected readonly workspaceIteratorService: WorkspaceIteratorService,+ private readonly workspaceCacheService: WorkspaceCacheService,+ private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,+ ) {+ super(workspaceIteratorService);+ }++ override async runOnWorkspace(args: RunOnWorkspaceArgs): Promise<void> {+ await this.up(args);+ }++ async up(args: RunOnWorkspaceArgs): Promise<void> {+ await this.setNewAiChatPinned(args, false);+ }++ async down(args: RunOnWorkspaceArgs): Promise<void> {+ await this.setNewAiChatPinned(args, true);+ }++ private async setNewAiChatPinned(+ { workspaceId, options }: RunOnWorkspaceArgs,+ isPinned: boolean,+ ): Promise<void> {+ const { flatCommandMenuItemMaps } =+ await this.workspaceCacheService.getOrRecompute(workspaceId, [+ 'flatCommandMenuItemMaps',+ ]);++ const newAiChat =+ flatCommandMenuItemMaps.byUniversalIdentifier[+ NEW_AI_CHAT_UNIVERSAL_IDENTIFIER+ ];++ if (!isDefined(newAiChat) || newAiChat.isPinned === isPinned) {+ return;+ }++ this.logger.log(+ `${options.dryRun ? '[DRY RUN] ' : ''}Workspace ${workspaceId}: ${isPinned ? 'pinning' : 'unpinning'} New chat`,+ );++ if (options.dryRun) {+ return;+ }++ const result =+ await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(+ {+ workspaceId,+ isSystemBuild: true,+ applicationUniversalIdentifier:+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,+ allFlatEntityOperationByMetadataName: {+ commandMenuItem: {+ flatEntityToCreate: [],+ flatEntityToDelete: [],+ flatEntityToUpdate: [+ {+ ...newAiChat,+ isPinned,+ updatedAt: new Date().toISOString(),+ },+ ],+ },+ },+ },+ );++ if (result.status === 'fail') {+ throw new WorkspaceMigrationBuilderException(result);+ }+ }+}diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/workspace-command-provider.module.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/workspace-command-provider.module.tsindex f3c07a4af9e..debe2a5d4f3 100644--- a/packages/twenty-server/src/database/commands/upgrade-version-command/workspace-command-provider.module.ts+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/workspace-command-provider.module.ts@@ -39,6 +39,7 @@ import { V2_42_UpgradeVersionCommandModule } from 'src/database/commands/upgradeimport { V2_44_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/2-44/2-44-upgrade-version-command.module';import { V2_45_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/2-45/2-45-upgrade-version-command.module';import { V2_46_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/2-46/2-46-upgrade-version-command.module';+import { V2_47_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/2-47/2-47-upgrade-version-command.module';import { V2_4_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/2-4/2-4-upgrade-version-command.module';import { V2_5_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/2-5/2-5-upgrade-version-command.module';import { V2_7_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/2-7/2-7-upgrade-version-command.module';@@ -91,6 +92,7 @@ import { V2_9_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-V2_44_UpgradeVersionCommandModule,V2_45_UpgradeVersionCommandModule,V2_46_UpgradeVersionCommandModule,+ V2_47_UpgradeVersionCommandModule,],})export class WorkspaceCommandProviderModule {}diff --git a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/utils/seed-feature-flags.util.ts b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/utils/seed-feature-flags.util.tsindex 3c57426b497..58fb84bf8ee 100644--- a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/utils/seed-feature-flags.util.ts+++ b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/core/utils/seed-feature-flags.util.ts@@ -14,6 +14,7 @@ const DEFAULT_SEEDED_FEATURE_FLAGS: Partial<Record<FeatureFlagKey, boolean>> = {[FeatureFlagKey.IS_RECORD_LEVEL_SHARING_ENABLED]: false,[FeatureFlagKey.IS_WORKFLOW_SEND_CHAT_MESSAGE_ENABLED]: true,[FeatureFlagKey.IS_CALENDAR_SYNC_SKIP_UNCHANGED_RECORDS_ENABLED]: true,+ [FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED]: true,};type SeedFeatureFlagsArgs = {diff --git a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/__tests__/standard-ai-chat-inbox-command-menu-items.spec.ts b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/__tests__/standard-ai-chat-inbox-command-menu-items.spec.tsindex db447b18233..28c6d4973be 100644--- a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/__tests__/standard-ai-chat-inbox-command-menu-items.spec.ts+++ b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/__tests__/standard-ai-chat-inbox-command-menu-items.spec.ts@@ -18,6 +18,7 @@ const getAvailableInboxCommands = (...scopes: InboxScope[]) =>{numberOfSelectedRecords: scopes.length,permissionFlags: { AI: true },+ featureFlags: { IS_AI_CHAT_INBOX_ENABLED: true },selectedRecords: scopes.map((scope, index) => ({id: `thread-${index}`,deletedAt: null,@@ -41,6 +42,7 @@ const getAvailableSubscriptionCommands = ({numberOfSelectedRecords: subscriptions.length,permissionFlags: { AI: true },+ featureFlags: { IS_AI_CHAT_INBOX_ENABLED: true },selectedRecords: subscriptions.map((subscription, index) => ({id: `thread-${index}`,deletedAt: null,@@ -57,6 +59,43 @@ const getAvailableSubscriptionCommands = ();describe('AI chat inbox command menu items', () => {+ it('offers nothing while the inbox feature flag is off', () => {+ const availableCommandMenuItemNames = (+ [+ ...INBOX_COMMAND_MENU_ITEM_NAMES,+ ...SUBSCRIPTION_COMMAND_MENU_ITEM_NAMES,+ 'markAiChatAsRead',+ 'markAiChatAsUnread',+ 'assignAiChat',+ ] as const+ ).filter((name) =>+ evaluateConditionalAvailabilityExpression(+ STANDARD_COMMAND_MENU_ITEMS[name].conditionalAvailabilityExpression,+ {+ numberOfSelectedRecords: 1,+ permissionFlags: { AI: true },+ featureFlags: { IS_AI_CHAT_INBOX_ENABLED: false },+ selectedRecords: [+ {+ id: 'thread-0',+ deletedAt: null,+ inboxStatus: {+ scope: 'INBOX',+ isUnread: true,+ isSubscribed: true,+ isAssignedToMe: false,+ event: null,+ },+ recordPermissions: { canUpdate: true },+ },+ ],+ },+ ),+ );++ expect(availableCommandMenuItemNames).toEqual([]);+ });+it('offers done and snooze on an open chat', () => {expect(getAvailableInboxCommands('INBOX')).toEqual(['markAiChatAsDone',diff --git a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant.ts b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant.tsindex cde1b2a7580..0edcd6a5cdb 100644--- a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant.ts+++ b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant.ts@@ -903,7 +903,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {msg({ message: `New chat`, context: 'commandMenuItem.label' }),),icon: 'IconMessageCirclePlus',- isPinned: false,+ isPinned: true,position: 43,shortLabel: i18nLabel(msg({ message: `New chat`, context: 'commandMenuItem.shortLabel' }),@@ -953,7 +953,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {),availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,conditionalAvailabilityExpression:- 'numberOfSelectedRecords >= 1 and permissionFlags.AI and noneDefined(selectedRecords, "deletedAt") and every(selectedRecords, "inboxStatus.isUnread")',+ 'numberOfSelectedRecords >= 1 and permissionFlags.AI and featureFlags.IS_AI_CHAT_INBOX_ENABLED and noneDefined(selectedRecords, "deletedAt") and every(selectedRecords, "inboxStatus.isUnread")',availabilityObjectMetadataUniversalIdentifier:STANDARD_OBJECTS.agentChatThread.universalIdentifier,frontComponentUniversalIdentifier: null,@@ -973,7 +973,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {),availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,conditionalAvailabilityExpression:- 'numberOfSelectedRecords >= 1 and permissionFlags.AI and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.isUnread", false)',+ 'numberOfSelectedRecords >= 1 and permissionFlags.AI and featureFlags.IS_AI_CHAT_INBOX_ENABLED and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.isUnread", false)',availabilityObjectMetadataUniversalIdentifier:STANDARD_OBJECTS.agentChatThread.universalIdentifier,frontComponentUniversalIdentifier: null,@@ -993,7 +993,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {),availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,conditionalAvailabilityExpression:- 'numberOfSelectedRecords >= 1 and permissionFlags.AI and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.scope", "INBOX")',+ 'numberOfSelectedRecords >= 1 and permissionFlags.AI and featureFlags.IS_AI_CHAT_INBOX_ENABLED and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.scope", "INBOX")',availabilityObjectMetadataUniversalIdentifier:STANDARD_OBJECTS.agentChatThread.universalIdentifier,frontComponentUniversalIdentifier: null,@@ -1013,7 +1013,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {),availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,conditionalAvailabilityExpression:- 'numberOfSelectedRecords >= 1 and permissionFlags.AI and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.scope", "ARCHIVED")',+ 'numberOfSelectedRecords >= 1 and permissionFlags.AI and featureFlags.IS_AI_CHAT_INBOX_ENABLED and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.scope", "ARCHIVED")',availabilityObjectMetadataUniversalIdentifier:STANDARD_OBJECTS.agentChatThread.universalIdentifier,frontComponentUniversalIdentifier: null,@@ -1033,7 +1033,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {),availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,conditionalAvailabilityExpression:- 'numberOfSelectedRecords >= 1 and permissionFlags.AI and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.scope", "SNOOZED")',+ 'numberOfSelectedRecords >= 1 and permissionFlags.AI and featureFlags.IS_AI_CHAT_INBOX_ENABLED and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.scope", "SNOOZED")',availabilityObjectMetadataUniversalIdentifier:STANDARD_OBJECTS.agentChatThread.universalIdentifier,frontComponentUniversalIdentifier: null,@@ -1053,7 +1053,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {),availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,conditionalAvailabilityExpression:- 'numberOfSelectedRecords >= 1 and permissionFlags.AI and noneDefined(selectedRecords, "deletedAt") and everyDefined(selectedRecords, "inboxStatus") and noneEquals(selectedRecords, "inboxStatus.scope", "SNOOZED")',+ 'numberOfSelectedRecords >= 1 and permissionFlags.AI and featureFlags.IS_AI_CHAT_INBOX_ENABLED and noneDefined(selectedRecords, "deletedAt") and everyDefined(selectedRecords, "inboxStatus") and noneEquals(selectedRecords, "inboxStatus.scope", "SNOOZED")',availabilityObjectMetadataUniversalIdentifier:STANDARD_OBJECTS.agentChatThread.universalIdentifier,frontComponentUniversalIdentifier: null,@@ -1073,7 +1073,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {),availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,conditionalAvailabilityExpression:- 'numberOfSelectedRecords >= 1 and permissionFlags.AI and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.isSubscribed", false)',+ 'numberOfSelectedRecords >= 1 and permissionFlags.AI and featureFlags.IS_AI_CHAT_INBOX_ENABLED and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.isSubscribed", false)',availabilityObjectMetadataUniversalIdentifier:STANDARD_OBJECTS.agentChatThread.universalIdentifier,frontComponentUniversalIdentifier: null,@@ -1093,7 +1093,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {),availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,conditionalAvailabilityExpression:- 'numberOfSelectedRecords >= 1 and permissionFlags.AI and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.isSubscribed", true) and noneEquals(selectedRecords, "inboxStatus.isAssignedToMe", true)',+ 'numberOfSelectedRecords >= 1 and permissionFlags.AI and featureFlags.IS_AI_CHAT_INBOX_ENABLED and noneDefined(selectedRecords, "deletedAt") and everyEquals(selectedRecords, "inboxStatus.isSubscribed", true) and noneEquals(selectedRecords, "inboxStatus.isAssignedToMe", true)',availabilityObjectMetadataUniversalIdentifier:STANDARD_OBJECTS.agentChatThread.universalIdentifier,frontComponentUniversalIdentifier: null,@@ -1113,7 +1113,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {),availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,conditionalAvailabilityExpression:- 'numberOfSelectedRecords >= 1 and permissionFlags.AI and noneDefined(selectedRecords, "deletedAt") and noneEquals(selectedRecords, "recordPermissions.canUpdate", false)',+ 'numberOfSelectedRecords >= 1 and permissionFlags.AI and featureFlags.IS_AI_CHAT_INBOX_ENABLED and noneDefined(selectedRecords, "deletedAt") and noneEquals(selectedRecords, "recordPermissions.canUpdate", false)',availabilityObjectMetadataUniversalIdentifier:STANDARD_OBJECTS.agentChatThread.universalIdentifier,frontComponentUniversalIdentifier: null,diff --git a/packages/twenty-shared/src/types/FeatureFlagKey.ts b/packages/twenty-shared/src/types/FeatureFlagKey.tsindex e729db1e7c8..9fe433dbef6 100644--- a/packages/twenty-shared/src/types/FeatureFlagKey.ts+++ b/packages/twenty-shared/src/types/FeatureFlagKey.ts@@ -17,4 +17,5 @@ export enum FeatureFlagKey {IS_WORKFLOW_SEND_CHAT_MESSAGE_ENABLED = 'IS_WORKFLOW_SEND_CHAT_MESSAGE_ENABLED',IS_CALENDAR_SYNC_SKIP_UNCHANGED_RECORDS_ENABLED = 'IS_CALENDAR_SYNC_SKIP_UNCHANGED_RECORDS_ENABLED',IS_RECORD_SHARE_VISIBILITY_GATING_ENABLED = 'IS_RECORD_SHARE_VISIBILITY_GATING_ENABLED',+ IS_AI_CHAT_INBOX_ENABLED = 'IS_AI_CHAT_INBOX_ENABLED',}