diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts index c6c9d1f49cc..45df30ff69b 100644 --- a/packages/twenty-front/src/generated-metadata/graphql.ts +++ b/packages/twenty-front/src/generated-metadata/graphql.ts @@ -70,7 +70,6 @@ export type Agent = { export type AgentChatMessage = { __typename?: 'AgentChatMessage'; createdAt: Scalars['DateTime']; - files: Array; id: Scalars['UUID']; parts: Array; role: Scalars['String']; @@ -1317,7 +1316,6 @@ export type File = { createdAt: Scalars['DateTime']; fullPath: Scalars['String']; id: Scalars['UUID']; - messageId?: Maybe; name: Scalars['String']; size: Scalars['Float']; type: Scalars['String']; @@ -4674,7 +4672,7 @@ export type GetAgentChatMessagesQueryVariables = Exact<{ }>; -export type GetAgentChatMessagesQuery = { __typename?: 'Query', agentChatMessages: Array<{ __typename?: 'AgentChatMessage', id: string, threadId: string, role: string, createdAt: string, parts: Array<{ __typename?: 'AgentChatMessagePart', id: string, messageId: string, orderIndex: number, type: string, textContent?: string | null, reasoningContent?: string | null, toolName?: string | null, toolCallId?: string | null, toolInput?: any | null, toolOutput?: any | null, state?: string | null, errorMessage?: string | null, errorDetails?: any | null, sourceUrlSourceId?: string | null, sourceUrlUrl?: string | null, sourceUrlTitle?: string | null, sourceDocumentSourceId?: string | null, sourceDocumentMediaType?: string | null, sourceDocumentTitle?: string | null, sourceDocumentFilename?: string | null, fileMediaType?: string | null, fileFilename?: string | null, fileUrl?: string | null, providerMetadata?: any | null, createdAt: string }>, files: Array<{ __typename?: 'File', id: string, name: string, fullPath: string, size: number, type: string, createdAt: string }> }> }; +export type GetAgentChatMessagesQuery = { __typename?: 'Query', agentChatMessages: Array<{ __typename?: 'AgentChatMessage', id: string, threadId: string, role: string, createdAt: string, parts: Array<{ __typename?: 'AgentChatMessagePart', id: string, messageId: string, orderIndex: number, type: string, textContent?: string | null, reasoningContent?: string | null, toolName?: string | null, toolCallId?: string | null, toolInput?: any | null, toolOutput?: any | null, state?: string | null, errorMessage?: string | null, errorDetails?: any | null, sourceUrlSourceId?: string | null, sourceUrlUrl?: string | null, sourceUrlTitle?: string | null, sourceDocumentSourceId?: string | null, sourceDocumentMediaType?: string | null, sourceDocumentTitle?: string | null, sourceDocumentFilename?: string | null, fileMediaType?: string | null, fileFilename?: string | null, fileUrl?: string | null, providerMetadata?: any | null, createdAt: string }> }> }; export type GetAgentChatThreadsQueryVariables = Exact<{ agentId: Scalars['UUID']; @@ -6963,14 +6961,6 @@ export const GetAgentChatMessagesDocument = gql` providerMetadata createdAt } - files { - id - name - fullPath - size - type - createdAt - } } } `; diff --git a/packages/twenty-front/src/generated/graphql.ts b/packages/twenty-front/src/generated/graphql.ts index 89f86748c0f..435d5b4204d 100644 --- a/packages/twenty-front/src/generated/graphql.ts +++ b/packages/twenty-front/src/generated/graphql.ts @@ -70,7 +70,6 @@ export type Agent = { export type AgentChatMessage = { __typename?: 'AgentChatMessage'; createdAt: Scalars['DateTime']; - files: Array; id: Scalars['UUID']; parts: Array; role: Scalars['String']; @@ -1281,7 +1280,6 @@ export type File = { createdAt: Scalars['DateTime']; fullPath: Scalars['String']; id: Scalars['UUID']; - messageId?: Maybe; name: Scalars['String']; size: Scalars['Float']; type: Scalars['String']; diff --git a/packages/twenty-front/src/modules/ai/components/AIChatTab.tsx b/packages/twenty-front/src/modules/ai/components/AIChatTab.tsx index 60fb33c92f1..2676cef8fb4 100644 --- a/packages/twenty-front/src/modules/ai/components/AIChatTab.tsx +++ b/packages/twenty-front/src/modules/ai/components/AIChatTab.tsx @@ -14,12 +14,15 @@ 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 { useAIChatFileUpload } from '@/ai/hooks/useAIChatFileUpload'; -import { type UIMessageWithMetadata } from '@/ai/types/UIMessageWithMetadata'; +import { useAgentChatContextOrThrow } from '@/ai/hooks/useAgentChatContextOrThrow'; +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 { Button } from 'twenty-ui/input'; -import { useAgentChat } from '../hooks/useAgentChat'; const StyledContainer = styled.div<{ isDraggingFile: boolean }>` background: ${({ theme }) => theme.background.primary}; @@ -56,13 +59,7 @@ const StyledButtonsContainer = styled.div` gap: ${({ theme }) => theme.spacing(2)}; `; -export const AIChatTab = ({ - agentId, - uiMessages, -}: { - agentId: string; - uiMessages: UIMessageWithMetadata[]; -}) => { +export const AIChatTab = ({ agentId }: { agentId: string }) => { const [isDraggingFile, setIsDraggingFile] = useState(false); const { @@ -71,11 +68,14 @@ export const AIChatTab = ({ handleInputChange, scrollWrapperId, messages, - handleSendMessage, isStreaming, - } = useAgentChat(agentId, uiMessages); - const { uploadFiles } = useAIChatFileUpload({ agentId }); + } = useAgentChatContextOrThrow(); + const contextStoreCurrentObjectMetadataItemId = useRecoilComponentValue( + contextStoreCurrentObjectMetadataItemIdComponentState, + ); + + const { uploadFiles } = useAIChatFileUpload(); const { createAgentChatThread } = useCreateNewAIChatThread({ agentId }); const { navigateCommandMenu } = useCommandMenu(); @@ -110,9 +110,9 @@ export const AIChatTab = ({ {isLoading && messages.length === 0 && } - +