Skip to content

Commit 913b250

Browse files
knajjarssanal-cohere
authored andcommitted
feat(toolkit): show assistant welcome message (#255)
* feat(toolkit): show assistant welcome message * feat(toolkit): show assistant welcome message
1 parent d7383a5 commit 913b250

File tree

5 files changed

+40
-43
lines changed

5 files changed

+40
-43
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ import { cn } from '@/utils';
1616
export const AgentsSidePanel: React.FC<React.PropsWithChildren> = ({ children }) => {
1717
const {
1818
settings: { isAgentsSidePanelOpen },
19-
setIsAgentsSidePanelOpen,
19+
setSettings,
20+
setIsConvListPanelOpen,
2021
} = useSettingsStore();
2122

2223
const isDesktop = useIsDesktop();
2324
const isMobile = !isDesktop;
2425

26+
const handleToggleAgentsSidePanel = () => {
27+
setIsConvListPanelOpen(false);
28+
setSettings({ isConfigDrawerOpen: false, isAgentsSidePanelOpen: !isAgentsSidePanelOpen });
29+
};
30+
2531
const navigationItems: {
2632
label: string;
2733
icon: IconProps['name'];
@@ -82,7 +88,7 @@ export const AgentsSidePanel: React.FC<React.PropsWithChildren> = ({ children })
8288

8389
<IconButton
8490
iconName="close-drawer"
85-
onClick={() => setIsAgentsSidePanelOpen(!isAgentsSidePanelOpen)}
91+
onClick={handleToggleAgentsSidePanel}
8692
className={cn('transition delay-100 duration-200 ease-in-out', {
8793
'rotate-180 transform text-secondary-700': isAgentsSidePanelOpen || isMobile,
8894
})}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Props = {
1919
startOptionsEnabled: boolean;
2020
messages: ChatMessage[];
2121
streamingMessage: StreamingMessage | null;
22+
agentId?: string;
2223
onRetry: VoidFunction;
2324
composer: ReactNode;
2425
conversationId?: string;
@@ -164,15 +165,15 @@ type MessagesProps = Props;
164165
* This component is in charge of rendering the messages.
165166
*/
166167
const Messages = forwardRef<HTMLDivElement, MessagesProps>(function MessagesInternal(
167-
{ onRetry, messages, streamingMessage },
168+
{ onRetry, messages, streamingMessage, agentId },
168169
ref
169170
) {
170171
const isChatEmpty = messages.length === 0;
171172

172173
if (isChatEmpty) {
173174
return (
174175
<div className="m-auto p-4">
175-
<Welcome show={isChatEmpty} isBaseAgent />
176+
<Welcome show={isChatEmpty} agentId={agentId} />
176177
</div>
177178
);
178179
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ const Conversation: React.FC<Props> = ({
165165
onRetry={handleRetry}
166166
messages={messages}
167167
streamingMessage={streamingMessage}
168+
agentId={agentId}
168169
composer={
169170
<>
170171
<WelcomeGuideTooltip step={3} className="absolute bottom-full mb-4" />
@@ -192,7 +193,7 @@ const Conversation: React.FC<Props> = ({
192193
enter="transition-all ease-in-out duration-300"
193194
enterFrom="w-0"
194195
enterTo="2xl:agent-panel-2xl md:w-agent-panel lg:w-agent-panel-lg w-full"
195-
leave="transition-all ease-in-out duration-300"
196+
leave="transition-all ease-in-out duration-0 md:duration-300"
196197
leaveFrom="2xl:agent-panel-2xl md:w-agent-panel lg:w-agent-panel-lg w-full"
197198
leaveTo="w-0"
198199
>

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

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,28 @@ import React from 'react';
33

44
import { BotAvatar } from '@/components/Avatar';
55
import { Text } from '@/components/Shared';
6+
import { useAgent } from '@/hooks/agents';
67
import { BotState } from '@/types/message';
78
import { cn } from '@/utils';
89
import { getCohereColor } from '@/utils/getCohereColor';
910

10-
type BaseAgentProps = {
11+
type Props = {
1112
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);
13+
agentId?: string;
2714
};
2815

2916
/**
3017
* @description Welcome message shown to the user when they first open the chat.
3118
*/
32-
export const Welcome: React.FC<Props> = (props) => {
33-
const isBaseAgentProps = isBaseAgent(props);
19+
export const Welcome: React.FC<Props> = ({ show, agentId }) => {
20+
const { data: agent, isLoading } = useAgent({ agentId });
21+
const isAgent = agentId !== undefined && !isLoading && !!agent;
3422

3523
return (
3624
<Transition
37-
show={props.show}
25+
show={show}
3826
appear
39-
className="flex flex-col items-center gap-y-4"
27+
className="flex flex-col items-center gap-y-4 p-4 md:max-w-[480px] lg:max-w-[720px]"
4028
enter="transition-all duration-300 ease-out delay-300"
4129
enterFrom="opacity-0"
4230
enterTo="opacity-100"
@@ -48,17 +36,17 @@ export const Welcome: React.FC<Props> = (props) => {
4836
<div
4937
className={cn(
5038
'flex h-7 w-7 items-center justify-center rounded md:h-9 md:w-9',
51-
!isBaseAgentProps && getCohereColor(props.id),
39+
isAgent && getCohereColor(agent.id),
5240
{
53-
'bg-secondary-400': isBaseAgentProps,
41+
'bg-secondary-400': !isAgent,
5442
}
5543
)}
5644
>
57-
{isBaseAgentProps ? (
45+
{!isAgent ? (
5846
<BotAvatar state={BotState.FULFILLED} style="secondary" />
5947
) : (
6048
<Text className="uppercase text-white" styleAs="p-lg">
61-
{props.name[0]}
49+
{agent.name[0]}
6250
</Text>
6351
)}
6452
</div>
@@ -67,14 +55,14 @@ export const Welcome: React.FC<Props> = (props) => {
6755
styleAs="p-lg"
6856
className={cn(
6957
'text-center text-secondary-800 md:!text-h4',
70-
!isBaseAgentProps && getCohereColor(props.id, { background: false })
58+
isAgent && getCohereColor(agent.id, { background: false })
7159
)}
7260
>
73-
{isBaseAgentProps ? 'Need help? Your wish is my command.' : props.name}
61+
{!isAgent ? 'Need help? Your wish is my command.' : agent.name}
7462
</Text>
75-
{!isBaseAgentProps && (
63+
{isAgent && (
7664
<Text className="!text-p-md text-center text-volcanic-900 md:!text-p-lg">
77-
{props.description}
65+
{agent.description}
7866
</Text>
7967
)}
8068
</Transition>

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,24 @@ const AgentsPage: NextPage<Props> = () => {
7878
<MainSection>
7979
<div className="flex h-full">
8080
<Transition
81-
as="main"
81+
as="aside"
8282
show={(isMobileConvListPanelOpen && isMobile) || (isConvListPanelOpen && isDesktop)}
83-
enterFrom="translate-x-full lg:translate-x-0 lg:w-0"
84-
enterTo="translate-x-0 lg:w-[300px]"
85-
leaveFrom="translate-x-0 lg:w-[300px]"
86-
leaveTo="translate-x-full lg:translate-x-0 lg:w-0"
83+
enter="transition-all transform ease-in-out duration-300"
84+
enterFrom="-translate-x-full w-0"
85+
enterTo="translate-x-0 w-full md:w-[320px]"
86+
leave="transition-all transform ease-in-out duration-300"
87+
leaveFrom="translate-x-0 w-full md:w-[320px]"
88+
leaveTo="-translate-x-full w-0"
8789
className={cn(
88-
'z-main-section flex flex-grow lg:min-w-0',
89-
'absolute h-full w-full lg:static lg:h-auto',
90-
'border-0 border-marble-400 md:border-r',
91-
'transition-[transform, width] duration-500 ease-in-out'
90+
'z-main-section flex lg:min-w-0',
91+
'absolute h-full lg:static lg:h-auto',
92+
'border-0 border-marble-400 md:border-r'
9293
)}
9394
>
9495
<ConversationListPanel />
9596
</Transition>
9697
<Transition
97-
as="div"
98+
as="main"
9899
show={isDesktop || !isMobileConvListPanelOpen}
99100
enterFrom="-translate-x-full"
100101
enterTo="translate-x-0"

0 commit comments

Comments
 (0)