diff --git a/packages/twenty-front/src/modules/ai/components/AIChatErrorMessage.tsx b/packages/twenty-front/src/modules/ai/components/AIChatErrorMessage.tsx index e10c880fb1..a47abe027a 100644 --- a/packages/twenty-front/src/modules/ai/components/AIChatErrorMessage.tsx +++ b/packages/twenty-front/src/modules/ai/components/AIChatErrorMessage.tsx @@ -1,5 +1,4 @@ import { useAgentChatContextOrThrow } from '@/ai/hooks/useAgentChatContextOrThrow'; -import { type ObjectRecord } from '@/object-record/types/ObjectRecord'; import { useTheme } from '@emotion/react'; import styled from '@emotion/styled'; import { t } from '@lingui/core/macro'; @@ -43,8 +42,6 @@ const StyledErrorMessage = styled.div` type AIChatErrorMessageProps = { error: Error; - records?: ObjectRecord[]; - isRetrying?: boolean; }; export const AIChatErrorMessage = ({ error }: AIChatErrorMessageProps) => { diff --git a/packages/twenty-front/src/modules/ai/components/AIChatMessage.tsx b/packages/twenty-front/src/modules/ai/components/AIChatMessage.tsx index f813afde04..32bac32251 100644 --- a/packages/twenty-front/src/modules/ai/components/AIChatMessage.tsx +++ b/packages/twenty-front/src/modules/ai/components/AIChatMessage.tsx @@ -8,10 +8,7 @@ import { AgentMessageRole } from '@/ai/constants/AgentMessageRole'; import { AIChatAssistantMessageRenderer } from '@/ai/components/AIChatAssistantMessageRenderer'; import { AIChatErrorMessage } from '@/ai/components/AIChatErrorMessage'; -import { AIChatErrorMessageWithRecordsContext } from '@/ai/components/internal/AIChatErrorMessageWithRecordsContext'; -import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState'; import { LightCopyIconButton } from '@/object-record/record-field/ui/components/LightCopyIconButton'; -import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue'; import { type ExtendedUIMessage } from 'twenty-shared/ai'; import { isDefined } from 'twenty-shared/utils'; import { dateLocaleState } from '~/localization/states/dateLocaleState'; @@ -156,10 +153,6 @@ export const AIChatMessage = ({ const theme = useTheme(); const { localeCatalog } = useRecoilValue(dateLocaleState); - const contextStoreCurrentObjectMetadataItemId = useRecoilComponentValue( - contextStoreCurrentObjectMetadataItemIdComponentState, - ); - const showError = isDefined(error) && message.role === AgentMessageRole.ASSISTANT; @@ -201,12 +194,7 @@ export const AIChatMessage = ({ ))} )} - {showError && - (contextStoreCurrentObjectMetadataItemId ? ( - - ) : ( - - ))} + {showError && } {message.parts.length > 0 && message.metadata?.createdAt && ( diff --git a/packages/twenty-front/src/modules/ai/components/AIChatTab.tsx b/packages/twenty-front/src/modules/ai/components/AIChatTab.tsx index c45a668cdd..1368a915a0 100644 --- a/packages/twenty-front/src/modules/ai/components/AIChatTab.tsx +++ b/packages/twenty-front/src/modules/ai/components/AIChatTab.tsx @@ -14,14 +14,11 @@ import { AIChatMessage } from '@/ai/components/AIChatMessage'; import { AIChatSkeletonLoader } from '@/ai/components/internal/AIChatSkeletonLoader'; import { AgentChatContextPreview } from '@/ai/components/internal/AgentChatContextPreview'; import { SendMessageButton } from '@/ai/components/internal/SendMessageButton'; -import { SendMessageWithRecordsContextButton } from '@/ai/components/internal/SendMessageWithRecordsContextButton'; import { AI_CHAT_INPUT_ID } from '@/ai/constants/AiChatInputId'; import { AI_CHAT_SCROLL_WRAPPER_ID } from '@/ai/constants/AiChatScrollWrapperId'; import { useAIChatFileUpload } from '@/ai/hooks/useAIChatFileUpload'; import { useAgentChatContextOrThrow } from '@/ai/hooks/useAgentChatContextOrThrow'; import { agentChatInputState } from '@/ai/states/agentChatInputState'; -import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState'; -import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue'; import { t } from '@lingui/core/macro'; import { useState } from 'react'; import { useRecoilState } from 'recoil'; @@ -71,10 +68,6 @@ export const AIChatTab = () => { const [agentChatInput, setAgentChatInput] = useRecoilState(agentChatInputState); - const contextStoreCurrentObjectMetadataItemId = useRecoilComponentValue( - contextStoreCurrentObjectMetadataItemIdComponentState, - ); - const { uploadFiles } = useAIChatFileUpload(); const { createChatThread } = useCreateNewAIChatThread(); const { navigateCommandMenu } = useCommandMenu(); @@ -145,11 +138,7 @@ export const AIChatTab = () => { onClick={() => createChatThread()} /> - {contextStoreCurrentObjectMetadataItemId ? ( - - ) : ( - - )} + diff --git a/packages/twenty-front/src/modules/ai/components/internal/AIChatErrorMessageWithRecordsContext.tsx b/packages/twenty-front/src/modules/ai/components/internal/AIChatErrorMessageWithRecordsContext.tsx deleted file mode 100644 index 08a6bc3aa4..0000000000 --- a/packages/twenty-front/src/modules/ai/components/internal/AIChatErrorMessageWithRecordsContext.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { AIChatErrorMessage } from '@/ai/components/AIChatErrorMessage'; -import { useFindManyRecordsSelectedInContextStore } from '@/context-store/hooks/useFindManyRecordsSelectedInContextStore'; - -export const AIChatErrorMessageWithRecordsContext = ({ - error, -}: { - error: Error; -}) => { - const { records } = useFindManyRecordsSelectedInContextStore({ - limit: 10, - }); - - return ; -}; diff --git a/packages/twenty-front/src/modules/ai/components/internal/AgentChatContextPreview.tsx b/packages/twenty-front/src/modules/ai/components/internal/AgentChatContextPreview.tsx index 409eac7101..4f02525b1b 100644 --- a/packages/twenty-front/src/modules/ai/components/internal/AgentChatContextPreview.tsx +++ b/packages/twenty-front/src/modules/ai/components/internal/AgentChatContextPreview.tsx @@ -1,8 +1,5 @@ -import { AgentChatContextRecordPreview } from '@/ai/components/internal/AgentChatContextRecordPreview'; import { agentChatSelectedFilesState } from '@/ai/states/agentChatSelectedFilesState'; import { agentChatUploadedFilesState } from '@/ai/states/agentChatUploadedFilesState'; -import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState'; -import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue'; import styled from '@emotion/styled'; import { useRecoilState } from 'recoil'; import { AgentChatFilePreview } from './AgentChatFilePreview'; @@ -29,15 +26,18 @@ export const AgentChatContextPreview = () => { agentChatUploadedFilesState, ); - const handleRemoveUploadedFile = async (fileIndex: number) => { + const handleRemoveUploadedFile = (fileIndex: number) => { setAgentChatUploadedFiles( - agentChatUploadedFiles.filter((f, index) => fileIndex !== index), + agentChatUploadedFiles.filter((_, index) => fileIndex !== index), ); }; - const contextStoreCurrentObjectMetadataItemId = useRecoilComponentValue( - contextStoreCurrentObjectMetadataItemIdComponentState, - ); + const hasFiles = + agentChatSelectedFiles.length > 0 || agentChatUploadedFiles.length > 0; + + if (!hasFiles) { + return null; + } return ( @@ -62,13 +62,6 @@ export const AgentChatContextPreview = () => { isUploading={false} /> ))} - {contextStoreCurrentObjectMetadataItemId && ( - - )} ); diff --git a/packages/twenty-front/src/modules/ai/components/internal/AgentChatContextRecordPreview.tsx b/packages/twenty-front/src/modules/ai/components/internal/AgentChatContextRecordPreview.tsx deleted file mode 100644 index 73060aa31b..0000000000 --- a/packages/twenty-front/src/modules/ai/components/internal/AgentChatContextRecordPreview.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import { isAgentChatCurrentContextActiveState } from '@/ai/states/isAgentChatCurrentContextActiveState'; -import { CommandMenuContextRecordChipAvatars } from '@/command-menu/components/CommandMenuContextRecordChipAvatars'; -import { getSelectedRecordsContextText } from '@/command-menu/utils/getRecordContextText'; -import { useFindManyRecordsSelectedInContextStore } from '@/context-store/hooks/useFindManyRecordsSelectedInContextStore'; -import { useObjectMetadataItemById } from '@/object-metadata/hooks/useObjectMetadataItemById'; -import { useTheme } from '@emotion/react'; -import styled from '@emotion/styled'; -import { t } from '@lingui/core/macro'; -import { useRecoilState } from 'recoil'; -import { MultipleAvatarChip } from 'twenty-ui/components'; -import { IconReload, IconX } from 'twenty-ui/display'; - -const StyledRightIconContainer = styled.div` - display: flex; - border-left: 1px solid ${({ theme }) => theme.border.color.light}; - - svg { - cursor: pointer; - } -`; - -const StyledChipWrapper = styled.div<{ isActive: boolean }>` - opacity: ${({ isActive }) => (isActive ? 1 : 0.7)}; -`; - -export const AgentChatContextRecordPreview = ({ - contextStoreCurrentObjectMetadataItemId, -}: { - contextStoreCurrentObjectMetadataItemId: string; -}) => { - const theme = useTheme(); - - const { records, totalCount } = useFindManyRecordsSelectedInContextStore({ - limit: 3, - }); - - const { objectMetadataItem } = useObjectMetadataItemById({ - objectId: contextStoreCurrentObjectMetadataItemId, - }); - - const [isAgentChatCurrentContextActive, setIsAgentChatCurrentContextActive] = - useRecoilState(isAgentChatCurrentContextActiveState); - - const Avatars = records.map((record) => ( - // @todo move this components to be less specific. (Outside of CommandMenu - - )); - - const recordSelectionContextChip = { - // @todo move this utils outside of CommandMenu - text: getSelectedRecordsContextText( - objectMetadataItem, - records, - totalCount ?? 0, - ), - Icons: Avatars, - withIconBackground: false, - }; - - const toggleIsAgentChatCurrentContextActive = () => { - setIsAgentChatCurrentContextActive(!isAgentChatCurrentContextActive); - }; - - return ( - <> - {records.length !== 0 && ( - - - {isAgentChatCurrentContextActive ? ( - - ) : ( - - )} - - } - /> - - )} - - ); -}; diff --git a/packages/twenty-front/src/modules/ai/components/internal/SendMessageButton.tsx b/packages/twenty-front/src/modules/ai/components/internal/SendMessageButton.tsx index 09bbe5b35c..f34d78f559 100644 --- a/packages/twenty-front/src/modules/ai/components/internal/SendMessageButton.tsx +++ b/packages/twenty-front/src/modules/ai/components/internal/SendMessageButton.tsx @@ -1,18 +1,13 @@ import { AI_CHAT_INPUT_ID } from '@/ai/constants/AiChatInputId'; import { useAgentChatContextOrThrow } from '@/ai/hooks/useAgentChatContextOrThrow'; import { agentChatInputState } from '@/ai/states/agentChatInputState'; -import { type ObjectRecord } from '@/object-record/types/ObjectRecord'; import { useHotkeysOnFocusedElement } from '@/ui/utilities/hotkey/hooks/useHotkeysOnFocusedElement'; import { t } from '@lingui/core/macro'; import { useRecoilValue } from 'recoil'; import { Key } from 'ts-key-enum'; import { Button } from 'twenty-ui/input'; -export const SendMessageButton = ({ - records, -}: { - records?: ObjectRecord[]; -}) => { +export const SendMessageButton = () => { const agentChatInput = useRecoilValue(agentChatInputState); const { handleSendMessage, isLoading } = useAgentChatContextOrThrow(); @@ -21,7 +16,7 @@ export const SendMessageButton = ({ callback: (event: KeyboardEvent) => { if (!event.ctrlKey && !event.metaKey) { event.preventDefault(); - handleSendMessage(records); + handleSendMessage(); } }, focusId: AI_CHAT_INPUT_ID, @@ -34,7 +29,7 @@ export const SendMessageButton = ({ return (