Skip to content

The open alternative to Salesforce, designed for AI.

Mount AI Overview behind the inbox flag (#29322)

Raphaël Bosi1f09e7fd5473
diff --git a/packages/twenty-front/src/modules/settings/ai/constants/SettingsAiTabs.ts b/packages/twenty-front/src/modules/settings/ai/constants/SettingsAiTabs.ts
index 539a9680816..0e46a528041 100644
--- a/packages/twenty-front/src/modules/settings/ai/constants/SettingsAiTabs.ts
+++ b/packages/twenty-front/src/modules/settings/ai/constants/SettingsAiTabs.ts
@@ -1,6 +1,7 @@
export const SETTINGS_AI_TABS = {
COMPONENT_INSTANCE_ID: 'settings-ai-tab-list',
TABS_IDS: {
+ OVERVIEW: 'overview',
MCP: 'mcp',
MODELS: 'models',
SKILLS: 'skills',
diff --git a/packages/twenty-front/src/modules/settings/ai/utils/getSettingsAiModelsSectionVisibility.ts b/packages/twenty-front/src/modules/settings/ai/utils/getSettingsAiModelsSectionVisibility.ts
new file mode 100644
index 00000000000..33add1c0714
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/ai/utils/getSettingsAiModelsSectionVisibility.ts
@@ -0,0 +1,10 @@
+export const getSettingsAiModelsSectionVisibility = ({
+ isInboxEnabled,
+ canReadSystemPrompts,
+}: {
+ isInboxEnabled: boolean;
+ canReadSystemPrompts: boolean;
+}) => ({
+ isWorkspaceInstructionsSectionVisible: !isInboxEnabled,
+ isSystemPromptsSectionVisible: !isInboxEnabled && canReadSystemPrompts,
+});
diff --git a/packages/twenty-front/src/modules/settings/ai/utils/getSettingsAiTabs.ts b/packages/twenty-front/src/modules/settings/ai/utils/getSettingsAiTabs.ts
new file mode 100644
index 00000000000..7830915de27
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/ai/utils/getSettingsAiTabs.ts
@@ -0,0 +1,47 @@
+import { SETTINGS_AI_TABS } from '@/settings/ai/constants/SettingsAiTabs';
+import { t } from '@lingui/core/macro';
+import {
+ IconBook,
+ IconChartBar,
+ IconCpu,
+ IconLayoutDashboard,
+ IconSparkles,
+ IconTool,
+} from 'twenty-ui/icon';
+
+export const getSettingsAiTabs = (isInboxEnabled: boolean) => [
+ ...(isInboxEnabled
+ ? [
+ {
+ id: SETTINGS_AI_TABS.TABS_IDS.OVERVIEW,
+ title: t`Overview`,
+ Icon: IconLayoutDashboard,
+ },
+ ]
+ : []),
+ {
+ id: SETTINGS_AI_TABS.TABS_IDS.MCP,
+ title: t`MCP`,
+ Icon: IconSparkles,
+ },
+ {
+ id: SETTINGS_AI_TABS.TABS_IDS.MODELS,
+ title: t`Models`,
+ Icon: IconCpu,
+ },
+ {
+ id: SETTINGS_AI_TABS.TABS_IDS.SKILLS,
+ title: t`Skills`,
+ Icon: IconBook,
+ },
+ {
+ id: SETTINGS_AI_TABS.TABS_IDS.TOOLS,
+ title: t`Tools`,
+ Icon: IconTool,
+ },
+ {
+ id: SETTINGS_AI_TABS.TABS_IDS.USAGE,
+ title: t`Usage`,
+ Icon: IconChartBar,
+ },
+];
diff --git a/packages/twenty-front/src/pages/settings/ai/SettingsAI.tsx b/packages/twenty-front/src/pages/settings/ai/SettingsAI.tsx
index 67adc36d4a6..6fb4ec8f033 100644
--- a/packages/twenty-front/src/pages/settings/ai/SettingsAI.tsx
+++ b/packages/twenty-front/src/pages/settings/ai/SettingsAI.tsx
@@ -1,24 +1,19 @@
import { NavigationButton } from '@/ui/input/components/NavigationButton';
+import { getSettingsAiTabs } from '@/settings/ai/utils/getSettingsAiTabs';
import { SettingsDiscoveryHeroCard } from '@/settings/components/SettingsDiscoveryHeroCard';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
import { SettingsTabBar } from '@/settings/components/layout/SettingsTabBar';
import { useSettingsActiveTabId } from '@/settings/components/layout/useSettingsActiveTabId';
+import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { SettingsPath } from 'twenty-shared/types';
import { getSettingsPath } from 'twenty-shared/utils';
import { t } from '@lingui/core/macro';
import { Section } from 'twenty-ui/components/layout';
-import {
- IconBook,
- IconChartBar,
- IconCpu,
- IconPlus,
- IconSparkle2,
- IconSparkles,
- IconTool,
-} from 'twenty-ui/icon';
+import { IconPlus, IconSparkle2 } from 'twenty-ui/icon';
import { Button } from 'twenty-ui/primitives/input';
import { SettingsAgentSkillsTab } from '~/pages/settings/ai/components/SettingsAgentSkillsTab';
import { SettingsAgentToolsTab } from '~/pages/settings/ai/components/SettingsAgentToolsTab';
@@ -29,6 +24,14 @@ import McpCoverDark from '@/settings/mcp/assets/mcp-cover-dark.png';
import McpCoverLight from '@/settings/mcp/assets/mcp-cover-light.png';
import { SettingsMcpSetup } from '@/settings/mcp/components/SettingsMcpSetup';
import { useCreateTool } from '~/pages/settings/ai/hooks/useCreateTool';
+import { SettingsAiOverview } from '~/pages/settings/ai/components/SettingsAiOverview';
+import { SettingsAiMcpSection } from '~/pages/settings/ai/components/SettingsAiMcpSection';
+import { SettingsAiWorkspaceInstructionsSection } from '~/pages/settings/ai/components/SettingsAiWorkspaceInstructionsSection';
+import { SettingsAiSystemPromptsSection } from '~/pages/settings/ai/components/SettingsAiSystemPromptsSection';
+import {
+ FeatureFlagKey,
+ PermissionFlagType,
+} from '~/generated-metadata/graphql';
const AI_HERO_LIGHT = '/images/ai/ai-tools-cover-light.png';
const AI_HERO_DARK = '/images/ai/ai-tools-cover-dark.png';
@@ -37,56 +40,49 @@ const SETTINGS_AI_HERO_INSTANCE_ID_PREFIX = 'settings-ai-hero';
export const SettingsAI = () => {
const { handleCreateTool, isCreatingTool } = useCreateTool();
+ const canReadSystemPrompts = useHasPermissionFlag(PermissionFlagType.AI);
+ const isInboxEnabled = useIsFeatureEnabled(
+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,
+ );
+ const tabs = getSettingsAiTabs(isInboxEnabled);
+ const activeTabId = useSettingsActiveTabId(
+ SETTINGS_AI_TABS.COMPONENT_INSTANCE_ID,
+ tabs.map((tab) => tab.id),
+ );
+ const isOverviewTab = activeTabId === SETTINGS_AI_TABS.TABS_IDS.OVERVIEW;
+ const isMcpTab = activeTabId === SETTINGS_AI_TABS.TABS_IDS.MCP;
+ const isModelsTab = activeTabId === SETTINGS_AI_TABS.TABS_IDS.MODELS;
+ const isSkillsTab = activeTabId === SETTINGS_AI_TABS.TABS_IDS.SKILLS;
+ const isToolsTab = activeTabId === SETTINGS_AI_TABS.TABS_IDS.TOOLS;
+ const isUsageTab = activeTabId === SETTINGS_AI_TABS.TABS_IDS.USAGE;
- const tabs = [
- {
- id: SETTINGS_AI_TABS.TABS_IDS.MCP,
- title: t`MCP`,
- Icon: IconSparkles,
- },
- {
- id: SETTINGS_AI_TABS.TABS_IDS.MODELS,
- title: t`Models`,
- Icon: IconCpu,
- },
- {
- id: SETTINGS_AI_TABS.TABS_IDS.SKILLS,
- title: t`Skills`,
- Icon: IconBook,
- },
- {
- id: SETTINGS_AI_TABS.TABS_IDS.TOOLS,
- title: t`Tools`,
- Icon: IconTool,
- },
- {
- id: SETTINGS_AI_TABS.TABS_IDS.USAGE,
- title: t`Usage`,
- Icon: IconChartBar,
- },
- ];
+ const secondaryBar = (
+ <SettingsTabBar
+ aria-label={t`AI settings`}
+ tabs={tabs}
+ componentInstanceId={SETTINGS_AI_TABS.COMPONENT_INSTANCE_ID}
+ />
+ );
- const resolvedTabId =
- useSettingsActiveTabId(
- SETTINGS_AI_TABS.COMPONENT_INSTANCE_ID,
- tabs.map((tab) => tab.id),
- ) ?? SETTINGS_AI_TABS.TABS_IDS.MCP;
- const isMcpTab = resolvedTabId === SETTINGS_AI_TABS.TABS_IDS.MCP;
- const isModelsTab = resolvedTabId === SETTINGS_AI_TABS.TABS_IDS.MODELS;
- const isSkillsTab = resolvedTabId === SETTINGS_AI_TABS.TABS_IDS.SKILLS;
- const isToolsTab = resolvedTabId === SETTINGS_AI_TABS.TABS_IDS.TOOLS;
- const isUsageTab = resolvedTabId === SETTINGS_AI_TABS.TABS_IDS.USAGE;
+ if (isOverviewTab) {
+ return (
+ <SettingsAiOverview
+ secondaryBar={secondaryBar}
+ mcpSection={<SettingsAiMcpSection />}
+ workspaceInstructionsSection={
+ <SettingsAiWorkspaceInstructionsSection />
+ }
+ systemPromptSection={
+ canReadSystemPrompts ? <SettingsAiSystemPromptsSection /> : null
+ }
+ />
+ );
+ }
return (
<SettingsPageLayout
title={t`AI`}
- secondaryBar={
- <SettingsTabBar
- aria-label={t`AI settings`}
- tabs={tabs}
- componentInstanceId={SETTINGS_AI_TABS.COMPONENT_INSTANCE_ID}
- />
- }
+ secondaryBar={secondaryBar}
actionButton={
isSkillsTab ? (
<NavigationButton
diff --git a/packages/twenty-front/src/pages/settings/ai/components/SettingsAiBehaviorModeSelect.tsx b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiBehaviorModeSelect.tsx
index 12c22f5c8c3..89940904948 100644
--- a/packages/twenty-front/src/pages/settings/ai/components/SettingsAiBehaviorModeSelect.tsx
+++ b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiBehaviorModeSelect.tsx
@@ -2,11 +2,11 @@ import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
import { isDefined } from 'twenty-shared/utils';
import { Select } from 'twenty-ui/primitives/input';
-import { type SettingsAiAssistantMode } from '~/pages/settings/ai/types/SettingsAiAssistantMode';
+import { AiChatAssistantMode } from '~/generated-metadata/graphql';
type SettingsAiBehaviorModeSelectProps = {
- value: SettingsAiAssistantMode | null;
- onChange: (value: SettingsAiAssistantMode) => void;
+ value: AiChatAssistantMode | null;
+ onChange: (value: AiChatAssistantMode) => void;
labelledBy: string;
describedBy: string;
disabled: boolean;
@@ -26,15 +26,15 @@ export const SettingsAiBehaviorModeSelect = ({
disabled,
isLoading,
}: SettingsAiBehaviorModeSelectProps) => {
- const options: { value: SettingsAiAssistantMode; label: string }[] = [
- { value: 'NEVER', label: t`Never` },
- { value: 'MENTION_ONLY', label: t`Only when mentioned` },
- { value: 'AUTOMATIC', label: t`Auto` },
+ const options: { value: AiChatAssistantMode; label: string }[] = [
+ { value: AiChatAssistantMode.NEVER, label: t`Never` },
+ { value: AiChatAssistantMode.MENTION_ONLY, label: t`Only when mentioned` },
+ { value: AiChatAssistantMode.AUTOMATIC, label: t`Auto` },
];
return (
<StyledSelectContainer>
- <Select.Root<SettingsAiAssistantMode>
+ <Select.Root<AiChatAssistantMode>
items={options}
value={isLoading ? null : value}
onValueChange={(nextValue, eventDetails) => {
diff --git a/packages/twenty-front/src/pages/settings/ai/components/SettingsAiBehaviorSection.tsx b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiBehaviorSection.tsx
index e6d1cafc530..98dcf24c4b7 100644
--- a/packages/twenty-front/src/pages/settings/ai/components/SettingsAiBehaviorSection.tsx
+++ b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiBehaviorSection.tsx
@@ -13,15 +13,15 @@ import { Card } from 'twenty-ui/primitives/surfaces';
import { Text } from 'twenty-ui/primitives/typography';
import { themeCssVariables } from 'twenty-ui/theme';
import { SettingsAiBehaviorModeSelect } from '~/pages/settings/ai/components/SettingsAiBehaviorModeSelect';
-import { type SettingsAiAssistantMode } from '~/pages/settings/ai/types/SettingsAiAssistantMode';
+import { type AiChatAssistantMode } from '~/generated-metadata/graphql';
const BEHAVIOR_SELECT_CONTROL_WIDTH = 180;
type SettingsAiBehaviorSectionProps = {
- directMessageMode: SettingsAiAssistantMode | null;
- inboxMode: SettingsAiAssistantMode | null;
- onDirectMessageModeChange: (value: SettingsAiAssistantMode) => void;
- onInboxModeChange: (value: SettingsAiAssistantMode) => void;
+ directMessageMode: AiChatAssistantMode | null;
+ inboxMode: AiChatAssistantMode | null;
+ onDirectMessageModeChange: (value: AiChatAssistantMode) => void;
+ onInboxModeChange: (value: AiChatAssistantMode) => void;
isLoading?: boolean;
disabled?: boolean;
errorMessage?: string;
diff --git a/packages/twenty-front/src/pages/settings/ai/components/SettingsAiMcpSection.tsx b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiMcpSection.tsx
new file mode 100644
index 00000000000..c85f39aa8da
--- /dev/null
+++ b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiMcpSection.tsx
@@ -0,0 +1,31 @@
+import { SETTINGS_AI_TABS } from '@/settings/ai/constants/SettingsAiTabs';
+import { SettingsCard } from '@/settings/components/SettingsCard';
+import { t } from '@lingui/core/macro';
+import { SettingsPath } from 'twenty-shared/types';
+import { getSettingsPath } from 'twenty-shared/utils';
+import { Section } from 'twenty-ui/components/layout';
+import { IconSparkles } from 'twenty-ui/icon';
+import { useTheme } from 'twenty-ui/theme';
+
+export const SettingsAiMcpSection = () => {
+ const theme = useTheme();
+
+ return (
+ <Section.Root>
+ <Section.Header
+ title={t`MCP Server`}
+ description={t`Connect AI assistants like Claude or Cursor to your workspace via the Model Context Protocol`}
+ />
+ <SettingsCard
+ Icon={<IconSparkles size={theme.icon.size.xl} />}
+ title={t`Set up MCP`}
+ to={getSettingsPath(
+ SettingsPath.AI,
+ undefined,
+ undefined,
+ SETTINGS_AI_TABS.TABS_IDS.MCP,
+ )}
+ />
+ </Section.Root>
+ );
+};
diff --git a/packages/twenty-front/src/pages/settings/ai/components/SettingsAiModelsTab.tsx b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiModelsTab.tsx
index df791e30468..07bf9a69d18 100644
--- a/packages/twenty-front/src/pages/settings/ai/components/SettingsAiModelsTab.tsx
+++ b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiModelsTab.tsx
@@ -13,19 +13,37 @@ import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { aiModelsState } from '@/client-config/states/aiModelsState';
import { AiModelPinSelect } from '@/ai/components/AiModelPinSelect';
import { getAiModelModeDescription } from '@/ai/utils/getAiModelModeDescription';
+import { getSettingsAiModelsSectionVisibility } from '@/settings/ai/utils/getSettingsAiModelsSectionVisibility';
import { NestedSettingsRow } from '@/settings/components/SettingsOptions/NestedSettingsRow';
import { SettingsOptionCardContentSelect } from '@/settings/components/SettingsOptions/SettingsOptionCardContentSelect';
import { SettingsOptionCardContentSwitch } from '@/settings/components/SettingsOptions/SettingsOptionCardContentSwitch';
import { StyledSettingsSelectGroup } from '@/settings/components/SettingsOptions/StyledSettingsSelectGroup';
+import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
import { Select } from '@/ui/input/components/Select';
import { GenericDropdownContentWidth } from '@/ui/layout/dropdown/constants/GenericDropdownContentWidth';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
+import {
+ FeatureFlagKey,
+ PermissionFlagType,
+} from '~/generated-metadata/graphql';
import { SettingsAiModelTiersPreview } from '~/pages/settings/ai/components/SettingsAiModelTiersPreview';
import { SettingsAiSystemPromptsSection } from '~/pages/settings/ai/components/SettingsAiSystemPromptsSection';
import { SettingsAiWorkspaceInstructionsSection } from '~/pages/settings/ai/components/SettingsAiWorkspaceInstructionsSection';
import { useSettingsAiModelsActions } from '~/pages/settings/ai/hooks/useSettingsAiModelsActions';
export const SettingsAiModelsTab = () => {
+ const isInboxEnabled = useIsFeatureEnabled(
+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,
+ );
+ const canReadSystemPrompts = useHasPermissionFlag(PermissionFlagType.AI);
+ const {
+ isWorkspaceInstructionsSectionVisible,
+ isSystemPromptsSectionVisible,
+ } = getSettingsAiModelsSectionVisibility({
+ isInboxEnabled,
+ canReadSystemPrompts,
+ });
const currentWorkspace = useAtomStateValue(currentWorkspaceState);
const aiModels = useAtomStateValue(aiModelsState);
const tiers = useAiModelTiers();
@@ -126,8 +144,10 @@ export const SettingsAiModelsTab = () => {
</Section.Root>
<SettingsAiModelTiersPreview />
- <SettingsAiWorkspaceInstructionsSection />
- <SettingsAiSystemPromptsSection />
+ {isWorkspaceInstructionsSectionVisible && (
+ <SettingsAiWorkspaceInstructionsSection />
+ )}
+ {isSystemPromptsSectionVisible && <SettingsAiSystemPromptsSection />}
</>
);
};
diff --git a/packages/twenty-front/src/pages/settings/ai/components/SettingsAiWorkspaceInstructionsSection.tsx b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiWorkspaceInstructionsSection.tsx
index 376bf03a697..26cc548d481 100644
--- a/packages/twenty-front/src/pages/settings/ai/components/SettingsAiWorkspaceInstructionsSection.tsx
+++ b/packages/twenty-front/src/pages/settings/ai/components/SettingsAiWorkspaceInstructionsSection.tsx
@@ -2,6 +2,7 @@ import { FormAdvancedTextFieldInput } from '@/advanced-text-editor/components/Fo
import { AI_INSTRUCTIONS_EDITOR_PROFILE } from '@/ai/constants/AiInstructionsEditorProfile';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { getToastOptionsFromError } from '@/error-handler/utils/getToastOptionsFromError';
+import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
import { CombinedGraphQLErrors } from '@apollo/client';
import { useMutation } from '@apollo/client/react';
@@ -12,7 +13,11 @@ import { useToast } from 'twenty-ui/components/feedback';
import { Section } from 'twenty-ui/components/layout';
import { themeCssVariables } from 'twenty-ui/theme';
import { useDebouncedCallback } from 'use-debounce';
-import { UpdateWorkspaceDocument } from '~/generated-metadata/graphql';
+import { isDefined } from 'twenty-shared/utils';
+import {
+ PermissionFlagType,
+ UpdateWorkspaceDocument,
+} from '~/generated-metadata/graphql';
const StyledInstructionsContainer = styled.div`
display: flex;
@@ -22,6 +27,9 @@ const StyledInstructionsContainer = styled.div`
export const SettingsAiWorkspaceInstructionsSection = () => {
const { enqueueToast } = useToast();
+ const canEditInstructions = useHasPermissionFlag(
+ PermissionFlagType.WORKSPACE,
+ );
const [currentWorkspace, setCurrentWorkspace] = useAtomState(
currentWorkspaceState,
);
@@ -34,7 +42,13 @@ export const SettingsAiWorkspaceInstructionsSection = () => {
useState(initialInstructions);
const autoSave = useDebouncedCallback(async (newValue: string) => {
- if (!currentWorkspace?.id || newValue === originalInstructions) return;
+ if (
+ !canEditInstructions ||
+ !isDefined(currentWorkspace) ||
+ newValue === originalInstructions
+ ) {
+ return;
+ }
try {
setCurrentWorkspace({
...currentWorkspace,
@@ -71,10 +85,15 @@ export const SettingsAiWorkspaceInstructionsSection = () => {
<StyledInstructionsContainer>
<FormAdvancedTextFieldInput
key={originalInstructions}
- readonly={false}
+ readonly={!canEditInstructions}
+ aria-label={t`Workspace Instructions`}
defaultValue={workspaceInstructions}
profile={AI_INSTRUCTIONS_EDITOR_PROFILE}
onChange={(value) => {
+ if (!canEditInstructions) {
+ return;
+ }
+
setWorkspaceInstructions(value);
autoSave(value);
}}
diff --git a/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiBehavior.stories.tsx b/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiBehavior.stories.tsx
index 4d888ddb6e4..faa03aa4ae7 100644
--- a/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiBehavior.stories.tsx
+++ b/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiBehavior.stories.tsx
@@ -3,6 +3,7 @@ import { Button } from 'twenty-ui/primitives/input';
import { type Meta, type StoryObj } from '@storybook/react-vite';
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
import { ComponentDecorator } from 'twenty-ui/testing';
+import { AiChatAssistantMode } from '~/generated-metadata/graphql';
import { SettingsAiBehaviorExample } from '~/pages/settings/ai/components/__stories__/SettingsAiBehaviorExample';
const meta = {
@@ -11,8 +12,8 @@ const meta = {
decorators: [ComponentDecorator],
parameters: { container: { width: 694 } },
args: {
- directMessageMode: 'MENTION_ONLY',
- inboxMode: 'AUTOMATIC',
+ directMessageMode: AiChatAssistantMode.MENTION_ONLY,
+ inboxMode: AiChatAssistantMode.AUTOMATIC,
onDirectMessageModeChange: fn(),
onInboxModeChange: fn(),
},
@@ -41,7 +42,9 @@ export const IndependentSelection: Story = {
);
await waitFor(() => expect(directMessages).toHaveTextContent('Never'));
await waitFor(() => expect(directMessages).toHaveFocus());
- expect(args.onDirectMessageModeChange).toHaveBeenLastCalledWith('NEVER');
+ expect(args.onDirectMessageModeChange).toHaveBeenLastCalledWith(
+ AiChatAssistantMode.NEVER,
+ );
expect(args.onInboxModeChange).not.toHaveBeenCalled();
expect(inbox).toHaveTextContent('Auto');
@@ -58,7 +61,9 @@ export const IndependentSelection: Story = {
await userEvent.keyboard('{Home}{ArrowDown}{Enter}');
await waitFor(() => expect(inbox).toHaveTextContent('Only when mentioned'));
expect(args.onInboxModeChange).toHaveBeenCalledOnce();
- expect(args.onInboxModeChange).toHaveBeenLastCalledWith('MENTION_ONLY');
+ expect(args.onInboxModeChange).toHaveBeenLastCalledWith(
+ AiChatAssistantMode.MENTION_ONLY,
+ );
expect(directMessages).toHaveTextContent('Never');
await waitFor(() => expect(inbox).toHaveFocus());
@@ -134,7 +139,9 @@ export const FailedChange: Story = {
within(options).getByRole('option', { name: 'Never' }),
);
expect(args.onDirectMessageModeChange).toHaveBeenCalledOnce();
- expect(args.onDirectMessageModeChange).toHaveBeenLastCalledWith('NEVER');
+ expect(args.onDirectMessageModeChange).toHaveBeenLastCalledWith(
+ AiChatAssistantMode.NEVER,
+ );
await waitFor(() =>
expect(directMessages).toHaveTextContent('Only when mentioned'),
);
@@ -162,7 +169,9 @@ export const Narrow: Story = {
);
await waitFor(() => expect(directMessages).toHaveTextContent('Never'));
expect(args.onDirectMessageModeChange).toHaveBeenCalledOnce();
- expect(args.onDirectMessageModeChange).toHaveBeenLastCalledWith('NEVER');
+ expect(args.onDirectMessageModeChange).toHaveBeenLastCalledWith(
+ AiChatAssistantMode.NEVER,
+ );
expect(args.onInboxModeChange).not.toHaveBeenCalled();
await waitFor(() => expect(directMessages).toHaveFocus());
await userEvent.tab();
diff --git a/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiIntegration.stories.tsx b/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiIntegration.stories.tsx
new file mode 100644
index 00000000000..0187da9534c
--- /dev/null
+++ b/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiIntegration.stories.tsx
@@ -0,0 +1,182 @@
+import { SettingsProtectedRouteWrapper } from '@/settings/components/SettingsProtectedRouteWrapper';
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, userEvent, waitFor, within } from 'storybook/test';
+import { PermissionFlagType } from '~/generated-metadata/graphql';
+import { SettingsAI } from '~/pages/settings/ai/SettingsAI';
+import { createSettingsAiIntegrationStoryFixture } from '~/pages/settings/ai/components/__stories__/createSettingsAiIntegrationStoryFixture';
+import {
+ PageDecorator,
+ type PageDecoratorArgs,
+} from '~/testing/decorators/PageDecorator';
+
+const fixture = createSettingsAiIntegrationStoryFixture();
+
+type SettingsAiIntegrationStoryArgs = PageDecoratorArgs & {
+ permissionFlags: PermissionFlagType[];
+ isInboxEnabled: boolean;
+};
+
+const meta = {
+ title: 'Pages/Settings/AI/Integration',
+ component: SettingsAI,
+ decorators: [PageDecorator],
+ args: {
+ routePath: '/settings/ai',
+ routeParams: {},
+ additionalRoutes: ['/settings/profile'],
+ permissionFlags: [
+ PermissionFlagType.AI_SETTINGS,
+ PermissionFlagType.AI,
+ PermissionFlagType.WORKSPACE,
+ ],
+ isInboxEnabled: true,
+ },
+ beforeEach: async ({ args }) => {
+ await fixture.reset({
+ permissionFlags: args.permissionFlags,
+ isInboxEnabled: args.isInboxEnabled,
+ });
+ },
+ parameters: { mockingDate: null, msw: { handlers: fixture.handlers } },
+ render: () => (
+ <SettingsProtectedRouteWrapper
+ settingsPermission={PermissionFlagType.AI_SETTINGS}
+ >
+ <SettingsAI />
+ </SettingsProtectedRouteWrapper>
+ ),
+} satisfies Meta<SettingsAiIntegrationStoryArgs>;
+
+export default meta;
+type Story = StoryObj<SettingsAiIntegrationStoryArgs>;
+
+export const OverviewNavigationAndInstructionsPersistence: Story = {
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const overview = await canvas.findByRole('link', {
+ name: 'Overview',
+ });
+
+ await waitFor(() =>
+ expect(overview).toHaveAttribute('aria-current', 'page'),
+ );
+ expect(canvas.getByRole('heading', { name: 'MCP Server' })).toBeVisible();
+ expect(
+ canvas.queryByRole('heading', { name: 'Behavior' }),
+ ).not.toBeInTheDocument();
+ expect(
+ canvas.queryByRole('heading', { name: 'Avatar' }),
+ ).not.toBeInTheDocument();
+
+ const instructions = await canvas.findByRole('textbox', {
+ name: 'Workspace Instructions',
+ });
+ expect(instructions).toHaveAttribute('contenteditable', 'true');
+ await userEvent.type(instructions, 'Use concise replies.');
+ expect(fixture.saveInstructions).not.toHaveBeenCalled();
+
+ await waitFor(
+ () => expect(fixture.saveInstructions).toHaveBeenCalledOnce(),
+ { timeout: 3000 },
+ );
+ expect(fixture.saveInstructions).toHaveBeenCalledWith({
+ aiAdditionalInstructions: expect.stringContaining('Use concise replies.'),
+ });
+
+ await userEvent.click(canvas.getByRole('link', { name: 'Models' }));
+ await canvas.findByRole('heading', { name: 'Models' });
+ expect(
+ canvas.queryByRole('heading', {
+ name: 'Workspace Instructions',
+ }),
+ ).not.toBeInTheDocument();
+ expect(
+ canvas.queryByRole('heading', { name: 'System Prompt' }),
+ ).not.toBeInTheDocument();
+
+ await userEvent.click(canvas.getByRole('link', { name: 'Overview' }));
+ expect(
+ await canvas.findByRole('textbox', { name: 'Workspace Instructions' }),
+ ).toHaveTextContent('Use concise replies.');
+ expect(fixture.saveInstructions).toHaveBeenCalledOnce();
+
+ await userEvent.click(canvas.getByRole('link', { name: 'Set up MCP' }));
+ await waitFor(() =>
+ expect(canvas.getByRole('link', { name: 'MCP' })).toHaveAttribute(
+ 'aria-current',
+ 'page',
+ ),
+ );
+ expect(
+ canvas.queryByRole('heading', {
+ name: 'Workspace Instructions',
+ }),
+ ).not.toBeInTheDocument();
+ await userEvent.click(canvas.getByRole('link', { name: 'Overview' }));
+ expect(
+ await canvas.findByRole('textbox', { name: 'Workspace Instructions' }),
+ ).toHaveTextContent('Use concise replies.');
+ },
+};
+
+export const LegacyTabsWithoutInbox: Story = {
+ args: { isInboxEnabled: false, routeHash: '#overview' },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const mcp = await canvas.findByRole('link', { name: 'MCP' });
+
+ await waitFor(() => expect(mcp).toHaveAttribute('aria-current', 'page'));
+ expect(
+ canvas.queryByRole('link', { name: 'Overview' }),
+ ).not.toBeInTheDocument();
+ expect(
+ canvas.queryByRole('heading', { name: 'Behavior' }),
+ ).not.toBeInTheDocument();
+ await userEvent.click(canvas.getByRole('link', { name: 'Models' }));
+ expect(
+ await canvas.findByRole('textbox', { name: 'Workspace Instructions' }),
+ ).toHaveAttribute('contenteditable', 'true');
+ expect(
+ canvas.getByRole('heading', { name: 'System Prompt' }),
+ ).toBeVisible();
+ },
+};
+
+export const SettingsPermissionDenied: Story = {
+ args: {
+ permissionFlags: [PermissionFlagType.AI, PermissionFlagType.WORKSPACE],
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(
+ await canvas.findByText('Navigated to /settings/profile'),
+ ).toBeVisible();
+ expect(
+ canvas.queryByRole('textbox', { name: 'Workspace Instructions' }),
+ ).not.toBeInTheDocument();
+ expect(fixture.loadSystemPrompts).not.toHaveBeenCalled();
+ expect(fixture.saveInstructions).not.toHaveBeenCalled();
+ },
+};
+
+export const ReadOnlyInstructionsWithoutAiAccess: Story = {
+ args: { permissionFlags: [PermissionFlagType.AI_SETTINGS] },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const instructions = await canvas.findByRole('textbox', {
+ name: 'Workspace Instructions',
+ });
+
+ expect(instructions).toHaveAttribute('contenteditable', 'false');
+ expect(canvas.getByRole('link', { name: 'Set up MCP' })).toBeVisible();
+ expect(
+ canvas.queryByRole('link', { name: 'Read system prompts' }),
+ ).not.toBeInTheDocument();
+ expect(
+ canvas.queryByRole('button', { name: 'Expand to full screen' }),
+ ).not.toBeInTheDocument();
+ expect(fixture.loadSystemPrompts).not.toHaveBeenCalled();
+ expect(fixture.saveInstructions).not.toHaveBeenCalled();
+ },
+};
diff --git a/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiOverview.stories.tsx b/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiOverview.stories.tsx
index c630b105c28..e2dde14d968 100644
--- a/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiOverview.stories.tsx
+++ b/packages/twenty-front/src/pages/settings/ai/components/__stories__/SettingsAiOverview.stories.tsx
@@ -4,6 +4,7 @@ import { SettingsPath } from 'twenty-shared/types';
import { getSettingsPath } from 'twenty-shared/utils';
import { Section } from 'twenty-ui/components/layout';
import { Text } from 'twenty-ui/primitives/typography';
+import { AiChatAssistantMode } from '~/generated-metadata/graphql';
import { SettingsAiOverview } from '~/pages/settings/ai/components/SettingsAiOverview';
import { SettingsAiBehaviorExample } from '~/pages/settings/ai/components/__stories__/SettingsAiBehaviorExample';
import { settingsAiOverviewStoryParameters } from '~/pages/settings/ai/components/__stories__/settingsAiOverviewStoryParameters';
@@ -66,8 +67,8 @@ export const WithSections: Story = {
),
behaviorSection: (
<SettingsAiBehaviorExample
- directMessageMode="MENTION_ONLY"
- inboxMode="AUTOMATIC"
+ directMessageMode={AiChatAssistantMode.MENTION_ONLY}
+ inboxMode={AiChatAssistantMode.AUTOMATIC}
onDirectMessageModeChange={fn()}
onInboxModeChange={fn()}
/>
diff --git a/packages/twenty-front/src/pages/settings/ai/components/__stories__/createSettingsAiIntegrationStoryFixture.ts b/packages/twenty-front/src/pages/settings/ai/components/__stories__/createSettingsAiIntegrationStoryFixture.ts
new file mode 100644
index 00000000000..26bbfe91ab8
--- /dev/null
+++ b/packages/twenty-front/src/pages/settings/ai/components/__stories__/createSettingsAiIntegrationStoryFixture.ts
@@ -0,0 +1,149 @@
+import { currentUserWorkspaceState } from '@/auth/states/currentUserWorkspaceState';
+import {
+ currentWorkspaceState,
+ type CurrentWorkspace,
+} from '@/auth/states/currentWorkspaceState';
+import { isCookieAuthActiveState } from '@/auth/states/isCookieAuthActiveState';
+import { SETTINGS_AI_TABS } from '@/settings/ai/constants/SettingsAiTabs';
+import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';
+import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
+import { delay, graphql, HttpResponse } from 'msw';
+import { fn } from 'storybook/test';
+import {
+ FeatureFlagKey,
+ type PermissionFlagType,
+ type UpdateWorkspaceMutation,
+ type UpdateWorkspaceMutationVariables,
+} from '~/generated-metadata/graphql';
+import { graphqlMocks } from '~/testing/graphqlMocks';
+import {
+ mockCurrentWorkspace,
+ mockedUserData,
+} from '~/testing/mock-data/users';
+import { mockedApolloClient } from '~/testing/mockedApolloClient';
+
+type SettingsAiIntegrationStoryOptions = {
+ permissionFlags: PermissionFlagType[];
+ isInboxEnabled: boolean;
+};
+
+export const createSettingsAiIntegrationStoryFixture = () => {
+ const saveInstructions = fn();
+ const loadSystemPrompts = fn();
+ let permissionFlags: PermissionFlagType[] = [];
+ let workspace: CurrentWorkspace = {
+ ...mockCurrentWorkspace,
+ aiAdditionalInstructions: null,
+ };
+
+ const reset = async (options: SettingsAiIntegrationStoryOptions) => {
+ await mockedApolloClient.clearStore();
+ saveInstructions.mockClear();
+ loadSystemPrompts.mockClear();
+ permissionFlags = options.permissionFlags;
+ workspace = {
+ ...mockCurrentWorkspace,
+ aiAdditionalInstructions: null,
+ featureFlags: [
+ {
+ __typename: 'FeatureFlag',
+ key: FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,
+ value: options.isInboxEnabled,
+ },
+ ],
+ };
+ jotaiStore.set(isCookieAuthActiveState.atom, true);
+ jotaiStore.set(currentWorkspaceState.atom, workspace);
+ jotaiStore.set(currentUserWorkspaceState.atom, {
+ ...mockedUserData.currentUserWorkspace,
+ permissionFlags,
+ });
+ jotaiStore.set(
+ activeTabIdComponentState.atomFamily({
+ instanceId: SETTINGS_AI_TABS.COMPONENT_INSTANCE_ID,
+ }),
+ null,
+ );
+ };
+
+ const handlers = [
+ graphql.query('GetAgentChatOpenThreadsSummary', () =>
+ HttpResponse.json({
+ data: {
+ agentChatOpenThreadsSummary: {
+ __typename: 'AgentChatOpenThreadsSummary',
+ openThreadCount: 0,
+ unreadOpenThreadCount: 0,
+ needsInputThreadCount: 0,
+ mentionThreadCount: 0,
+ assignedToMeThreadCount: 0,
+ assignedThreadCount: 0,
+ unassignedThreadCount: 0,
+ hasUnreadOpenThread: false,
+ hasUnreadMentionThread: false,
+ hasUnreadAssignedThread: false,
+ },
+ },
+ }),
+ ),
+ graphql.query('MyConnectedAccounts', () =>
+ HttpResponse.json({ data: { myConnectedAccounts: [] } }),
+ ),
+ graphql.query('GetCurrentUser', () =>
+ HttpResponse.json({
+ data: {
+ currentUser: {
+ ...mockedUserData,
+ currentWorkspace: workspace,
+ currentUserWorkspace: {
+ ...mockedUserData.currentUserWorkspace,
+ id: 'ai-settings-user-workspace',
+ permissionFlags,
+ },
+ },
+ },
+ }),
+ ),
+ graphql.mutation<UpdateWorkspaceMutation, UpdateWorkspaceMutationVariables>(
+ 'UpdateWorkspace',
+ async ({ variables }) => {
+ await delay(100);
+ workspace = {
+ ...workspace,
+ aiAdditionalInstructions:
+ variables.input.aiAdditionalInstructions ?? null,
+ };
+
+ saveInstructions(variables.input);
+
+ return HttpResponse.json({
+ data: {
+ updateWorkspace: {
+ ...workspace,
+ __typename: 'Workspace',
+ customDomain: workspace.customDomain ?? null,
+ displayName: workspace.displayName ?? null,
+ logo: workspace.logo ?? null,
+ defaultRole: null,
+ },
+ },
+ });
+ },
+ ),
+ graphql.query('GetAiSystemPromptPreview', () => {
+ loadSystemPrompts();
+ return HttpResponse.json({
+ data: {
+ getAiSystemPromptPreview: {
+ __typename: 'AiSystemPromptPreview',
+ estimatedTokenCount: 12400,
+ sections: [],
+ },
+ },
+ });
+ }),
+ ...graphqlMocks.handlers,
+ ];
+
+ return { reset, handlers, saveInstructions, loadSystemPrompts };
+};
diff --git a/packages/twenty-front/src/pages/settings/ai/types/SettingsAiAssistantMode.ts b/packages/twenty-front/src/pages/settings/ai/types/SettingsAiAssistantMode.ts
deleted file mode 100644
index 9383ba16398..00000000000
--- a/packages/twenty-front/src/pages/settings/ai/types/SettingsAiAssistantMode.ts
+++ /dev/null
@@ -1 +0,0 @@
-export type SettingsAiAssistantMode = 'NEVER' | 'MENTION_ONLY' | 'AUTOMATIC';