The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Update inbox rows and triage controls (#28564)
Raphaël Bosibea3df3bf9b6
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInboxBulkActions.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInboxBulkActions.tsxnew file mode 100644index 00000000000..3c6acf90715--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatInboxBulkActions.tsx@@ -0,0 +1,92 @@+import { useLingui } from '@lingui/react/macro';+import { styled } from '@linaria/react';+import { isDefined } from 'twenty-shared/utils';+import { IconCheck, IconZzz } from 'twenty-ui/icon';+import { Button } from 'twenty-ui/primitives/input';+import { Text } from 'twenty-ui/primitives/typography';+import { themeCssVariables } from 'twenty-ui/theme';++const StyledActions = styled.div`+ align-items: center;+ display: flex;+ flex-wrap: wrap;+ gap: ${themeCssVariables.spacing[1]};+`;++const StyledCount = styled.span`+ margin-right: ${themeCssVariables.spacing[2]};+`;++type AiChatInboxBulkActionsProps = {+ selectedCount: number;+ onDone?: () => void;+ onSnooze?: () => void;+ onClearSelection?: () => void;+ onMarkAllDone?: () => void;+ disabled?: boolean;+};++export const AiChatInboxBulkActions = ({+ selectedCount,+ onDone,+ onSnooze,+ onClearSelection,+ onMarkAllDone,+ disabled = false,+}: AiChatInboxBulkActionsProps) => {+ const { t } = useLingui();++ if (selectedCount === 0) {+ return isDefined(onMarkAllDone) ? (+ <Button+ size="sm"+ variant="outline"+ startIcon={<IconCheck />}+ disabled={disabled}+ onClick={onMarkAllDone}+ >+ {t`Mark all done`}+ </Button>+ ) : null;+ }++ return (+ <StyledActions role="group" aria-label={t`Selected chats`}>+ <Text render={<StyledCount />} size="md" color="secondary">+ {t`${selectedCount} selected`}+ </Text>+ {isDefined(onSnooze) && (+ <Button+ size="sm"+ variant="outline"+ startIcon={<IconZzz />}+ disabled={disabled}+ onClick={onSnooze}+ >+ {t`Snooze`}+ </Button>+ )}+ {isDefined(onDone) && (+ <Button+ size="sm"+ variant="outline"+ startIcon={<IconCheck />}+ disabled={disabled}+ onClick={onDone}+ >+ {t`Done`}+ </Button>+ )}+ {isDefined(onClearSelection) && (+ <Button+ size="sm"+ variant="ghost"+ disabled={disabled}+ onClick={onClearSelection}+ >+ {t`Clear selection`}+ </Button>+ )}+ </StyledActions>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatSnoozeMenu.tsx b/packages/twenty-front/src/modules/ai/components/AiChatSnoozeMenu.tsxnew file mode 100644index 00000000000..02eed95a677--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatSnoozeMenu.tsx@@ -0,0 +1,110 @@+import { useLingui } from '@lingui/react/macro';+import { isDefined } from 'twenty-shared/utils';+import { Dropdown } from 'twenty-ui/components/navigation';+import {+ IconCalendarEvent,+ IconCheck,+ IconClock,+ IconMessage,+ IconZzz,+} from 'twenty-ui/icon';+import { Button } from 'twenty-ui/primitives/input';++import { AGENT_CHAT_ASSISTANT_NAME } from '@/ai/constants/AgentChatAssistantName';+import { type AiChatSnoozePreset } from '@/ai/types/AiChatSnoozePreset';++const SNOOZE_MENU_WIDTH = 240;++type AiChatSnoozeMenuProps = {+ open: boolean;+ onOpenChange: (open: boolean) => void;+ presets: AiChatSnoozePreset[];+ onSelectPreset: (presetKey: AiChatSnoozePreset['key']) => void;+ onPickDate: () => void;+ onSomeoneReplies?: () => void;+ onAssistantFinishes?: () => void;+ assistantName?: string;+ disabled?: boolean;+};++export const AiChatSnoozeMenu = ({+ open,+ onOpenChange,+ presets,+ onSelectPreset,+ onPickDate,+ onSomeoneReplies,+ onAssistantFinishes,+ assistantName = AGENT_CHAT_ASSISTANT_NAME,+ disabled = false,+}: AiChatSnoozeMenuProps) => {+ const { t } = useLingui();+ const hasEventOptions =+ isDefined(onSomeoneReplies) || isDefined(onAssistantFinishes);++ return (+ <Dropdown.Root type="menu" open={open} onOpenChange={onOpenChange}>+ <Dropdown.Trigger+ disabled={disabled}+ render={+ <Button size="sm" variant="outline" startIcon={<IconZzz />}>+ {t`Snooze`}+ </Button>+ }+ />+ <Dropdown.Content+ width={SNOOZE_MENU_WIDTH}+ side="bottom"+ align="end"+ aria-label={t`Snooze chat`}+ >+ <Dropdown.Section>+ {presets.map((preset) => (+ <Dropdown.ActionItem+ key={preset.key}+ startIcon={<IconClock />}+ description={preset.description}+ descriptionPlacement="end"+ disabled={disabled}+ onClick={() => onSelectPreset(preset.key)}+ >+ {t(preset.label)}+ </Dropdown.ActionItem>+ ))}+ <Dropdown.ActionItem+ startIcon={<IconCalendarEvent />}+ disabled={disabled}+ onClick={onPickDate}+ >+ {t`Pick a date`}+ </Dropdown.ActionItem>+ </Dropdown.Section>+ {hasEventOptions && (+ <>+ <Dropdown.Separator />+ <Dropdown.Section>+ {isDefined(onSomeoneReplies) && (+ <Dropdown.ActionItem+ startIcon={<IconMessage />}+ disabled={disabled}+ onClick={onSomeoneReplies}+ >+ {t`Someone replies`}+ </Dropdown.ActionItem>+ )}+ {isDefined(onAssistantFinishes) && (+ <Dropdown.ActionItem+ startIcon={<IconCheck />}+ disabled={disabled}+ onClick={onAssistantFinishes}+ >+ {t`When ${assistantName} finishes`}+ </Dropdown.ActionItem>+ )}+ </Dropdown.Section>+ </>+ )}+ </Dropdown.Content>+ </Dropdown.Root>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadActionsDropdown.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadActionsDropdown.tsxindex f2c655b09da..e8a8cec8d18 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadActionsDropdown.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadActionsDropdown.tsx@@ -6,6 +6,7 @@ import { LightIconButton } from 'twenty-ui/components/input';import { Dropdown } from 'twenty-ui/components/navigation';import { IconDotsVertical, IconPencil, IconUnlink } from 'twenty-ui/icon';+import { AiChatThreadRowTriage } from '@/ai/components/AiChatThreadRowTriage';import { AiChatThreadCommandMenuItems } from '@/ai/components/AiChatThreadCommandMenuItems';import { useRefreshAgentChatThreadPermissions } from '@/ai/hooks/useRefreshAgentChatThreadPermissions';import { useTargetAiChatThreadsInContextStore } from '@/ai/hooks/useTargetAiChatThreadsInContextStore';@@ -31,6 +32,7 @@ type AiChatThreadActionsDropdownProps = {instanceId: string;onRenameRequested: () => void;onDetach?: () => void;+ shouldShowTriageActions?: boolean;};export const AiChatThreadActionsDropdown = ({@@ -38,6 +40,7 @@ export const AiChatThreadActionsDropdown = ({instanceId,onRenameRequested,onDetach,+ shouldShowTriageActions = false,}: AiChatThreadActionsDropdownProps) => {const { t } = useLingui();const { upsertRecordsInStore } = useUpsertRecordsInStore();@@ -76,6 +79,9 @@ export const AiChatThreadActionsDropdown = ({return (<ContextStoreComponentInstanceContext.Provider value={{ instanceId }}><CommandMenuComponentInstanceContext.Provider value={{ instanceId }}>+ {shouldShowTriageActions && !isDeleted && (+ <AiChatThreadRowTriage threadId={thread.id} />+ )}<DropdownRootdropdownId={getCommandMenuDropdownIdFromCommandMenuId(instanceId)}type="menu"diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadActivityTime.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadActivityTime.tsxindex 9601a523297..94afbd82868 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadActivityTime.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadActivityTime.tsx@@ -1,7 +1,8 @@import { styled } from '@linaria/react';import { useLingui } from '@lingui/react/macro';-import { themeCssVariables } from 'twenty-ui/theme';+import { Text } from 'twenty-ui/primitives/typography';+import { useIsAgentChatThreadShownAsUnread } from '@/ai/hooks/useIsAgentChatThreadShownAsUnread';import { useFormatAgentChatThreadDate } from '@/ai/hooks/useFormatAgentChatThreadDate';import { agentChatThreadInboxStatusFamilySelector } from '@/ai/states/selectors/agentChatThreadInboxStatusFamilySelector';import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';@@ -10,9 +11,7 @@ import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useimport { beautifyPastDateRelativeToNowShort } from '~/utils/date-utils';const StyledActivityTime = styled.div`- color: ${themeCssVariables.font.color.tertiary};flex-shrink: 0;- font-size: ${themeCssVariables.font.size.sm};`;type AiChatThreadActivityTimeProps = {@@ -23,6 +22,7 @@ export const AiChatThreadActivityTime = ({thread,}: AiChatThreadActivityTimeProps) => {const { t } = useLingui();+ const isUnread = useIsAgentChatThreadShownAsUnread(thread);const { event } = useAtomFamilySelectorValue(agentChatThreadInboxStatusFamilySelector,thread.id,@@ -55,5 +55,13 @@ export const AiChatThreadActivityTime = ({}};- return <StyledActivityTime>{getActivityTimeLabel()}</StyledActivityTime>;+ return (+ <Text+ render={<StyledActivityTime />}+ size="sm"+ color={isUnread ? 'primary' : 'tertiary'}+ >+ {getActivityTimeLabel()}+ </Text>+ );};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadAvatar.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadAvatar.tsxindex a7dfc56a651..73ac133f566 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadAvatar.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadAvatar.tsx@@ -1,7 +1,11 @@import { useLingui } from '@lingui/react/macro';+import { isDefined } from 'twenty-shared/utils';+import { Avatar } from 'twenty-ui/primitives/data-display';import { useAgentChatThreadMembers } from '@/ai/hooks/useAgentChatThreadMembers';import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';+import { getWorkspaceMemberNameOrEmail } from '@/workspace-member/utils/getWorkspaceMemberNameOrEmail';+import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';import { WorkspaceMemberAvatarStack } from '@/workspace-member/components/WorkspaceMemberAvatarStack';type AiChatThreadAvatarProps = {@@ -12,6 +16,23 @@ export const AiChatThreadAvatar = ({ thread }: AiChatThreadAvatarProps) => {const { t } = useLingui();const threadMembers = useAgentChatThreadMembers(thread);+ const [onlyMember, secondMember] = threadMembers;++ if (isDefined(onlyMember) && !isDefined(secondMember)) {+ const name = getWorkspaceMemberNameOrEmail(onlyMember);++ return (+ <Avatar+ src={getAbsoluteImageUrl(onlyMember.avatarUrl)}+ name={name}+ imageProps={{ alt: name }}+ colorSeed={onlyMember.id}+ size="lg"+ shape="circle"+ />+ );+ }+return (<WorkspaceMemberAvatarStackworkspaceMembers={threadMembers}diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadList.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadList.tsxindex 04b5762a478..63b08c734cb 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadList.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadList.tsx@@ -1,20 +1,11 @@-import { styled } from '@linaria/react';import { type MouseEvent } from 'react';import { isDefined } from 'twenty-shared/utils';-import { themeCssVariables } from 'twenty-ui/theme';+import { AiChatThreadListGroup } from '@/ai/components/AiChatThreadListGroup';import { AiChatThreadListItem } from '@/ai/components/AiChatThreadListItem';import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';import { groupThreadsByDate } from '@/ai/utils/groupThreadsByDate';-const StyledGroupTitle = styled.div`- color: ${themeCssVariables.font.color.light};- font-size: ${themeCssVariables.font.size.xs};- font-weight: ${themeCssVariables.font.weight.semiBold};- padding: ${themeCssVariables.spacing[3]} ${themeCssVariables.spacing[4]}- ${themeCssVariables.spacing[1]};-`;-type AiChatThreadListProps = {threads: AgentChatThreadRecord[];selectedThreadIds?: string[];@@ -64,10 +55,9 @@ export const AiChatThreadList = ({return (<>{groupThreadsByDate(threads).map((dateGroup) => (- <div key={dateGroup.id}>- <StyledGroupTitle>{dateGroup.title}</StyledGroupTitle>+ <AiChatThreadListGroup key={dateGroup.id} title={dateGroup.title}>{dateGroup.threads.map(renderThread)}- </div>+ </AiChatThreadListGroup>))}</>);diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadListGroup.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadListGroup.tsxnew file mode 100644index 00000000000..674f7016134--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadListGroup.tsx@@ -0,0 +1,54 @@+import { styled } from '@linaria/react';+import { type ReactNode, useId } from 'react';+import { isDefined } from 'twenty-shared/utils';+import { Text } from 'twenty-ui/primitives/typography';+import { themeCssVariables } from 'twenty-ui/theme';++const StyledHeader = styled.div`+ align-items: center;+ display: flex;+ gap: ${themeCssVariables.spacing[1]};+ padding: ${themeCssVariables.spacing[4]} ${themeCssVariables.spacing[4]}+ ${themeCssVariables.spacing[2]};+`;++const StyledTitle = styled.h3`+ margin: 0;+ padding: ${themeCssVariables.spacing[1]} 0;+`;++type AiChatThreadListGroupProps = {+ title: string;+ count?: number;+ children: ReactNode;+};++export const AiChatThreadListGroup = ({+ title,+ count,+ children,+}: AiChatThreadListGroupProps) => {+ const titleId = useId();++ return (+ <section aria-labelledby={titleId}>+ <StyledHeader>+ <Text+ render={<StyledTitle />}+ id={titleId}+ size="md"+ weight="medium"+ color="primary"+ >+ {title}+ </Text>+ {isDefined(count) && (+ <Text render={<span />} size="sm" color="light">+ {count}+ </Text>+ )}+ </StyledHeader>+ {children}+ </section>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsxindex c58748f74ca..a236f25d06c 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx@@ -1,130 +1,21 @@-import { styled } from '@linaria/react';import { type MouseEvent, useId } from 'react';import { useLingui } from '@lingui/react/macro';import { Key } from 'ts-key-enum';import { isDefined } from 'twenty-shared/utils';-import { Checkbox } from 'twenty-ui/primitives/input';-import { themeCssVariables } from 'twenty-ui/theme';import { AiChatThreadActionsDropdown } from '@/ai/components/AiChatThreadActionsDropdown';import { AiChatThreadActivityTime } from '@/ai/components/AiChatThreadActivityTime';import { AiChatThreadAvatar } from '@/ai/components/AiChatThreadAvatar';+import { AiChatThreadRow } from '@/ai/components/AiChatThreadRow';import { AiChatThreadSubtitle } from '@/ai/components/AiChatThreadSubtitle';import { AiChatThreadTitle } from '@/ai/components/AiChatThreadTitle';-import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';import { useAiChatThreadRename } from '@/ai/hooks/useAiChatThreadRename';+import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';import { getCommandMenuDropdownIdFromCommandMenuId } from '@/command-menu-item/utils/getCommandMenuDropdownIdFromCommandMenuId';import { TextInput } from '@/ui/input/components/TextInput';import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';-const StyledThreadItem = styled.div<{- $isSelected: boolean;- $isChecked: boolean;-}>`- align-items: flex-start;- background: ${({ $isSelected, $isChecked }) =>- $isChecked- ? themeCssVariables.accent.tertiary- : $isSelected- ? themeCssVariables.background.transparent.light- : 'none'};- border-bottom: 1px solid ${themeCssVariables.border.color.light};- cursor: pointer;- display: flex;- gap: ${themeCssVariables.spacing[3]};- padding: ${themeCssVariables.spacing[4]};- position: relative;-- &:hover {- background: ${({ $isChecked }) =>- $isChecked- ? themeCssVariables.accent.tertiary- : themeCssVariables.background.transparent.light};- }-`;--const StyledLeading = styled.div`- display: flex;- flex-shrink: 0;- justify-content: center;- padding-top: ${themeCssVariables.spacing['0.5']};- width: ${themeCssVariables.spacing[7]};-`;--// The checkbox takes the avatar's place while the chat is checked, or while-// the row is hovered or focused; without hover, a tap on the avatar checks it-const StyledCheckboxContainer = styled.div<{ $isChecked: boolean }>`- display: ${({ $isChecked }) => ($isChecked ? 'flex' : 'none')};-- ${StyledThreadItem}:focus-within & {- display: flex;- }-- @media (hover: hover) {- ${StyledThreadItem}:hover & {- display: flex;- }- }-`;--const StyledAvatarContainer = styled.div<{- $isCheckable: boolean;- $isChecked: boolean;-}>`- display: ${({ $isChecked }) => ($isChecked ? 'none' : 'flex')};-- ${StyledThreadItem}:focus-within & {- display: ${({ $isCheckable, $isChecked }) =>- $isCheckable || $isChecked ? 'none' : 'flex'};- }-- @media (hover: hover) {- ${StyledThreadItem}:hover & {- display: ${({ $isCheckable, $isChecked }) =>- $isCheckable || $isChecked ? 'none' : 'flex'};- }- }-`;--const StyledThreadContent = styled.div`- display: flex;- flex: 1;- flex-direction: column;- min-width: 0;-`;--const StyledThreadHeading = styled.div`- align-items: center;- display: flex;- gap: ${themeCssVariables.spacing[2]};- min-width: 0;-`;--const StyledActivityTimeContainer = styled.div<{ $isDropdownOpen: boolean }>`- visibility: ${({ $isDropdownOpen }) =>- $isDropdownOpen ? 'hidden' : 'visible'};-- ${StyledThreadItem}:hover & {- visibility: hidden;- }-`;--const StyledMenuTrigger = styled.div<{ $isDropdownOpen: boolean }>`- opacity: ${({ $isDropdownOpen }) => ($isDropdownOpen ? 1 : 0)};- pointer-events: ${({ $isDropdownOpen }) =>- $isDropdownOpen ? 'auto' : 'none'};- position: absolute;- right: ${themeCssVariables.spacing[3]};- top: ${themeCssVariables.spacing[3]};- transition: opacity 150ms;-- ${StyledThreadItem}:hover & {- opacity: 1;- pointer-events: auto;- }-`;-type AiChatThreadListItemProps = {thread: AgentChatThreadRecord;isSelected: boolean;@@ -172,53 +63,27 @@ export const AiChatThreadListItem = ({);return (- <StyledThreadItem- $isSelected={isSelected}- $isChecked={isChecked}- data-selectable-id={thread.id}- data-select-disable={isRenaming || undefined}- onMouseDown={(event) => {- // Shift+click selects a range of chats, not the text in between- if (event.shiftKey && !isRenaming) {- event.preventDefault();- }- }}- onClick={(event) => {- if (!isRenaming) {- onClick(thread, event);- }- }}- onContextMenu={(event) => {- if (!isRenaming) {- onContextMenu?.(thread, event);- }- }}- >- <StyledLeading- data-select-disable={isDefined(onCheckboxClick) || undefined}- onClick={- isDefined(onCheckboxClick)- ? (event) => {- event.stopPropagation();- onCheckboxClick(thread, event);- }- : undefined- }- >- {isDefined(onCheckboxClick) && (- <StyledCheckboxContainer $isChecked={isChecked}>- <Checkbox checked={isChecked} aria-label={t`Select chat`} />- </StyledCheckboxContainer>- )}- <StyledAvatarContainer- $isCheckable={isDefined(onCheckboxClick)}- $isChecked={isChecked}- >- <AiChatThreadAvatar thread={thread} />- </StyledAvatarContainer>- </StyledLeading>- <StyledThreadContent>- {isRenaming ? (+ <AiChatThreadRow+ id={thread.id}+ label={thread.title ?? t`Untitled`}+ isSelected={isSelected}+ isChecked={isChecked}+ isEditing={isRenaming}+ isActionMenuOpen={isDropdownOpen}+ onClick={(event) => onClick(thread, event)}+ onCheckboxClick={+ isDefined(onCheckboxClick)+ ? (event) => onCheckboxClick(thread, event)+ : undefined+ }+ onContextMenu={+ isDefined(onContextMenu)+ ? (event) => onContextMenu(thread, event)+ : undefined+ }+ avatar={<AiChatThreadAvatar thread={thread} />}+ title={+ isRenaming ? (<TextInputvalue={draftTitle}onChange={setDraftTitle}@@ -232,7 +97,9 @@ export const AiChatThreadListItem = ({if (event.key === Key.Enter) {event.preventDefault();void commitRename(draftTitle);- } else if (event.key === Key.Escape) {+ return;+ }+ if (event.key === Key.Escape) {event.preventDefault();cancelRename();}@@ -243,26 +110,20 @@ export const AiChatThreadListItem = ({aria-label={t`Rename chat`}/>) : (- <StyledThreadHeading>- <AiChatThreadTitle thread={thread} />- <StyledActivityTimeContainer $isDropdownOpen={isDropdownOpen}>- <AiChatThreadActivityTime thread={thread} />- </StyledActivityTimeContainer>- </StyledThreadHeading>- )}- <AiChatThreadSubtitle thread={thread} />- </StyledThreadContent>- <StyledMenuTrigger- $isDropdownOpen={isDropdownOpen}- onClick={(event) => event.stopPropagation()}- >+ <AiChatThreadTitle thread={thread} />+ )+ }+ activityTime={!isRenaming && <AiChatThreadActivityTime thread={thread} />}+ subtitle={<AiChatThreadSubtitle thread={thread} />}+ actions={<AiChatThreadActionsDropdownthread={thread}instanceId={actionsInstanceId}onRenameRequested={startRename}onDetach={onDetach}+ shouldShowTriageActions/>- </StyledMenuTrigger>- </StyledThreadItem>+ }+ />);};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadReasonBadge.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadReasonBadge.tsxnew file mode 100644index 00000000000..17bd24633c2--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadReasonBadge.tsx@@ -0,0 +1,60 @@+import { styled } from '@linaria/react';+import { useLingui } from '@lingui/react/macro';+import { Text } from 'twenty-ui/primitives/typography';+import { themeCssVariables, useTheme } from 'twenty-ui/theme';++import { AI_CHAT_THREAD_REASONS } from '@/ai/constants/AiChatThreadReasons';+import { type AiChatThreadReason } from '@/ai/types/AiChatThreadReason';++const StyledReason = styled.span<{+ $isHighlighted: boolean;+ $isUnread: boolean;+}>`+ align-items: center;+ color: ${({ $isHighlighted, $isUnread }) => {+ if ($isHighlighted) {+ return themeCssVariables.color.blue;+ }++ if ($isUnread) {+ return themeCssVariables.font.color.primary;+ }++ return themeCssVariables.font.color.tertiary;+ }};+ display: inline-flex;+ flex-shrink: 0;+ gap: ${themeCssVariables.spacing[1]};+ white-space: nowrap;+`;++type AiChatThreadReasonBadgeProps = {+ reason: AiChatThreadReason;+ isUnread?: boolean;+};++export const AiChatThreadReasonBadge = ({+ reason,+ isUnread = false,+}: AiChatThreadReasonBadgeProps) => {+ const { t } = useLingui();+ const theme = useTheme();+ const { Icon, label } = AI_CHAT_THREAD_REASONS[reason];+ const isHighlighted =+ isUnread && ['needsInput', 'mentioned', 'assigned'].includes(reason);++ return (+ <Text+ render={+ <StyledReason+ $isHighlighted={isHighlighted}+ $isUnread={isUnread && reason !== 'draft'}+ />+ }+ size="sm"+ >+ <Icon size={theme.icon.size.sm} />+ {t(label)}+ </Text>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadRequestActions.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadRequestActions.tsxnew file mode 100644index 00000000000..cb01de59b32--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadRequestActions.tsx@@ -0,0 +1,80 @@+import { useLingui } from '@lingui/react/macro';+import { styled } from '@linaria/react';+import { Button } from 'twenty-ui/primitives/input';+import { themeCssVariables } from 'twenty-ui/theme';++import { type AiChatThreadRequest } from '@/ai/types/AiChatThreadRequest';++const StyledActions = styled.div`+ display: flex;+ flex-wrap: wrap;+ gap: ${themeCssVariables.spacing[2]};+ min-width: 0;+`;++type AiChatThreadRequestActionsProps = {+ request: AiChatThreadRequest;+ disabled?: boolean;+ isLoading?: boolean;+};++export const AiChatThreadRequestActions = ({+ request,+ disabled = false,+ isLoading = false,+}: AiChatThreadRequestActionsProps) => {+ const { t } = useLingui();++ return (+ <StyledActions+ role="group"+ aria-label={t`Respond to request`}+ aria-busy={isLoading}+ >+ {request.type === 'choices' &&+ request.choices.map((choice) => (+ <Button+ key={choice.id}+ size="sm"+ variant="outline"+ startIcon={choice.avatar}+ disabled={disabled || isLoading}+ onClick={(event) => {+ event.stopPropagation();+ request.onChoose(choice.id);+ }}+ >+ {choice.label}+ </Button>+ ))}+ {request.type === 'review' && (+ <Button+ size="sm"+ variant="outline"+ disabled={disabled}+ loading={isLoading}+ onClick={(event) => {+ event.stopPropagation();+ request.onReview();+ }}+ >+ {request.label}+ </Button>+ )}+ {request.type === 'reply' && (+ <Button+ size="sm"+ variant="outline"+ disabled={disabled}+ loading={isLoading}+ onClick={(event) => {+ event.stopPropagation();+ request.onReply();+ }}+ >+ {t`Reply`}+ </Button>+ )}+ </StyledActions>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadRow.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadRow.tsxnew file mode 100644index 00000000000..112e83bb787--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadRow.tsx@@ -0,0 +1,256 @@+import { styled } from '@linaria/react';+import { useLingui } from '@lingui/react/macro';+import { type MouseEvent, type ReactNode } from 'react';+import { Key } from 'ts-key-enum';+import { isDefined } from 'twenty-shared/utils';+import { Checkbox } from 'twenty-ui/primitives/input';+import { ListItem } from 'twenty-ui/primitives/navigation';+import { themeCssVariables } from 'twenty-ui/theme';++const StyledRow = styled.div`+ border-bottom: 1px solid ${themeCssVariables.border.color.light};+ border-radius: 0;+ column-gap: ${themeCssVariables.spacing[4]};+ padding: ${themeCssVariables.spacing[4]};+ row-gap: ${themeCssVariables.spacing[2]};+`;++const StyledLeading = styled.div`+ align-items: center;+ display: flex;+ flex-shrink: 0;+ height: ${themeCssVariables.spacing[8]};+ justify-content: center;+ width: ${themeCssVariables.spacing[6]};+`;++const StyledCheckbox = styled.div<{ $isChecked: boolean }>`+ display: ${({ $isChecked }) => ($isChecked ? 'flex' : 'none')};++ ${StyledRow}:focus-within & {+ display: flex;+ }++ @media (hover: hover) {+ ${StyledRow}:hover & {+ display: flex;+ }+ }+`;++const StyledAvatar = styled.div<{ $isCheckable: boolean; $isChecked: boolean }>`+ display: ${({ $isChecked }) => ($isChecked ? 'none' : 'flex')};++ ${StyledRow}:focus-within & {+ display: ${({ $isCheckable, $isChecked }) =>+ $isCheckable || $isChecked ? 'none' : 'flex'};+ }++ @media (hover: hover) {+ ${StyledRow}:hover & {+ display: ${({ $isCheckable, $isChecked }) =>+ $isCheckable || $isChecked ? 'none' : 'flex'};+ }+ }+`;++const StyledHeading = styled.div`+ align-items: center;+ display: flex;+ gap: ${themeCssVariables.spacing[2]};+ min-width: 0;+`;++const StyledTitle = styled.div`+ display: flex;+ flex: 1;+ min-width: 0;+`;++const StyledTime = styled.div<{+ $isActionMenuOpen: boolean;+ $hasActions: boolean;+}>`+ flex-shrink: 0;+ white-space: nowrap;++ @media (hover: hover) {+ display: ${({ $isActionMenuOpen, $hasActions }) =>+ $isActionMenuOpen && $hasActions ? 'none' : 'block'};++ ${StyledRow}:hover &,+ ${StyledRow}:focus-within & {+ display: ${({ $hasActions }) => ($hasActions ? 'none' : 'block')};+ }+ }++ @container (max-width: 480px) {+ &,+ ${StyledRow}:hover &,+ ${StyledRow}:focus-within & {+ display: block;+ }+ }+`;++const StyledActions = styled.div`+ align-items: center;+ display: flex;+ flex-wrap: wrap;+ gap: ${themeCssVariables.spacing[1]};+ margin-top: ${themeCssVariables.spacing[1]};++ @container (max-width: 480px) {+ margin-top: 0;+ padding-left: calc(+ ${themeCssVariables.spacing[6]} + ${themeCssVariables.spacing[4]}+ );+ }+`;++const StyledDescription = styled.div`+ display: flex;+ flex-direction: column;+ gap: ${themeCssVariables.spacing[2]};+ min-width: 0;+`;++type AiChatThreadRowProps = {+ id: string;+ label: string;+ avatar: ReactNode;+ title: ReactNode;+ subtitle: ReactNode;+ activityTime?: ReactNode;+ actions?: ReactNode;+ children?: ReactNode;+ isSelected?: boolean;+ isChecked?: boolean;+ isEditing?: boolean;+ isActionMenuOpen?: boolean;+ onClick: (event: MouseEvent<HTMLDivElement>) => void;+ onCheckboxClick?: (event: MouseEvent<HTMLDivElement>) => void;+ onContextMenu?: (event: MouseEvent<HTMLDivElement>) => void;+};++const stopPropagation = (event: MouseEvent<HTMLDivElement>) =>+ event.stopPropagation();++export const AiChatThreadRow = ({+ id,+ label,+ avatar,+ title,+ subtitle,+ activityTime,+ actions,+ children,+ isSelected = false,+ isChecked = false,+ isEditing = false,+ isActionMenuOpen = false,+ onClick,+ onCheckboxClick,+ onContextMenu,+}: AiChatThreadRowProps) => {+ const { t } = useLingui();++ return (+ <ListItem+ active={isSelected}+ selected={isChecked}+ selectionAppearance="accent"+ descriptionPlacement="below"+ actionsVisibility={isActionMenuOpen ? 'always' : 'hover'}+ render={+ <StyledRow+ aria-label={label}+ role="group"+ tabIndex={0}+ data-selectable-id={id}+ data-select-disable={isEditing || undefined}+ onMouseDown={(event) => {+ if (event.shiftKey && !isEditing) {+ event.preventDefault();+ }+ }}+ onKeyDown={(event) => {+ if (+ event.target !== event.currentTarget ||+ isEditing ||+ (event.key !== Key.Enter && event.key !== ' ')+ ) {+ return;+ }++ event.preventDefault();+ event.stopPropagation();+ event.currentTarget.click();+ }}+ onClick={isEditing ? undefined : onClick}+ onContextMenu={isEditing ? undefined : onContextMenu}+ />+ }+ startIcon={+ <StyledLeading+ data-select-disable={isDefined(onCheckboxClick) || undefined}+ onClick={+ isDefined(onCheckboxClick)+ ? (event) => {+ event.stopPropagation();+ onCheckboxClick(event);+ }+ : undefined+ }+ >+ {isDefined(onCheckboxClick) && (+ <StyledCheckbox $isChecked={isChecked}>+ <Checkbox checked={isChecked} aria-label={t`Select chat`} />+ </StyledCheckbox>+ )}+ <StyledAvatar+ $isCheckable={isDefined(onCheckboxClick)}+ $isChecked={isChecked}+ >+ {avatar}+ </StyledAvatar>+ </StyledLeading>+ }+ description={+ <StyledDescription>+ {subtitle}+ {isDefined(children) && (+ <div+ data-select-disable+ onClick={stopPropagation}+ onContextMenu={stopPropagation}+ >+ {children}+ </div>+ )}+ </StyledDescription>+ }+ actions={+ isDefined(actions) && (+ <StyledActions+ data-select-disable+ onClick={stopPropagation}+ onContextMenu={stopPropagation}+ >+ {actions}+ </StyledActions>+ )+ }+ >+ <StyledHeading>+ <StyledTitle>{title}</StyledTitle>+ <StyledTime+ $isActionMenuOpen={isActionMenuOpen}+ $hasActions={isDefined(actions)}+ >+ {activityTime}+ </StyledTime>+ </StyledHeading>+ </ListItem>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadRowTriage.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadRowTriage.tsxnew file mode 100644index 00000000000..c82e00050d5--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadRowTriage.tsx@@ -0,0 +1,66 @@+import { isDefined } from 'twenty-shared/utils';++import { AiChatThreadTriageButtons } from '@/ai/components/AiChatThreadTriageButtons';+import { useExecuteAgentChatThreadInboxAction } from '@/ai/hooks/useExecuteAgentChatThreadInboxAction';+import { agentChatThreadParticipantsState } from '@/ai/states/agentChatThreadParticipantsState';+import { agentChatThreadInboxStatusFamilySelector } from '@/ai/states/selectors/agentChatThreadInboxStatusFamilySelector';+import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';+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 {+ AgentChatInboxAction,+ FeatureFlagKey,+ PermissionFlagType,+} from '~/generated-metadata/graphql';++const TRIAGE_STATUS_BY_SCOPE = {+ INBOX: 'open',+ SNOOZED: 'snoozed',+ ARCHIVED: 'done',+} as const;++type AiChatThreadRowTriageProps = {+ threadId: string;+};++export const AiChatThreadRowTriage = ({+ threadId,+}: AiChatThreadRowTriageProps) => {+ const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);+ const isInboxEnabled = useIsFeatureEnabled(+ FeatureFlagKey.IS_AI_CHAT_INBOX_ENABLED,+ );+ const agentChatThreadParticipants = useAtomStateValue(+ agentChatThreadParticipantsState,+ );+ const { scope } = useAtomFamilySelectorValue(+ agentChatThreadInboxStatusFamilySelector,+ threadId,+ );+ const { executeAgentChatThreadInboxAction, isPending } =+ useExecuteAgentChatThreadInboxAction();++ if (+ !hasAiPermission ||+ !isInboxEnabled ||+ !isDefined(agentChatThreadParticipants) ||+ scope === 'NONE'+ ) {+ return null;+ }++ const executeInboxAction = (action: AgentChatInboxAction) => {+ void executeAgentChatThreadInboxAction({ threadIds: [threadId], action });+ };++ return (+ <AiChatThreadTriageButtons+ status={TRIAGE_STATUS_BY_SCOPE[scope]}+ isPending={isPending}+ onSnooze={() => executeInboxAction(AgentChatInboxAction.SNOOZE)}+ onDone={() => executeInboxAction(AgentChatInboxAction.ARCHIVE)}+ onReopen={() => executeInboxAction(AgentChatInboxAction.MOVE_TO_INBOX)}+ />+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadSubtitle.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadSubtitle.tsxindex 0cf37a945b6..89fee3f1212 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadSubtitle.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadSubtitle.tsx@@ -1,11 +1,12 @@import { styled } from '@linaria/react';import { useLingui } from '@lingui/react/macro';import { isDefined, isNonEmptyString } from 'twenty-shared/utils';-import { IconHandClick, IconPencil } from 'twenty-ui/icon';import { VisuallyHidden } from 'twenty-ui/primitives/accessibility';import { Avatar } from 'twenty-ui/primitives/data-display';-import { themeCssVariables, useTheme } from 'twenty-ui/theme';+import { Text } from 'twenty-ui/primitives/typography';+import { themeCssVariables } from 'twenty-ui/theme';+import { AiChatThreadReasonBadge } from '@/ai/components/AiChatThreadReasonBadge';import { useIsAgentChatThreadShownAsUnread } from '@/ai/hooks/useIsAgentChatThreadShownAsUnread';import { agentChatDraftPreviewTextFamilySelector } from '@/ai/states/selectors/agentChatDraftPreviewTextFamilySelector';import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';@@ -19,31 +20,19 @@ import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';const StyledSubtitle = styled.div`align-items: center;- color: ${themeCssVariables.font.color.tertiary};display: flex;- font-size: ${themeCssVariables.font.size.sm};gap: ${themeCssVariables.spacing[1]};- min-height: ${themeCssVariables.spacing[4]};+ line-height: calc(+ ${themeCssVariables.spacing[4]} - ${themeCssVariables.spacing['0.5']}+ );+ min-height: calc(+ ${themeCssVariables.spacing[4]} - ${themeCssVariables.spacing['0.5']}+ );min-width: 0;`;-const StyledStatus = styled.div<{ $isHighlighted: boolean }>`- align-items: center;- color: ${({ $isHighlighted }) =>- $isHighlighted- ? themeCssVariables.color.blue- : themeCssVariables.font.color.tertiary};- display: flex;- flex-shrink: 0;- font-weight: ${themeCssVariables.font.weight.medium};- gap: ${themeCssVariables.spacing[1]};-`;-const StyledPreview = styled.div`min-width: 0;- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;`;const StyledAssignee = styled.div`@@ -58,7 +47,6 @@ type AiChatThreadSubtitleProps = {export const AiChatThreadSubtitle = ({ thread }: AiChatThreadSubtitleProps) => {const { t } = useLingui();- const theme = useTheme();const isUnread = useIsAgentChatThreadShownAsUnread(thread);const currentWorkspaceMember = useAtomStateValue(currentWorkspaceMemberState);const currentWorkspaceMembers = useAtomStateValue(@@ -86,24 +74,22 @@ export const AiChatThreadSubtitle = ({ thread }: AiChatThreadSubtitleProps) => {});return (- <StyledSubtitle>+ <Text+ render={<StyledSubtitle />}+ size="sm"+ color={isUnread ? 'secondary' : 'tertiary'}+ >{isAwaitingAnswer && (- <StyledStatus $isHighlighted={isUnread}>- <IconHandClick size={theme.icon.size.sm} />- {t`Needs input`}- </StyledStatus>+ <AiChatThreadReasonBadge reason="needsInput" isUnread={isUnread} />)}{isAwaitingAnswer && hasDraft && <span aria-hidden>·</span>}- {hasDraft && (- <StyledStatus $isHighlighted={false}>- <IconPencil size={theme.icon.size.sm} />- {t`Draft`}- </StyledStatus>- )}+ {hasDraft && <AiChatThreadReasonBadge reason="draft" />}{(isAwaitingAnswer || hasDraft) && isNonEmptyString(previewText) && (<span aria-hidden>·</span>)}- <StyledPreview>{previewText}</StyledPreview>+ <Text render={<StyledPreview />} truncate>+ {previewText}+ </Text>{isDefined(assignee) && (<StyledAssignee title={t`Assigned to ${assigneeName}`}><Avatar@@ -116,6 +102,6 @@ export const AiChatThreadSubtitle = ({ thread }: AiChatThreadSubtitleProps) => {<VisuallyHidden>{t`, assigned to ${assigneeName}`}</VisuallyHidden></StyledAssignee>)}- </StyledSubtitle>+ </Text>);};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadTitle.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadTitle.tsxindex c269267b3d7..f04d7477404 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadTitle.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadTitle.tsx@@ -2,26 +2,16 @@ import { styled } from '@linaria/react';import { useLingui } from '@lingui/react/macro';import { isNonEmptyString } from 'twenty-shared/utils';import { VisuallyHidden } from 'twenty-ui/primitives/accessibility';+import { Text } from 'twenty-ui/primitives/typography';import { themeCssVariables } from 'twenty-ui/theme';import { useIsAgentChatThreadShownAsUnread } from '@/ai/hooks/useIsAgentChatThreadShownAsUnread';import { type AgentChatThreadRecord } from '@/ai/types/AgentChatThreadRecord';-const StyledTitle = styled.div<{ $isUnread: boolean }>`- color: ${({ $isUnread }) =>- $isUnread- ? themeCssVariables.font.color.primary- : themeCssVariables.font.color.secondary};+const StyledTitle = styled.div`flex: 1;- font-size: ${themeCssVariables.font.size.md};- font-weight: ${({ $isUnread }) =>- $isUnread- ? themeCssVariables.font.weight.semiBold- : themeCssVariables.font.weight.medium};+ line-height: ${themeCssVariables.spacing[4]};min-width: 0;- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;`;type AiChatThreadTitleProps = {@@ -33,9 +23,15 @@ export const AiChatThreadTitle = ({ thread }: AiChatThreadTitleProps) => {const isUnread = useIsAgentChatThreadShownAsUnread(thread);return (- <StyledTitle $isUnread={isUnread}>+ <Text+ render={<StyledTitle />}+ size="md"+ weight={isUnread ? 'semibold' : 'regular'}+ color="primary"+ truncate+ >{isNonEmptyString(thread.title) ? thread.title : t`Untitled`}{isUnread && <VisuallyHidden>{t`, unread`}</VisuallyHidden>}- </StyledTitle>+ </Text>);};diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadTriageButtons.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadTriageButtons.tsxnew file mode 100644index 00000000000..1beced0fc32--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadTriageButtons.tsx@@ -0,0 +1,55 @@+import { useLingui } from '@lingui/react/macro';+import { IconArrowBackUp, IconBell, IconCheck, IconZzz } from 'twenty-ui/icon';+import { Button } from 'twenty-ui/primitives/input';++type AiChatThreadTriageButtonsProps = {+ status: 'open' | 'snoozed' | 'done';+ isPending?: boolean;+ onSnooze: () => void;+ onDone: () => void;+ onReopen: () => void;+};++export const AiChatThreadTriageButtons = ({+ status,+ isPending = false,+ onSnooze,+ onDone,+ onReopen,+}: AiChatThreadTriageButtonsProps) => {+ const { t } = useLingui();++ if (status === 'done') {+ return (+ <Button+ size="sm"+ startIcon={<IconArrowBackUp />}+ disabled={isPending}+ onClick={onReopen}+ >+ {t`Reopen`}+ </Button>+ );+ }++ return (+ <>+ <Button+ size="sm"+ startIcon={<IconZzz />}+ disabled={isPending}+ onClick={onSnooze}+ >+ {status === 'snoozed' ? t`Change` : t`Snooze`}+ </Button>+ <Button+ size="sm"+ startIcon={status === 'snoozed' ? <IconBell /> : <IconCheck />}+ disabled={isPending}+ onClick={status === 'snoozed' ? onReopen : onDone}+ >+ {status === 'snoozed' ? t`Wake now` : t`Done`}+ </Button>+ </>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatInboxBulkActions.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatInboxBulkActions.stories.tsxnew file mode 100644index 00000000000..b92d06da3e9--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatInboxBulkActions.stories.tsx@@ -0,0 +1,77 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, fn, userEvent, within } from 'storybook/test';+import { ComponentDecorator } from 'twenty-ui/testing';++import { AiChatInboxBulkActions } from '@/ai/components/AiChatInboxBulkActions';++const meta: Meta<typeof AiChatInboxBulkActions> = {+ title: 'Modules/AI/AiChatInboxBulkActions',+ component: AiChatInboxBulkActions,+ decorators: [ComponentDecorator],+ parameters: { container: { width: 560 } },+ args: {+ selectedCount: 3,+ onDone: fn(),+ onSnooze: fn(),+ onClearSelection: fn(),+ },+};++export default meta;+type Story = StoryObj<typeof AiChatInboxBulkActions>;++export const Selection: Story = {+ args: { onMarkAllDone: fn() },+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);++ await expect(canvas.getByText('3 selected')).toBeVisible();+ await expect(+ canvas.queryByRole('button', { name: 'Mark all done' }),+ ).not.toBeInTheDocument();+ await userEvent.click(canvas.getByRole('button', { name: 'Snooze' }));+ await expect(args.onSnooze).toHaveBeenCalledTimes(1);+ await userEvent.click(canvas.getByRole('button', { name: 'Done' }));+ await expect(args.onDone).toHaveBeenCalledTimes(1);+ await userEvent.click(+ canvas.getByRole('button', { name: 'Clear selection' }),+ );+ await expect(args.onClearSelection).toHaveBeenCalledTimes(1);+ await expect(args.onMarkAllDone).not.toHaveBeenCalled();+ },+};++export const MarkAllDone: Story = {+ args: { selectedCount: 0, onMarkAllDone: fn() },+ play: async ({ canvasElement, args }) => {+ await userEvent.click(+ within(canvasElement).getByRole('button', { name: 'Mark all done' }),+ );+ await expect(args.onMarkAllDone).toHaveBeenCalledTimes(1);+ await expect(args.onDone).not.toHaveBeenCalled();+ },+};++export const NoAllMatchingAction: Story = {+ args: { selectedCount: 0 },+ play: async ({ canvasElement }) => {+ await expect(+ within(canvasElement).queryByRole('button'),+ ).not.toBeInTheDocument();+ },+};++export const Pending: Story = {+ args: { disabled: true },+ play: async ({ canvasElement, args }) => {+ const button = within(canvasElement).getByRole('button', { name: 'Done' });++ await expect(button).toBeDisabled();+ await userEvent.click(button);+ await expect(args.onDone).not.toHaveBeenCalled();+ },+};++export const NarrowSelection: Story = {+ parameters: { container: { width: 240 } },+};diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatSnoozeMenu.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatSnoozeMenu.stories.tsxnew file mode 100644index 00000000000..2b81d9e6f8e--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatSnoozeMenu.stories.tsx@@ -0,0 +1,136 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { type ComponentProps, useState } from 'react';+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';+import { ComponentDecorator } from 'twenty-ui/testing';++import { AiChatSnoozeMenu } from '@/ai/components/AiChatSnoozeMenu';+import { getAgentChatThreadSnoozeOptions } from '@/ai/utils/getAgentChatThreadSnoozeOptions';++const SNOOZE_PREVIEW_TIME_ZONE = 'UTC';+const SNOOZE_PREVIEW_DATE = new Date('2026-10-21T15:00:00Z');+const snoozePresetDateFormatter = new Intl.DateTimeFormat('en-GB', {+ weekday: 'short',+ hour: '2-digit',+ minute: '2-digit',+ timeZone: SNOOZE_PREVIEW_TIME_ZONE,+});++const ControlledSnoozeMenu = ({+ open: initialOpen,+ onOpenChange,+ presets,+ onSelectPreset,+ onPickDate,+ onSomeoneReplies,+ onAssistantFinishes,+ assistantName,+ disabled,+}: ComponentProps<typeof AiChatSnoozeMenu>) => {+ const [open, setOpen] = useState(initialOpen);++ return (+ <AiChatSnoozeMenu+ open={open}+ onOpenChange={(nextOpen) => {+ setOpen(nextOpen);+ onOpenChange(nextOpen);+ }}+ presets={presets}+ onSelectPreset={onSelectPreset}+ onPickDate={onPickDate}+ onSomeoneReplies={onSomeoneReplies}+ onAssistantFinishes={onAssistantFinishes}+ assistantName={assistantName}+ disabled={disabled}+ />+ );+};++const meta: Meta<typeof AiChatSnoozeMenu> = {+ title: 'Modules/AI/AiChatSnoozeMenu',+ component: AiChatSnoozeMenu,+ decorators: [ComponentDecorator],+ render: ControlledSnoozeMenu,+ parameters: { container: { width: 320, height: 360 } },+ args: {+ open: false,+ onOpenChange: fn(),+ presets: getAgentChatThreadSnoozeOptions({+ now: SNOOZE_PREVIEW_DATE,+ timeZone: SNOOZE_PREVIEW_TIME_ZONE,+ }).map((option) => ({+ ...option,+ description: snoozePresetDateFormatter.format(option.date),+ })),+ onSelectPreset: fn(),+ onPickDate: fn(),+ },+};++export default meta;+type Story = StoryObj<typeof AiChatSnoozeMenu>;++export const TimedPresets: Story = {+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ const trigger = canvas.getByRole('button', { name: 'Snooze' });++ await userEvent.click(trigger);+ await expect(await body.findByRole('menu')).toBeVisible();+ await expect(+ body.queryByRole('menuitem', { name: 'Someone replies' }),+ ).not.toBeInTheDocument();+ await userEvent.click(body.getByRole('menuitem', { name: /Tomorrow/ }));+ await expect(args.onSelectPreset).toHaveBeenCalledWith('tomorrow');+ await waitFor(() =>+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),+ );+ await expect(trigger).toHaveFocus();+ await userEvent.click(trigger);+ await userEvent.click(+ await body.findByRole('menuitem', { name: 'Pick a date' }),+ );+ await expect(args.onPickDate).toHaveBeenCalledTimes(1);+ },+};++export const EventWaits: Story = {+ args: { onSomeoneReplies: fn(), onAssistantFinishes: fn() },+ play: async ({ canvasElement, args }) => {+ const trigger = within(canvasElement).getByRole('button', {+ name: 'Snooze',+ });+ const body = within(canvasElement.ownerDocument.body);++ await userEvent.click(trigger);+ await userEvent.click(+ await body.findByRole('menuitem', { name: 'Someone replies' }),+ );+ await expect(args.onSomeoneReplies).toHaveBeenCalledTimes(1);+ await waitFor(() =>+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),+ );+ await userEvent.click(trigger);+ await userEvent.click(+ await body.findByRole('menuitem', { name: 'When Ada finishes' }),+ );+ await expect(args.onAssistantFinishes).toHaveBeenCalledTimes(1);+ await expect(args.onSelectPreset).not.toHaveBeenCalled();+ },+};++export const Disabled: Story = {+ args: { disabled: true },+ play: async ({ canvasElement }) => {+ const trigger = within(canvasElement).getByRole('button', {+ name: 'Snooze',+ });++ await expect(trigger).toBeDisabled();+ await userEvent.click(trigger);+ await expect(+ within(canvasElement.ownerDocument.body).queryByRole('menu'),+ ).not.toBeInTheDocument();+ },+};diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadListGroup.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadListGroup.stories.tsxnew file mode 100644index 00000000000..9abe135b179--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadListGroup.stories.tsx@@ -0,0 +1,60 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { Avatar } from 'twenty-ui/primitives/data-display';+import { ListItem } from 'twenty-ui/primitives/navigation';+import { ComponentDecorator } from 'twenty-ui/testing';++import { AiChatThreadListGroup } from '@/ai/components/AiChatThreadListGroup';++const meta: Meta<typeof AiChatThreadListGroup> = {+ title: 'Modules/AI/AiChatThreadListGroup',+ component: AiChatThreadListGroup,+ decorators: [ComponentDecorator],+ parameters: { container: { width: 560 } },+};++export default meta;+type Story = StoryObj<typeof AiChatThreadListGroup>;++export const Snoozed: Story = {+ render: () => (+ <>+ <AiChatThreadListGroup title="Later today" count={1}>+ <ListItem+ startIcon={<Avatar name="Sarah Lin" size="sm" />}+ description="18:00"+ descriptionPlacement="end"+ >+ Churn risk accounts+ </ListItem>+ </AiChatThreadListGroup>+ <AiChatThreadListGroup title="Tomorrow" count={2}>+ <ListItem+ startIcon={<Avatar name="Sarah Lin" size="sm" />}+ description="09:00"+ descriptionPlacement="end"+ >+ Event sponsorship deck+ </ListItem>+ <ListItem description="09:00" descriptionPlacement="end">+ Board deck numbers+ </ListItem>+ </AiChatThreadListGroup>+ <AiChatThreadListGroup title="Until something happens" count={1}>+ <ListItem description="When Ada finishes" descriptionPlacement="end">+ Q4 forecast+ </ListItem>+ </AiChatThreadListGroup>+ </>+ ),+};++export const WithoutCount: Story = {+ args: {+ title: 'Tomorrow',+ children: (+ <ListItem description="09:00" descriptionPlacement="end">+ Board deck numbers+ </ListItem>+ ),+ },+};diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadReasonBadge.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadReasonBadge.stories.tsxnew file mode 100644index 00000000000..6d4cce91406--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadReasonBadge.stories.tsx@@ -0,0 +1,25 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { ComponentDecorator } from 'twenty-ui/testing';++import { AiChatThreadReasonBadge } from '@/ai/components/AiChatThreadReasonBadge';++const meta = {+ title: 'Modules/AI/AiChatThreadReasonBadge',+ component: AiChatThreadReasonBadge,+ decorators: [ComponentDecorator],+ args: { isUnread: true },+} satisfies Meta<typeof AiChatThreadReasonBadge>;++export default meta;+type Story = StoryObj<typeof meta>;++export const NeedsInput: Story = { args: { reason: 'needsInput' } };+export const Mentioned: Story = { args: { reason: 'mentioned' } };+export const Assigned: Story = { args: { reason: 'assigned' } };+export const Finished: Story = { args: { reason: 'finished' } };+export const Failed: Story = { args: { reason: 'failed' } };+export const Cancelled: Story = { args: { reason: 'cancelled' } };+export const Draft: Story = { args: { reason: 'draft' } };+export const ReadOutcome: Story = {+ args: { reason: 'finished', isUnread: false },+};diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadRequestActions.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadRequestActions.stories.tsxnew file mode 100644index 00000000000..d3b63e0ab53--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadRequestActions.stories.tsx@@ -0,0 +1,90 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, fn, userEvent, within } from 'storybook/test';+import { Avatar } from 'twenty-ui/primitives/data-display';+import { ComponentDecorator } from 'twenty-ui/testing';++import { AiChatThreadRequestActions } from '@/ai/components/AiChatThreadRequestActions';++const onChoose = fn();+const onReview = fn();+const onReply = fn();++const meta: Meta<typeof AiChatThreadRequestActions> = {+ title: 'Modules/AI/AiChatThreadRequestActions',+ component: AiChatThreadRequestActions,+ decorators: [ComponentDecorator],+ parameters: { container: { width: 560 } },+};++export default meta;+type Story = StoryObj<typeof AiChatThreadRequestActions>;++export const Choices: Story = {+ args: {+ request: {+ type: 'choices',+ choices: [+ {+ id: 'marco',+ label: 'Marco Rossi',+ avatar: <Avatar name="Marco Rossi" size="xs" />,+ },+ {+ id: 'sarah',+ label: 'Sarah Lin',+ avatar: <Avatar name="Sarah Lin" size="xs" />,+ },+ { id: 'me', label: 'Me', avatar: <Avatar name="Thomas" size="xs" /> },+ ],+ onChoose,+ },+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ await userEvent.click(canvas.getByRole('button', { name: 'Sarah Lin' }));+ await expect(onChoose).toHaveBeenCalledWith('sarah');+ await expect(onChoose).toHaveBeenCalledTimes(1);+ },+};++export const ReviewSummary: Story = {+ args: {+ request: { type: 'review', label: 'Review 5 drafts', onReview },+ },+ play: async ({ canvasElement }) => {+ await userEvent.click(+ within(canvasElement).getByRole('button', { name: 'Review 5 drafts' }),+ );+ await expect(onReview).toHaveBeenCalledTimes(1);+ },+};++export const Reply: Story = {+ args: { request: { type: 'reply', onReply } },+ play: async ({ canvasElement }) => {+ const button = within(canvasElement).getByRole('button', { name: 'Reply' });++ await userEvent.tab();+ await expect(button).toHaveFocus();+ await userEvent.keyboard('{Enter}');+ await expect(onReply).toHaveBeenCalledTimes(1);+ },+};++export const Pending: Story = {+ args: { ...Choices.args, isLoading: true },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const button = canvas.getByRole('button', { name: 'Sarah Lin' });++ await expect(button).toBeDisabled();+ await userEvent.click(button);+ await expect(onChoose).not.toHaveBeenCalled();+ },+};++export const NarrowChoices: Story = {+ args: Choices.args,+ parameters: { container: { width: 220 } },+};diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadRow.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadRow.stories.tsxnew file mode 100644index 00000000000..89c9b1e4a87--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadRow.stories.tsx@@ -0,0 +1,311 @@+import { styled } from '@linaria/react';+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';+import { Avatar } from 'twenty-ui/primitives/data-display';+import { Input } from 'twenty-ui/primitives/input';+import { Text } from 'twenty-ui/primitives/typography';+import { ComponentDecorator } from 'twenty-ui/testing';+import { themeCssVariables } from 'twenty-ui/theme';++import { AiChatThreadReasonBadge } from '@/ai/components/AiChatThreadReasonBadge';+import { AiChatThreadRequestActions } from '@/ai/components/AiChatThreadRequestActions';+import { AiChatThreadRow } from '@/ai/components/AiChatThreadRow';+import { AiChatThreadTriageButtons } from '@/ai/components/AiChatThreadTriageButtons';++const StyledSubtitle = styled.div`+ align-items: center;+ display: flex;+ gap: ${themeCssVariables.spacing[1]};+ min-width: 0;+`;++const onDone = fn();+const onSnooze = fn();+const onReopen = fn();+const onReview = fn();++const meta = {+ title: 'Modules/AI/AiChatThreadRow',+ component: AiChatThreadRow,+ decorators: [ComponentDecorator],+ parameters: { container: { width: 760 } },+ args: {+ id: 'renewal-outreach',+ label: 'Q3 renewal outreach',+ avatar: <Avatar name="Sarah Lin" size="lg" shape="circle" />,+ title: (+ <Text size="md" weight="medium" truncate>+ Q3 renewal outreach+ </Text>+ ),+ subtitle: (+ <Text size="sm" color="tertiary" truncate>+ Sarah: I drafted five check-in emails for the October renewals.+ </Text>+ ),+ activityTime: (+ <Text size="sm" color="tertiary">+ 09:48+ </Text>+ ),+ actions: (+ <AiChatThreadTriageButtons+ status="open"+ onDone={onDone}+ onSnooze={onSnooze}+ onReopen={onReopen}+ />+ ),+ onClick: fn(),+ onCheckboxClick: fn(),+ onContextMenu: fn(),+ },+} satisfies Meta<typeof AiChatThreadRow>;++export default meta;+type Story = StoryObj<typeof meta>;++export const Open: Story = {+ play: async ({ canvasElement, args }) => {+ const user = userEvent.setup();+ const canvas = within(canvasElement);+ const row = canvas.getByRole('group', { name: 'Q3 renewal outreach' });++ await user.hover(row);+ await user.click(canvas.getByRole('button', { name: 'Snooze' }));+ await expect(onSnooze).toHaveBeenCalledTimes(1);+ await user.click(canvas.getByRole('button', { name: 'Done' }));+ await expect(onDone).toHaveBeenCalledTimes(1);+ await expect(args.onClick).not.toHaveBeenCalled();+ await user.keyboard('{Shift>}');+ await user.click(canvas.getByRole('checkbox', { name: 'Select chat' }));+ await user.keyboard('{/Shift}');+ await expect(args.onCheckboxClick).toHaveBeenCalledTimes(1);+ await expect(args.onCheckboxClick).toHaveBeenCalledWith(+ expect.objectContaining({ shiftKey: true }),+ );+ await expect(args.onClick).not.toHaveBeenCalled();+ },+};++export const Keyboard: Story = {+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const row = canvas.getByRole('group', { name: 'Q3 renewal outreach' });++ await userEvent.tab();+ await expect(row).toHaveFocus();+ await waitFor(() =>+ expect(canvas.getByRole('button', { name: 'Done' })).toBeVisible(),+ );+ await userEvent.keyboard('{Enter}');+ await expect(args.onClick).toHaveBeenCalledTimes(1);+ await userEvent.tab();+ await expect(+ canvas.getByRole('checkbox', { name: 'Select chat' }),+ ).toHaveFocus();+ await userEvent.keyboard(' ');+ await expect(args.onCheckboxClick).toHaveBeenCalledTimes(1);+ await expect(args.onClick).toHaveBeenCalledTimes(1);+ },+};++export const Editing: Story = {+ args: {+ isEditing: true,+ activityTime: undefined,+ title: (+ <Input aria-label="Rename chat" defaultValue="Q3 renewal outreach" />+ ),+ },+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const row = canvas.getByRole('group', { name: 'Q3 renewal outreach' });+ const input = canvas.getByRole('textbox', { name: 'Rename chat' });++ await userEvent.click(row);+ await expect(row).toHaveFocus();+ await userEvent.keyboard('{Enter} ');+ await userEvent.pointer({ target: row, keys: '[MouseRight]' });+ await userEvent.type(input, ' updated');+ await expect(input).toHaveValue('Q3 renewal outreach updated');+ await userEvent.keyboard('{Enter} ');+ await userEvent.pointer({ target: input, keys: '[MouseRight]' });+ await expect(args.onClick).not.toHaveBeenCalled();+ await expect(args.onContextMenu).not.toHaveBeenCalled();+ },+};++export const ActionMenuOpen: Story = {+ args: { isActionMenuOpen: true },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const row = canvas.getByRole('group', { name: 'Q3 renewal outreach' });++ await userEvent.hover(row);+ await userEvent.unhover(row);+ await expect(canvas.getByRole('button', { name: 'Snooze' })).toBeVisible();+ await expect(canvas.getByRole('button', { name: 'Done' })).toBeVisible();+ await expect(canvas.getByText('09:48')).not.toBeVisible();+ },+};++export const WithoutOptionalControls: Story = {+ args: { actions: undefined, onCheckboxClick: undefined },+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const row = canvas.getByRole('group', { name: 'Q3 renewal outreach' });+ const activityTime = canvas.getByText('09:48');++ await userEvent.hover(row);+ await expect(activityTime).toBeVisible();+ await expect(canvas.queryByRole('checkbox')).not.toBeInTheDocument();+ await expect(canvas.queryByRole('button')).not.toBeInTheDocument();+ await userEvent.unhover(row);+ await userEvent.tab();+ await expect(row).toHaveFocus();+ await expect(activityTime).toBeVisible();+ await userEvent.click(row);+ await expect(args.onClick).toHaveBeenCalledTimes(1);+ },+};++export const UnreadRequest: Story = {+ args: {+ title: (+ <Text size="md" weight="semibold" truncate>+ Q3 renewal outreach+ </Text>+ ),+ subtitle: (+ <StyledSubtitle>+ <AiChatThreadReasonBadge reason="needsInput" isUnread />+ <Text size="sm" color="secondary" truncate>+ Ada: Five renewal drafts are ready for your review.+ </Text>+ </StyledSubtitle>+ ),+ children: (+ <AiChatThreadRequestActions+ request={{ type: 'review', label: 'Review 5 drafts', onReview }}+ />+ ),+ },+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);++ await userEvent.click(+ canvas.getByRole('button', { name: 'Review 5 drafts' }),+ );+ await expect(onReview).toHaveBeenCalledTimes(1);+ await expect(args.onClick).not.toHaveBeenCalled();+ },+};++export const Selected: Story = { args: { isSelected: true } };+export const Checked: Story = { args: { isChecked: true } };++export const NarrowDraft: Story = {+ parameters: { container: { width: 320 } },+ args: {+ subtitle: (+ <StyledSubtitle>+ <AiChatThreadReasonBadge reason="needsInput" isUnread />+ <AiChatThreadReasonBadge reason="draft" />+ <Text size="sm" color="tertiary" truncate>+ Quote the annual plan and include the renewal details+ </Text>+ </StyledSubtitle>+ ),+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const row = canvas.getByRole('group', { name: 'Q3 renewal outreach' });+ const activityTime = canvas.getByText('09:48');+ const subtitle = canvas.getByText(+ 'Quote the annual plan and include the renewal details',+ );++ await userEvent.tab();+ await expect(row).toHaveFocus();+ const doneButton = canvas.getByRole('button', { name: 'Done' });+ await waitFor(() => expect(doneButton).toBeVisible());+ await expect(activityTime).toBeVisible();+ await expect(doneButton.getBoundingClientRect().top).toBeGreaterThanOrEqual(+ subtitle.getBoundingClientRect().bottom,+ );+ await expect(row.scrollWidth).toBeLessThanOrEqual(row.clientWidth);+ await userEvent.tab();+ await expect(+ canvas.getByRole('checkbox', { name: 'Select chat' }),+ ).toHaveFocus();+ await userEvent.tab();+ const snoozeButton = canvas.getByRole('button', { name: 'Snooze' });+ await expect(snoozeButton).toHaveFocus();+ await waitFor(() => expect(snoozeButton).toBeVisible());+ await expect(activityTime).toBeVisible();+ await expect(+ snoozeButton.getBoundingClientRect().top,+ ).toBeGreaterThanOrEqual(subtitle.getBoundingClientRect().bottom);+ await expect(row.scrollWidth).toBeLessThanOrEqual(row.clientWidth);+ },+};++export const SplitDraft: Story = {+ ...NarrowDraft,+ parameters: { container: { width: 400 } },+};++export const Snoozed: Story = {+ args: {+ activityTime: (+ <Text size="sm" color="tertiary">+ Thu · 09:00+ </Text>+ ),+ actions: (+ <AiChatThreadTriageButtons+ status="snoozed"+ onDone={onDone}+ onSnooze={onSnooze}+ onReopen={onReopen}+ />+ ),+ },+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ await userEvent.hover(+ canvas.getByRole('group', { name: 'Q3 renewal outreach' }),+ );+ await userEvent.click(canvas.getByRole('button', { name: 'Change' }));+ await expect(onSnooze).toHaveBeenCalledTimes(1);+ await userEvent.click(canvas.getByRole('button', { name: 'Wake now' }));+ await expect(onReopen).toHaveBeenCalledTimes(1);+ await expect(args.onClick).not.toHaveBeenCalled();+ },+};++export const Done: Story = {+ args: {+ actions: (+ <AiChatThreadTriageButtons+ status="done"+ onDone={onDone}+ onSnooze={onSnooze}+ onReopen={onReopen}+ />+ ),+ },+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ await userEvent.hover(+ canvas.getByRole('group', { name: 'Q3 renewal outreach' }),+ );+ await expect(+ canvas.queryByRole('button', { name: 'Done' }),+ ).not.toBeInTheDocument();+ await userEvent.click(canvas.getByRole('button', { name: 'Reopen' }));+ await expect(onReopen).toHaveBeenCalledTimes(1);+ await expect(args.onClick).not.toHaveBeenCalled();+ },+};diff --git a/packages/twenty-front/src/modules/ai/constants/AiChatThreadReasons.ts b/packages/twenty-front/src/modules/ai/constants/AiChatThreadReasons.tsnew file mode 100644index 00000000000..14135e075b4--- /dev/null+++ b/packages/twenty-front/src/modules/ai/constants/AiChatThreadReasons.ts@@ -0,0 +1,27 @@+import { type MessageDescriptor } from '@lingui/core';+import { msg } from '@lingui/core/macro';+import {+ IconAlertCircle,+ IconAt,+ IconCheck,+ type IconComponent,+ IconHandClick,+ IconPencil,+ IconUsers,+ IconX,+} from 'twenty-ui/icon';++import { type AiChatThreadReason } from '@/ai/types/AiChatThreadReason';++export const AI_CHAT_THREAD_REASONS: Record<+ AiChatThreadReason,+ { Icon: IconComponent; label: MessageDescriptor }+> = {+ needsInput: { Icon: IconHandClick, label: msg`Needs input` },+ mentioned: { Icon: IconAt, label: msg`Mentioned you` },+ assigned: { Icon: IconUsers, label: msg`Assigned to you` },+ finished: { Icon: IconCheck, label: msg`Finished` },+ failed: { Icon: IconAlertCircle, label: msg`Failed` },+ cancelled: { Icon: IconX, label: msg`Cancelled` },+ draft: { Icon: IconPencil, label: msg`Draft` },+};diff --git a/packages/twenty-front/src/modules/ai/hooks/useExecuteAgentChatThreadInboxAction.ts b/packages/twenty-front/src/modules/ai/hooks/useExecuteAgentChatThreadInboxAction.tsnew file mode 100644index 00000000000..51ae442b49f--- /dev/null+++ b/packages/twenty-front/src/modules/ai/hooks/useExecuteAgentChatThreadInboxAction.ts@@ -0,0 +1,47 @@+import { useState } from 'react';+import { isNonEmptyArray } from 'twenty-shared/utils';++import { useUpdateAgentChatThreadInboxState } from '@/ai/hooks/useUpdateAgentChatThreadInboxState';+import { useOpenAssignAiChatInSidePanel } from '@/side-panel/hooks/useOpenAssignAiChatInSidePanel';+import { useOpenSnoozeAiChatInSidePanel } from '@/side-panel/hooks/useOpenSnoozeAiChatInSidePanel';+import { AgentChatInboxAction } from '~/generated-metadata/graphql';++export const useExecuteAgentChatThreadInboxAction = () => {+ const [isPending, setIsPending] = useState(false);+ const { updateAgentChatThreadInboxState } =+ useUpdateAgentChatThreadInboxState();+ const { openSnoozeAiChatInSidePanel } = useOpenSnoozeAiChatInSidePanel();+ const { openAssignAiChatInSidePanel } = useOpenAssignAiChatInSidePanel();++ const executeAgentChatThreadInboxAction = async ({+ threadIds,+ action,+ }: {+ threadIds: string[];+ action: AgentChatInboxAction | 'assign';+ }) => {+ if (!isNonEmptyArray(threadIds) || isPending) {+ return;+ }++ if (action === AgentChatInboxAction.SNOOZE) {+ openSnoozeAiChatInSidePanel(threadIds);+ return;+ }++ if (action === 'assign') {+ openAssignAiChatInSidePanel(threadIds);+ return;+ }++ setIsPending(true);++ try {+ await updateAgentChatThreadInboxState({ threadIds, action });+ } finally {+ setIsPending(false);+ }+ };++ return { executeAgentChatThreadInboxAction, isPending };+};diff --git a/packages/twenty-front/src/modules/ai/types/AiChatSnoozePreset.ts b/packages/twenty-front/src/modules/ai/types/AiChatSnoozePreset.tsnew file mode 100644index 00000000000..673b7fd4a7f--- /dev/null+++ b/packages/twenty-front/src/modules/ai/types/AiChatSnoozePreset.ts@@ -0,0 +1,5 @@+import { type AgentChatThreadSnoozeOption } from '@/ai/utils/getAgentChatThreadSnoozeOptions';++export type AiChatSnoozePreset = AgentChatThreadSnoozeOption & {+ description?: string;+};diff --git a/packages/twenty-front/src/modules/ai/types/AiChatThreadReason.ts b/packages/twenty-front/src/modules/ai/types/AiChatThreadReason.tsnew file mode 100644index 00000000000..0910f8c3f94--- /dev/null+++ b/packages/twenty-front/src/modules/ai/types/AiChatThreadReason.ts@@ -0,0 +1,8 @@+export type AiChatThreadReason =+ | 'needsInput'+ | 'mentioned'+ | 'assigned'+ | 'finished'+ | 'failed'+ | 'cancelled'+ | 'draft';diff --git a/packages/twenty-front/src/modules/ai/types/AiChatThreadRequest.ts b/packages/twenty-front/src/modules/ai/types/AiChatThreadRequest.tsnew file mode 100644index 00000000000..93a4afe3707--- /dev/null+++ b/packages/twenty-front/src/modules/ai/types/AiChatThreadRequest.ts@@ -0,0 +1,10 @@+import { type ReactNode } from 'react';++export type AiChatThreadRequest =+ | {+ type: 'choices';+ choices: { id: string; label: string; avatar?: ReactNode }[];+ onChoose: (choiceId: string) => void;+ }+ | { type: 'review'; label: string; onReview: () => void }+ | { type: 'reply'; onReply: () => void };diff --git a/packages/twenty-front/src/modules/command-menu-item/engine-command/record/components/AgentChatThreadInboxCommand.tsx b/packages/twenty-front/src/modules/command-menu-item/engine-command/record/components/AgentChatThreadInboxCommand.tsxindex 45178339a6e..23991697d7c 100644--- a/packages/twenty-front/src/modules/command-menu-item/engine-command/record/components/AgentChatThreadInboxCommand.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/engine-command/record/components/AgentChatThreadInboxCommand.tsx@@ -1,9 +1,7 @@-import { useUpdateAgentChatThreadInboxState } from '@/ai/hooks/useUpdateAgentChatThreadInboxState';+import { useExecuteAgentChatThreadInboxAction } from '@/ai/hooks/useExecuteAgentChatThreadInboxAction';import { HeadlessEngineCommandWrapperEffect } from '@/command-menu-item/engine-command/components/HeadlessEngineCommandWrapperEffect';import { useHeadlessCommandContextApi } from '@/command-menu-item/engine-command/hooks/useHeadlessCommandContextApi';-import { useOpenAssignAiChatInSidePanel } from '@/side-panel/hooks/useOpenAssignAiChatInSidePanel';-import { useOpenSnoozeAiChatInSidePanel } from '@/side-panel/hooks/useOpenSnoozeAiChatInSidePanel';-import { AgentChatInboxAction } from '~/generated-metadata/graphql';+import { type AgentChatInboxAction } from '~/generated-metadata/graphql';type AgentChatThreadInboxCommandProps = {action: AgentChatInboxAction | 'assign';@@ -13,28 +11,14 @@ export const AgentChatThreadInboxCommand = ({action,}: AgentChatThreadInboxCommandProps) => {const { selectedRecords } = useHeadlessCommandContextApi();- const { updateAgentChatThreadInboxState } =- useUpdateAgentChatThreadInboxState();- const { openSnoozeAiChatInSidePanel } = useOpenSnoozeAiChatInSidePanel();- const { openAssignAiChatInSidePanel } = useOpenAssignAiChatInSidePanel();-- const handleExecute = async () => {- const threadIds = selectedRecords.map(({ id }) => id);-- if (threadIds.length === 0) {- return;- }-- if (action === AgentChatInboxAction.SNOOZE) {- return openSnoozeAiChatInSidePanel(threadIds);- }-- if (action === 'assign') {- return openAssignAiChatInSidePanel(threadIds);- }-- await updateAgentChatThreadInboxState({ threadIds, action });- };+ const { executeAgentChatThreadInboxAction } =+ useExecuteAgentChatThreadInboxAction();++ const handleExecute = () =>+ executeAgentChatThreadInboxAction({+ threadIds: selectedRecords.map(({ id }) => id),+ action,+ });return <HeadlessEngineCommandWrapperEffect execute={handleExecute} />;};