-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client-side conversation participants
- Loading branch information
Showing
4 changed files
with
87 additions
and
69 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
front/components/assistant/conversation/ConversationParticipants.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, UserParticipant>(); | ||
const agentParticipantsMap = new Map<string, AgentParticipant>(); | ||
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 ( | ||
<div className="flex gap-6"> | ||
<Avatar.Stack | ||
size="sm" | ||
nbMoreItems={ | ||
agentParticipants.length > 4 ? agentParticipants.length - 4 : 0 | ||
} | ||
> | ||
{agentParticipants.slice(0, 4).map((agent) => ( | ||
<Avatar | ||
name={agent.name} | ||
visual={agent.pictureUrl} | ||
size="md" | ||
key={agent.configurationId} | ||
/> | ||
))} | ||
</Avatar.Stack> | ||
<Avatar.Stack | ||
size="sm" | ||
nbMoreItems={ | ||
userParticipants.length > 4 ? userParticipants.length - 4 : 0 | ||
} | ||
> | ||
{userParticipants.slice(0, 4).map((user, i) => ( | ||
<Avatar | ||
name={user.fullName || user.username} | ||
visual={user.pictureUrl} | ||
size="md" | ||
key={i} | ||
/> | ||
))} | ||
</Avatar.Stack> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters