diff --git a/front/components/assistant/conversation/ConversationParticipants.tsx b/front/components/assistant/conversation/ConversationParticipants.tsx new file mode 100644 index 000000000000..5a0c388ef3ad --- /dev/null +++ b/front/components/assistant/conversation/ConversationParticipants.tsx @@ -0,0 +1,83 @@ +import { Avatar } from "@dust-tt/sparkle"; +import React from "react"; + +import { ConversationType } from "@app/types/assistant/conversation"; + +export function ConversationParticipants({ + conversation, +}: { + conversation: ConversationType; +}) { + type UserParticipant = { + username: string; + fullName: string | null; + pictureUrl: string | null; + }; + type AgentParticipant = { + configurationId: string; + name: string; + pictureUrl: string; + }; + const userParticipantsMap = new Map(); + const agentParticipantsMap = new Map(); + conversation.content.map((messages) => { + messages.map((m) => { + if (m.type === "user_message") { + const key = `${m.context.username}-${m.context.profilePictureUrl}`; + if (!userParticipantsMap.has(key)) { + userParticipantsMap.set(key, { + username: m.context.username, + fullName: m.context.fullName, + pictureUrl: m.context.profilePictureUrl, + }); + } + } else if (m.type === "agent_message") { + const key = `${m.configuration.sId}`; + if (!agentParticipantsMap.has(key)) { + agentParticipantsMap.set(key, { + configurationId: m.configuration.sId, + name: m.configuration.name, + pictureUrl: m.configuration.pictureUrl, + }); + } + } + }); + }); + const userParticipants = Array.from(userParticipantsMap.values()); + const agentParticipants = Array.from(agentParticipantsMap.values()); + + return ( +
+ 4 ? agentParticipants.length - 4 : 0 + } + > + {agentParticipants.slice(0, 4).map((agent) => ( + + ))} + + 4 ? userParticipants.length - 4 : 0 + } + > + {userParticipants.slice(0, 4).map((user, i) => ( + + ))} + +
+ ); +} diff --git a/front/components/assistant/conversation/ConversationTitle.tsx b/front/components/assistant/conversation/ConversationTitle.tsx index 24932ebb9cd5..724d9dd6a71c 100644 --- a/front/components/assistant/conversation/ConversationTitle.tsx +++ b/front/components/assistant/conversation/ConversationTitle.tsx @@ -1,6 +1,5 @@ import { ArrowUpOnSquareIcon, - Avatar, Button, CheckIcon, ClipboardCheckIcon, @@ -14,6 +13,7 @@ import { import React, { MouseEvent, useRef, useState } from "react"; import { useSWRConfig } from "swr"; +import { ConversationParticipants } from "@app/components/assistant/conversation/ConversationParticipants"; import { useConversation } from "@app/lib/swr"; import { WorkspaceType } from "@app/types/user"; @@ -161,46 +161,10 @@ export function ConversationTitle({ /> )} -
-
- 4 - ? conversation.participants.agents.length - 4 - : 0 - } - > - {conversation.participants.agents.slice(0, 4).map((agent) => ( - - ))} - -
-
- 4 - ? conversation.participants.users.length - 4 - : 0 - } - > - {conversation.participants.users.slice(0, 4).map((user, i) => ( - - ))} - +
+
+
-
{onDelete && ( diff --git a/front/lib/api/assistant/conversation.ts b/front/lib/api/assistant/conversation.ts index bd3be6f25772..ebe1ba607be0 100644 --- a/front/lib/api/assistant/conversation.ts +++ b/front/lib/api/assistant/conversation.ts @@ -82,7 +82,6 @@ export async function createConversation( title: conversation.title, visibility: conversation.visibility, content: [], - participants: { users: [], agents: [] }, }; } @@ -401,23 +400,11 @@ export async function getConversation( ], }); - const userParticipants = new Map(); - const agentParticipants = new Map(); - const render = await Promise.all( messages.map((message) => { return (async () => { if (message.userMessage) { const m = await renderUserMessage(message, message.userMessage); - - const key = `${m.context.username}-${m.context.profilePictureUrl}`; - if (!userParticipants.has(key)) { - userParticipants.set(key, { - username: m.context.username, - fullName: m.context.fullName, - pictureUrl: m.context.profilePictureUrl, - }); - } return { m, rank: message.rank, version: message.version }; } if (message.agentMessage) { @@ -426,14 +413,6 @@ export async function getConversation( agentMessage: message.agentMessage, messages, }); - const configurationId = m.configuration.sId; - if (!agentParticipants.has(configurationId)) { - agentParticipants.set(configurationId, { - configurationId: configurationId, - name: m.configuration.name, - pictureUrl: m.configuration.pictureUrl, - }); - } return { m, rank: message.rank, version: message.version }; } throw new Error("Unreachable: message must be either user or agent"); @@ -468,10 +447,6 @@ export async function getConversation( title: conversation.title, visibility: conversation.visibility, content, - participants: { - users: Array.from(userParticipants.values()), - agents: Array.from(agentParticipants.values()), - }, }; } diff --git a/front/types/assistant/conversation.ts b/front/types/assistant/conversation.ts index 4d3b8cd54d29..9bf48bbbddb2 100644 --- a/front/types/assistant/conversation.ts +++ b/front/types/assistant/conversation.ts @@ -135,10 +135,6 @@ export type ConversationType = { title: string | null; visibility: ConversationVisibility; content: (UserMessageType[] | AgentMessageType[])[]; - participants: { - users: UserParticipant[]; - agents: AgentParticipant[]; - }; }; export type UserParticipant = {