Skip to content

Commit 369eec3

Browse files
feat: List Assistants returned from API (#242)
* feat: list agents from BE * Update src/interfaces/coral_web/src/components/Conversation/MessagingContainer.tsx Co-authored-by: misspia-cohere <[email protected]> --------- Co-authored-by: misspia-cohere <[email protected]>
1 parent 8346f0f commit 369eec3

File tree

6 files changed

+118
-96
lines changed

6 files changed

+118
-96
lines changed

src/interfaces/coral_web/src/components/Agents/AgentsList.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ export const AgentsList: React.FC = () => {
3030
</Transition>
3131

3232
<AgentCard isExpanded={isAgentsSidePanelOpen} name="Command R+" isBaseAgent />
33-
<AgentCard
34-
isExpanded={isAgentsSidePanelOpen}
35-
name="HR Policy Advisor"
36-
id="hr-policy-advisor-01"
37-
/>
38-
<AgentCard
39-
isExpanded={isAgentsSidePanelOpen}
40-
name="Financial Advisor"
41-
id="financial-advisor-01"
42-
/>
4333
{agents?.map((agent) => (
4434
<AgentCard
4535
key={agent.id}

src/interfaces/coral_web/src/components/Agents/DiscoverAgentCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getCohereColor } from '@/utils/getCohereColor';
66

77
type Props = {
88
name: string;
9-
description: string;
9+
description?: string;
1010
isBaseAgent?: boolean;
1111
id?: string;
1212
};

src/interfaces/coral_web/src/components/Conversation/MessagingContainer.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,9 @@ const Messages = forwardRef<HTMLDivElement, MessagesProps>(function MessagesInte
164164
ref
165165
) {
166166
const isChatEmpty = messages.length === 0;
167+
167168
if (isChatEmpty) {
168-
return (
169-
<div className="m-auto p-4">
170-
<Welcome show={isChatEmpty} />
171-
</div>
172-
);
169+
return <div className="m-auto p-4"><Welcome show={isChatEmpty} isBaseAgent /></div>;
173170
}
174171

175172
return (

src/interfaces/coral_web/src/components/Welcome.tsx

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,37 @@ import React from 'react';
44
import { BotAvatar } from '@/components/Avatar';
55
import { Text } from '@/components/Shared';
66
import { BotState } from '@/types/message';
7+
import { cn } from '@/utils';
8+
import { getCohereColor } from '@/utils/getCohereColor';
79

8-
type Props = {
10+
type BaseAgentProps = {
911
show: boolean;
12+
isBaseAgent: true;
13+
};
14+
15+
type AgentProps = {
16+
show: boolean;
17+
isBaseAgent?: false;
18+
id: string;
19+
name: string;
20+
description?: string;
21+
};
22+
23+
type Props = BaseAgentProps | AgentProps;
24+
25+
const isBaseAgent = (props: AgentProps | BaseAgentProps): props is BaseAgentProps => {
26+
return Boolean(props.isBaseAgent);
1027
};
1128

1229
/**
1330
* @description Welcome message shown to the user when they first open the chat.
1431
*/
15-
export const Welcome: React.FC<Props> = ({ show }) => {
32+
export const Welcome: React.FC<Props> = (props) => {
33+
const isBaseAgentProps = isBaseAgent(props);
34+
1635
return (
1736
<Transition
18-
show={show}
37+
show={props.show}
1938
appear
2039
className="flex flex-col items-center gap-y-4"
2140
enter="transition-all duration-300 ease-out delay-300"
@@ -26,12 +45,38 @@ export const Welcome: React.FC<Props> = ({ show }) => {
2645
leaveTo="opacity-0"
2746
as="div"
2847
>
29-
<div className="flex h-7 w-7 items-center justify-center rounded bg-secondary-400 md:h-9 md:w-9">
30-
<BotAvatar state={BotState.FULFILLED} style="secondary" />
48+
<div
49+
className={cn(
50+
'flex h-7 w-7 items-center justify-center rounded md:h-9 md:w-9',
51+
!isBaseAgentProps && getCohereColor(props.id),
52+
{
53+
'bg-secondary-400': isBaseAgentProps,
54+
}
55+
)}
56+
>
57+
{isBaseAgentProps ? (
58+
<BotAvatar state={BotState.FULFILLED} style="secondary" />
59+
) : (
60+
<Text className="uppercase text-white" styleAs="p-lg">
61+
{props.name[0]}
62+
</Text>
63+
)}
3164
</div>
32-
<Text styleAs="p-lg" className="text-center text-secondary-800 md:!text-h4">
33-
Need help? Your wish is my command.
65+
66+
<Text
67+
styleAs="p-lg"
68+
className={cn(
69+
'text-center text-secondary-800 md:!text-h4',
70+
!isBaseAgentProps && getCohereColor(props.id, { background: false })
71+
)}
72+
>
73+
{isBaseAgentProps ? 'Need help? Your wish is my command.' : props.name}
3474
</Text>
75+
{!isBaseAgentProps && (
76+
<Text className="!text-p-md text-center text-volcanic-900 md:!text-p-lg">
77+
{props.description}
78+
</Text>
79+
)}
3580
</Transition>
3681
);
3782
};

src/interfaces/coral_web/src/pages/agents/discover/index.tsx

Lines changed: 47 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,41 @@
1+
import { useDebouncedState } from '@react-hookz/web';
12
import { QueryClient, dehydrate } from '@tanstack/react-query';
23
import { GetServerSideProps, NextPage } from 'next';
4+
import { useEffect, useState } from 'react';
35

46
import { CohereClient } from '@/cohere-client';
57
import { AgentsList } from '@/components/Agents/AgentsList';
68
import { DiscoverAgentCard } from '@/components/Agents/DiscoverAgentCard';
79
import { Layout, LeftSection, MainSection } from '@/components/Agents/Layout';
810
import { Input, Text } from '@/components/Shared';
11+
import { useListAgents } from '@/hooks/agents';
912
import { appSSR } from '@/pages/_app';
1013
import { cn } from '@/utils';
1114

15+
const MAX_DEBOUNCE_TIME = 300;
16+
1217
type Props = {};
1318

1419
const AgentsNewPage: NextPage<Props> = () => {
15-
const agents = [
16-
{
17-
id: '1',
18-
name: 'Agent 1',
19-
description: 'This is the first agent',
20-
},
21-
{
22-
id: '2',
23-
name: 'Agent 2',
24-
description: 'This is the second agent',
25-
},
26-
{
27-
id: '3',
28-
name: 'Agent 3',
29-
description: 'This is the third agent',
30-
},
31-
{
32-
id: '4',
33-
name: 'Agent 4',
34-
description: 'This is the fourth agent',
35-
},
36-
{
37-
id: '5',
38-
name: 'Agent 5',
39-
description: 'This is the fifth agent',
40-
},
41-
{
42-
id: '6',
43-
name: 'Agent 6',
44-
description: 'This is the sixth agent',
45-
},
46-
{
47-
id: '7',
48-
name: 'Agent 7',
49-
description: 'This is the seventh agent',
50-
},
51-
{
52-
id: '8',
53-
name: 'Agent 8',
54-
description: 'This is the eighth agent',
55-
},
56-
{
57-
id: '9',
58-
name: 'Agent 9',
59-
description: 'This is the ninth agent',
60-
},
61-
{
62-
id: '10',
63-
name: 'Agent 10',
64-
description: 'This is the tenth agent',
65-
},
66-
{
67-
id: '11',
68-
name: 'Agent 11',
69-
description: 'This is the eleventh agent',
70-
},
71-
{
72-
id: '12',
73-
name: 'Agent 12',
74-
description: 'This is the twelfth agent',
75-
},
76-
];
20+
const { data: agents = [] } = useListAgents();
21+
22+
const [filterText, setFilterText] = useState('');
23+
const [filteredAgents, setFilteredAgents] = useDebouncedState(
24+
agents,
25+
MAX_DEBOUNCE_TIME,
26+
MAX_DEBOUNCE_TIME
27+
);
28+
29+
useEffect(() => {
30+
if (!filterText) {
31+
setFilteredAgents(agents);
32+
return;
33+
}
34+
35+
setFilteredAgents(
36+
agents.filter((agent) => agent.name.toLowerCase().includes(filterText.toLowerCase()))
37+
);
38+
}, [filterText]);
7739

7840
return (
7941
<Layout>
@@ -99,19 +61,33 @@ const AgentsNewPage: NextPage<Props> = () => {
9961
</div>
10062
<div className="max-w-screen-xl flex-grow overflow-y-auto px-4 py-10 md:px-9 lg:px-10">
10163
<div className="grid grid-cols-1 gap-x-4 gap-y-5 md:grid-cols-2 xl:grid-cols-3">
102-
{agents.length >= 10 && (
64+
{agents.length >= 1 && (
10365
<>
104-
<Input size="sm" kind="default" actionType="search" placeholder="Search" />
66+
<Input
67+
size="sm"
68+
kind="default"
69+
actionType="search"
70+
placeholder="Search"
71+
value={filterText}
72+
onChange={(e) => setFilterText(e.target.value)}
73+
/>
10574
<div className="col-span-2 hidden md:flex" />
10675
</>
10776
)}
108-
<DiscoverAgentCard
109-
isBaseAgent
110-
name="Command R+"
111-
description="Review, understand and ask questions about internal financial documents."
112-
/>
113-
{agents.map((agent) => (
114-
<DiscoverAgentCard key={agent.name} {...agent} />
77+
{'command r+'.includes(filterText.toLowerCase()) && (
78+
<DiscoverAgentCard
79+
isBaseAgent
80+
name="Command R+"
81+
description="Review, understand and ask questions about internal financial documents."
82+
/>
83+
)}
84+
{filteredAgents?.map((agent) => (
85+
<DiscoverAgentCard
86+
key={agent.name}
87+
description={agent.description ?? undefined}
88+
name={agent.name}
89+
id={agent.id}
90+
/>
11591
))}
11692
</div>
11793
</div>

src/interfaces/coral_web/src/utils/getCohereColor.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const COLOR_LIST = [
1+
const BG_COLOR_LIST = [
22
'bg-quartz-500',
33
'bg-green-400',
44
'bg-primary-400',
@@ -7,12 +7,26 @@ export const COLOR_LIST = [
77
'bg-primary-500',
88
];
99

10+
const TEXT_COLOR_LIST = [
11+
'text-quartz-500',
12+
'text-green-400',
13+
'text-primary-400',
14+
'text-quartz-700',
15+
'text-green-700',
16+
'text-primary-500',
17+
];
18+
1019
/**
1120
* @description Get a color from the Cohere color palette, when no index is provided, a random color is returned
1221
* @param id - id for generating a constant color in the palette
22+
* @param background - if true, returns a background color, otherwise returns a text color
1323
* @returns color from the Cohere color palette
1424
*/
15-
export const getCohereColor = (id?: string) => {
25+
export const getCohereColor = (
26+
id?: string,
27+
options: { background?: boolean } = { background: true }
28+
) => {
29+
const COLOR_LIST = options?.background ? BG_COLOR_LIST : TEXT_COLOR_LIST;
1630
if (id === undefined) {
1731
const randomIndex = Math.floor(Math.random() * COLOR_LIST.length);
1832

0 commit comments

Comments
 (0)