@dashx/react 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/avatar.d.ts +5 -0
- package/dist/cjs/components/avatar.js +2 -0
- package/dist/cjs/components/avatar.js.map +7 -0
- package/dist/cjs/components/flex.d.ts +70 -0
- package/dist/cjs/components/flex.js +1 -1
- package/dist/cjs/components/flex.js.map +3 -3
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +1 -1
- package/dist/cjs/components/index.js.map +2 -2
- package/dist/cjs/components/markdown-renderer.d.ts +8 -0
- package/dist/cjs/components/markdown-renderer.js +2 -0
- package/dist/cjs/components/markdown-renderer.js.map +7 -0
- package/dist/cjs/components/popover copy.d.ts +47 -0
- package/dist/cjs/components/text-area.d.ts +1 -0
- package/dist/cjs/components/text-area.js +1 -1
- package/dist/cjs/components/text-area.js.map +3 -3
- package/dist/cjs/hooks/index.d.ts +2 -0
- package/dist/cjs/hooks/index.js +1 -1
- package/dist/cjs/hooks/index.js.map +3 -3
- package/dist/cjs/hooks/use-agent.d.ts +15 -0
- package/dist/cjs/hooks/use-agent.js +2 -0
- package/dist/cjs/hooks/use-agent.js.map +7 -0
- package/dist/cjs/hooks/use-animated-text.d.ts +11 -0
- package/dist/cjs/hooks/use-animated-text.js +2 -0
- package/dist/cjs/hooks/use-animated-text.js.map +7 -0
- package/dist/cjs/hooks/use-auto-scroll.d.ts +13 -0
- package/dist/cjs/hooks/use-auto-scroll.js +2 -0
- package/dist/cjs/hooks/use-auto-scroll.js.map +7 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/legacy.d.ts +2 -0
- package/dist/cjs/legacy.js +2 -0
- package/dist/cjs/legacy.js.map +7 -0
- package/dist/cjs/providers/DashXProvider.d.ts +3 -2
- package/dist/cjs/providers/DashXProvider.js +1 -1
- package/dist/cjs/providers/DashXProvider.js.map +3 -3
- package/dist/cjs/tsconfig.tsbuildinfo +1 -0
- package/dist/cjs/variants/avatar.d.ts +212 -0
- package/dist/cjs/variants/avatar.js +2 -0
- package/dist/cjs/variants/avatar.js.map +7 -0
- package/dist/cjs/variants/base-input.d.ts +1 -1
- package/dist/cjs/variants/base-input.js +1 -1
- package/dist/cjs/variants/base-input.js.map +2 -2
- package/dist/cjs/variants/button copy.d.ts +254 -0
- package/dist/cjs/variants/checkbox.d.ts +1 -1
- package/dist/cjs/widgets/Chat.d.ts +15 -0
- package/dist/cjs/widgets/Chat.js +2 -0
- package/dist/cjs/widgets/Chat.js.map +7 -0
- package/dist/cjs/widgets/ChatBody.d.ts +14 -0
- package/dist/cjs/widgets/ChatBody.js +2 -0
- package/dist/cjs/widgets/ChatBody.js.map +7 -0
- package/dist/cjs/widgets/ChatFooter.d.ts +7 -0
- package/dist/cjs/widgets/ChatFooter.js +2 -0
- package/dist/cjs/widgets/ChatFooter.js.map +7 -0
- package/dist/cjs/widgets/ChatHeader.d.ts +9 -0
- package/dist/cjs/widgets/ChatHeader.js +2 -0
- package/dist/cjs/widgets/ChatHeader.js.map +7 -0
- package/dist/cjs/widgets/ChatPopover.d.ts +3 -0
- package/dist/cjs/widgets/ChatPopover.js +2 -0
- package/dist/cjs/widgets/ChatPopover.js.map +7 -0
- package/dist/cjs/widgets/NotificationBell.js +1 -1
- package/dist/cjs/widgets/NotificationBell.js.map +2 -2
- package/dist/cjs/widgets/index.d.ts +2 -0
- package/dist/cjs/widgets/index.js +1 -1
- package/dist/cjs/widgets/index.js.map +3 -3
- package/dist/esm/components/avatar.d.ts +5 -0
- package/dist/esm/components/avatar.js +2 -0
- package/dist/esm/components/avatar.js.map +7 -0
- package/dist/esm/components/flex.d.ts +70 -0
- package/dist/esm/components/flex.js +1 -1
- package/dist/esm/components/flex.js.map +3 -3
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +1 -1
- package/dist/esm/components/index.js.map +2 -2
- package/dist/esm/components/markdown-renderer.d.ts +8 -0
- package/dist/esm/components/markdown-renderer.js +2 -0
- package/dist/esm/components/markdown-renderer.js.map +7 -0
- package/dist/esm/components/popover copy.d.ts +47 -0
- package/dist/esm/components/text-area.d.ts +1 -0
- package/dist/esm/components/text-area.js +1 -1
- package/dist/esm/components/text-area.js.map +3 -3
- package/dist/esm/hooks/index.d.ts +2 -0
- package/dist/esm/hooks/index.js +1 -1
- package/dist/esm/hooks/index.js.map +3 -3
- package/dist/esm/hooks/use-agent.d.ts +15 -0
- package/dist/esm/hooks/use-agent.js +2 -0
- package/dist/esm/hooks/use-agent.js.map +7 -0
- package/dist/esm/hooks/use-animated-text.d.ts +11 -0
- package/dist/esm/hooks/use-animated-text.js +2 -0
- package/dist/esm/hooks/use-animated-text.js.map +7 -0
- package/dist/esm/hooks/use-auto-scroll.d.ts +13 -0
- package/dist/esm/hooks/use-auto-scroll.js +2 -0
- package/dist/esm/hooks/use-auto-scroll.js.map +7 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/legacy.d.ts +2 -0
- package/dist/esm/legacy.js +2 -0
- package/dist/esm/legacy.js.map +7 -0
- package/dist/esm/providers/DashXProvider.d.ts +3 -2
- package/dist/esm/providers/DashXProvider.js +1 -1
- package/dist/esm/providers/DashXProvider.js.map +3 -3
- package/dist/esm/tsconfig.tsbuildinfo +1 -0
- package/dist/esm/variants/avatar.d.ts +212 -0
- package/dist/esm/variants/avatar.js +2 -0
- package/dist/esm/variants/avatar.js.map +7 -0
- package/dist/esm/variants/base-input.d.ts +1 -1
- package/dist/esm/variants/base-input.js +1 -1
- package/dist/esm/variants/base-input.js.map +2 -2
- package/dist/esm/variants/button copy.d.ts +254 -0
- package/dist/esm/variants/checkbox.d.ts +1 -1
- package/dist/esm/widgets/Chat.d.ts +15 -0
- package/dist/esm/widgets/Chat.js +2 -0
- package/dist/esm/widgets/Chat.js.map +7 -0
- package/dist/esm/widgets/ChatBody.d.ts +14 -0
- package/dist/esm/widgets/ChatBody.js +2 -0
- package/dist/esm/widgets/ChatBody.js.map +7 -0
- package/dist/esm/widgets/ChatFooter.d.ts +7 -0
- package/dist/esm/widgets/ChatFooter.js +2 -0
- package/dist/esm/widgets/ChatFooter.js.map +7 -0
- package/dist/esm/widgets/ChatHeader.d.ts +9 -0
- package/dist/esm/widgets/ChatHeader.js +2 -0
- package/dist/esm/widgets/ChatHeader.js.map +7 -0
- package/dist/esm/widgets/ChatPopover.d.ts +3 -0
- package/dist/esm/widgets/ChatPopover.js +2 -0
- package/dist/esm/widgets/ChatPopover.js.map +7 -0
- package/dist/esm/widgets/NotificationBell.js +1 -1
- package/dist/esm/widgets/NotificationBell.js.map +2 -2
- package/dist/esm/widgets/index.d.ts +2 -0
- package/dist/esm/widgets/index.js +1 -1
- package/dist/esm/widgets/index.js.map +2 -2
- package/package.json +5 -3
- package/src/components/avatar.tsx +32 -0
- package/src/components/flex.tsx +7 -2
- package/src/components/index.ts +1 -0
- package/src/components/markdown-renderer.tsx +57 -0
- package/src/components/text-area.tsx +23 -11
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use-agent.ts +89 -0
- package/src/hooks/use-animated-text.ts +67 -0
- package/src/hooks/use-auto-scroll.ts +65 -0
- package/src/index.ts +2 -1
- package/src/legacy.ts +2 -0
- package/src/providers/DashXProvider.tsx +9 -6
- package/src/variants/avatar.ts +31 -0
- package/src/variants/base-input.ts +1 -1
- package/src/widgets/Chat.tsx +96 -0
- package/src/widgets/ChatBody.tsx +171 -0
- package/src/widgets/ChatFooter.tsx +62 -0
- package/src/widgets/ChatHeader.tsx +26 -0
- package/src/widgets/ChatPopover.tsx +42 -0
- package/src/widgets/NotificationBell.tsx +1 -1
- package/src/widgets/index.ts +2 -0
- package/styles.css +122 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { tv } from 'tailwind-variants';
|
|
2
|
+
|
|
3
|
+
import baseElement from './base-element.js';
|
|
4
|
+
|
|
5
|
+
import type { VariantProps } from 'tailwind-variants';
|
|
6
|
+
|
|
7
|
+
const avatar = tv({
|
|
8
|
+
extend: baseElement,
|
|
9
|
+
base: 'inline-flex items-center justify-center outline-none select-none',
|
|
10
|
+
variants: {
|
|
11
|
+
size: {
|
|
12
|
+
extrasmall: 'rounded-sm-or-full text-xs',
|
|
13
|
+
small: 'rounded-sm-or-full text-sm',
|
|
14
|
+
medium: 'rounded-md-or-full text-base',
|
|
15
|
+
large: 'rounded-lg-or-full text-lg',
|
|
16
|
+
extralarge: 'rounded-lg-or-full text-xl',
|
|
17
|
+
},
|
|
18
|
+
roundness: {},
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: {
|
|
21
|
+
size: 'medium',
|
|
22
|
+
mode: 'distinct',
|
|
23
|
+
variant: 'fill',
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
type AvatarVariantProps = VariantProps<typeof avatar>;
|
|
28
|
+
|
|
29
|
+
export type { AvatarVariantProps };
|
|
30
|
+
|
|
31
|
+
export { avatar };
|
|
@@ -3,7 +3,7 @@ import { tv } from 'tailwind-variants';
|
|
|
3
3
|
import type { VariantProps } from 'tailwind-variants';
|
|
4
4
|
|
|
5
5
|
const baseInput = tv({
|
|
6
|
-
base: 'data-[invalid="true"]:border-negative-300 data-[invalid="true"]:hover:border-negative-400 data-[invalid="true"]:focus:border-negative-500 data-[invalid="true"]:text-negative-500 data-[invalid="true"]:bg-negative-50 ease-fluid data-[invalid="true"]:focus:outline-negative-500 focus:outline-accent-500 autofill:bg-accent-300 !hover:border-gray-400 border border-gray-300 py-3 px-4 text-sm text-gray-900 outline-none transition-[box-shadow,background-color,color,border-color] duration-300',
|
|
6
|
+
base: 'bg-white data-[invalid="true"]:border-negative-300 data-[invalid="true"]:hover:border-negative-400 data-[invalid="true"]:focus:border-negative-500 data-[invalid="true"]:text-negative-500 data-[invalid="true"]:bg-negative-50 ease-fluid data-[invalid="true"]:focus:outline-negative-500 focus:outline-accent-500 autofill:bg-accent-300 !hover:border-gray-400 border border-gray-300 py-3 px-4 text-sm text-gray-900 outline-none transition-[box-shadow,background-color,color,border-color] duration-300',
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
type BaseInputVariantProps = VariantProps<typeof baseInput>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { cn } from '../utils/cn.js';
|
|
4
|
+
import { Button, Flex, Theme, Popover } from '../components';
|
|
5
|
+
import { X } from '../icons';
|
|
6
|
+
import ChatHeader from './ChatHeader.js';
|
|
7
|
+
import ChatBody from './ChatBody.js';
|
|
8
|
+
import ChatFooter from './ChatFooter.js';
|
|
9
|
+
import useAgent, { type UseAgentHookResponse } from '../hooks/use-agent.js';
|
|
10
|
+
|
|
11
|
+
type ChatProps = UseAgentHookResponse & {
|
|
12
|
+
withChatHeader?: boolean;
|
|
13
|
+
withPopoverClose?: boolean;
|
|
14
|
+
borderless?: boolean;
|
|
15
|
+
isPopoverOpen?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const Chat = ({
|
|
19
|
+
agent,
|
|
20
|
+
messages,
|
|
21
|
+
isThinking,
|
|
22
|
+
error,
|
|
23
|
+
sendMessage,
|
|
24
|
+
withChatHeader = false,
|
|
25
|
+
withPopoverClose = false,
|
|
26
|
+
borderless = false,
|
|
27
|
+
isPopoverOpen = false,
|
|
28
|
+
}: ChatProps) => {
|
|
29
|
+
const [isAnimating, setIsAnimating] = useState(false);
|
|
30
|
+
|
|
31
|
+
if (!agent) {
|
|
32
|
+
return (
|
|
33
|
+
<Theme asChild>
|
|
34
|
+
<Flex direction="column" className="h-full">
|
|
35
|
+
<div className="text-red-600 p-4">
|
|
36
|
+
{error
|
|
37
|
+
? `Error loading chat agent: ${error}`
|
|
38
|
+
: 'Loading chat agent...'}
|
|
39
|
+
</div>
|
|
40
|
+
</Flex>
|
|
41
|
+
</Theme>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Theme asChild>
|
|
47
|
+
<Flex direction="column" className={cn("h-full", !borderless && "border border-gray-400/40")}>
|
|
48
|
+
{withChatHeader && (
|
|
49
|
+
<ChatHeader agent={agent}>
|
|
50
|
+
{withPopoverClose && (
|
|
51
|
+
<Popover.Close>
|
|
52
|
+
<Button shape="square" roundness="full" variant="ghost" mode="subtle" inset="right">
|
|
53
|
+
<X />
|
|
54
|
+
</Button>
|
|
55
|
+
</Popover.Close>
|
|
56
|
+
)}
|
|
57
|
+
</ChatHeader>
|
|
58
|
+
)}
|
|
59
|
+
<ChatBody
|
|
60
|
+
agent={agent}
|
|
61
|
+
messages={messages}
|
|
62
|
+
isThinking={isThinking}
|
|
63
|
+
error={error}
|
|
64
|
+
sendMessage={sendMessage}
|
|
65
|
+
isAnimating={isAnimating}
|
|
66
|
+
setIsAnimating={setIsAnimating}
|
|
67
|
+
isPopoverOpen={isPopoverOpen}
|
|
68
|
+
/>
|
|
69
|
+
<ChatFooter sendMessage={sendMessage} isDisabled={isThinking || isAnimating} />
|
|
70
|
+
</Flex>
|
|
71
|
+
</Theme>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
type ChatWrapperProps = Omit<ChatProps, keyof UseAgentHookResponse> & { publicEmbedKey: string };
|
|
76
|
+
|
|
77
|
+
const ChatWrapper = ({ publicEmbedKey, ...props }: ChatWrapperProps) => {
|
|
78
|
+
const { agent, messages, isThinking, error, sendMessage, conversationId } = useAgent({ publicEmbedKey });
|
|
79
|
+
return (
|
|
80
|
+
<Chat
|
|
81
|
+
agent={agent}
|
|
82
|
+
conversationId={conversationId}
|
|
83
|
+
messages={messages}
|
|
84
|
+
isThinking={isThinking}
|
|
85
|
+
error={error}
|
|
86
|
+
sendMessage={sendMessage}
|
|
87
|
+
{...props}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type { ChatProps, ChatWrapperProps };
|
|
93
|
+
|
|
94
|
+
export { Chat };
|
|
95
|
+
|
|
96
|
+
export default ChatWrapper;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as ScrollArea from '@radix-ui/react-scroll-area';
|
|
2
|
+
import React, { useEffect, useRef, useCallback } from 'react';
|
|
3
|
+
import type { AiAgent, AiMessage, AiAgentStarterSuggestion } from '@dashx/browser';
|
|
4
|
+
|
|
5
|
+
import { Button, Flex, Text } from '../components';
|
|
6
|
+
import { cn } from '../utils/cn.js';
|
|
7
|
+
import { MarkdownRenderer } from '../components/markdown-renderer.js';
|
|
8
|
+
import useAutoScroll from '../hooks/use-auto-scroll.js';
|
|
9
|
+
|
|
10
|
+
const AGENT_MESSAGE_WIDTH_CLASS = 'max-w-[max(80%,350px)]';
|
|
11
|
+
const USER_MESSAGE_WIDTH_CLASS = 'max-w-[80%]';
|
|
12
|
+
|
|
13
|
+
type ChatBodyProps = {
|
|
14
|
+
agent: AiAgent;
|
|
15
|
+
messages: AiMessage[];
|
|
16
|
+
isThinking: boolean;
|
|
17
|
+
error: string | null;
|
|
18
|
+
sendMessage: (message: string) => void;
|
|
19
|
+
isAnimating: boolean;
|
|
20
|
+
setIsAnimating: (animating: boolean) => void;
|
|
21
|
+
isPopoverOpen?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const ChatBody = ({
|
|
25
|
+
agent,
|
|
26
|
+
messages,
|
|
27
|
+
isThinking,
|
|
28
|
+
error,
|
|
29
|
+
sendMessage,
|
|
30
|
+
setIsAnimating,
|
|
31
|
+
isAnimating,
|
|
32
|
+
isPopoverOpen = false,
|
|
33
|
+
}: ChatBodyProps) => {
|
|
34
|
+
const previousMessageCountRef = useRef(messages.length);
|
|
35
|
+
const initialMessageCountRef = useRef(messages.length);
|
|
36
|
+
const { scrollAreaRef, scrollToBottom, checkIfUserAtBottom, isUserAtBottom } = useAutoScroll();
|
|
37
|
+
|
|
38
|
+
const handleAnimationComplete = useCallback(() => {
|
|
39
|
+
setIsAnimating(false);
|
|
40
|
+
}, [setIsAnimating]);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const lastMessage = messages[messages.length - 1];
|
|
44
|
+
const hasNewMessage = messages.length > previousMessageCountRef.current;
|
|
45
|
+
|
|
46
|
+
if (hasNewMessage && lastMessage?.role === 'assistant') {
|
|
47
|
+
setIsAnimating(true);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (hasNewMessage) {
|
|
51
|
+
setTimeout(() => scrollToBottom({ smooth: true }), 0);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
previousMessageCountRef.current = messages.length;
|
|
55
|
+
}, [messages, isThinking, setIsAnimating, scrollToBottom, isUserAtBottom]);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (isThinking) {
|
|
59
|
+
setTimeout(() => scrollToBottom({ smooth: true }), 0);
|
|
60
|
+
}
|
|
61
|
+
}, [isThinking, scrollToBottom, isUserAtBottom]);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (isAnimating && isUserAtBottom) {
|
|
65
|
+
const interval = setInterval(() => {
|
|
66
|
+
checkIfUserAtBottom();
|
|
67
|
+
if (isUserAtBottom) {
|
|
68
|
+
scrollToBottom({ smooth: false });
|
|
69
|
+
}
|
|
70
|
+
}, 100);
|
|
71
|
+
|
|
72
|
+
return () => clearInterval(interval);
|
|
73
|
+
}
|
|
74
|
+
}, [isAnimating, scrollToBottom, checkIfUserAtBottom, isUserAtBottom]);
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (isPopoverOpen) {
|
|
78
|
+
// Use a small delay to ensure the popover content is fully rendered
|
|
79
|
+
setTimeout(() => scrollToBottom({ smooth: true }), 100);
|
|
80
|
+
}
|
|
81
|
+
}, [isPopoverOpen, scrollToBottom]);
|
|
82
|
+
|
|
83
|
+
const handleSuggestionClick = (suggestion: AiAgentStarterSuggestion) => {
|
|
84
|
+
sendMessage(suggestion.content);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const renderMessage = (message: AiMessage, index: number) => {
|
|
88
|
+
const isUser = message.role === 'user';
|
|
89
|
+
const isLastMessage = index === messages.length - 1;
|
|
90
|
+
const isLastAgentMessage = isLastMessage && !isUser;
|
|
91
|
+
const isNewMessage = index >= initialMessageCountRef.current;
|
|
92
|
+
const shouldAnimate = isLastAgentMessage && isNewMessage;
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<div
|
|
96
|
+
key={message.id || index}
|
|
97
|
+
className={cn([
|
|
98
|
+
isUser
|
|
99
|
+
? `bg-bg ml-auto items-end rounded-lg py-2 px-3 ${USER_MESSAGE_WIDTH_CLASS}`
|
|
100
|
+
: `mr-auto items-start ${AGENT_MESSAGE_WIDTH_CLASS}`,
|
|
101
|
+
])}
|
|
102
|
+
>
|
|
103
|
+
<MarkdownRenderer animate={shouldAnimate} onAnimationComplete={handleAnimationComplete}>
|
|
104
|
+
{message.content || ''}
|
|
105
|
+
</MarkdownRenderer>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<Flex direction="column" className="grow overflow-auto bg-gray-50">
|
|
112
|
+
<ScrollArea.Root ref={scrollAreaRef} className="h-full grow-1 p-6">
|
|
113
|
+
<ScrollArea.Viewport className="h-full">
|
|
114
|
+
<Flex direction="column" gap={6}>
|
|
115
|
+
{agent.starterMessages?.map((msg, index) => (
|
|
116
|
+
<div
|
|
117
|
+
key={`message-${index}`}
|
|
118
|
+
className={cn('mr-auto items-start', AGENT_MESSAGE_WIDTH_CLASS)}
|
|
119
|
+
>
|
|
120
|
+
<MarkdownRenderer>{msg.content || ''}</MarkdownRenderer>
|
|
121
|
+
</div>
|
|
122
|
+
))}
|
|
123
|
+
|
|
124
|
+
{agent.starterSuggestions && messages.length === 0 && (
|
|
125
|
+
<Flex gap={2} wrap="wrap">
|
|
126
|
+
{agent.starterSuggestions.map((suggestion, index) => (
|
|
127
|
+
<Button
|
|
128
|
+
key={`suggestion-${index}`}
|
|
129
|
+
variant="fill"
|
|
130
|
+
mode="subtle"
|
|
131
|
+
roundness="full"
|
|
132
|
+
size="extrasmall"
|
|
133
|
+
onPress={() => handleSuggestionClick(suggestion)}
|
|
134
|
+
>
|
|
135
|
+
{suggestion.label || suggestion.content}
|
|
136
|
+
</Button>
|
|
137
|
+
))}
|
|
138
|
+
</Flex>
|
|
139
|
+
)}
|
|
140
|
+
|
|
141
|
+
{messages.map((message, index) => renderMessage(message, index))}
|
|
142
|
+
|
|
143
|
+
{isThinking && (
|
|
144
|
+
<Text as="p" size={2} className="mr-auto items-start text-gray-500">
|
|
145
|
+
Thinking...
|
|
146
|
+
</Text>
|
|
147
|
+
)}
|
|
148
|
+
|
|
149
|
+
{error && (
|
|
150
|
+
<Text
|
|
151
|
+
as="p"
|
|
152
|
+
size={2}
|
|
153
|
+
className="bg-negative-100 text-negative-900 mx-auto items-start rounded-lg py-2 px-3"
|
|
154
|
+
>
|
|
155
|
+
Error: {error}
|
|
156
|
+
</Text>
|
|
157
|
+
)}
|
|
158
|
+
</Flex>
|
|
159
|
+
</ScrollArea.Viewport>
|
|
160
|
+
<ScrollArea.Scrollbar orientation="vertical" className="w-1 bg-gray-200 opacity-50">
|
|
161
|
+
<ScrollArea.Thumb className="flex-1 rounded-2xl bg-gray-400" />
|
|
162
|
+
</ScrollArea.Scrollbar>
|
|
163
|
+
<ScrollArea.Corner />
|
|
164
|
+
</ScrollArea.Root>
|
|
165
|
+
</Flex>
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export type { ChatBodyProps };
|
|
170
|
+
|
|
171
|
+
export default ChatBody;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Send } from 'lucide-react';
|
|
3
|
+
import type { KeyboardEvent } from 'react';
|
|
4
|
+
|
|
5
|
+
import { Button, Flex, TextArea } from '../components';
|
|
6
|
+
|
|
7
|
+
type ChatFooterProps = {
|
|
8
|
+
sendMessage: (message: string) => void;
|
|
9
|
+
isDisabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const ChatFooter = ({ sendMessage, isDisabled = false }: ChatFooterProps) => {
|
|
13
|
+
const [inputValue, setInputValue] = useState('');
|
|
14
|
+
|
|
15
|
+
const handleSubmit = () => {
|
|
16
|
+
if (!inputValue.trim()) return;
|
|
17
|
+
sendMessage(inputValue);
|
|
18
|
+
setInputValue('');
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
22
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
handleSubmit();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className="shrink-0 grow-0 border-t border-t-gray-400/40">
|
|
30
|
+
<Flex gap={2} align="end" className="w-full">
|
|
31
|
+
<div className="w-full [&_textarea]:!border-none [&_textarea]:!outline-none">
|
|
32
|
+
<TextArea
|
|
33
|
+
aria-label="message"
|
|
34
|
+
size="extralarge"
|
|
35
|
+
placeholder="Ask anything..."
|
|
36
|
+
value={inputValue}
|
|
37
|
+
onKeyDown={handleKeyDown}
|
|
38
|
+
onChange={(text) => setInputValue(text)}
|
|
39
|
+
roundness="none"
|
|
40
|
+
autogrow
|
|
41
|
+
/>
|
|
42
|
+
</div>
|
|
43
|
+
<div className="mr-[7px] mb-[7px]">
|
|
44
|
+
<Button
|
|
45
|
+
shape="square"
|
|
46
|
+
roundness="full"
|
|
47
|
+
variant="fill"
|
|
48
|
+
size="medium"
|
|
49
|
+
onPress={handleSubmit}
|
|
50
|
+
isDisabled={!inputValue.trim() || isDisabled}
|
|
51
|
+
>
|
|
52
|
+
<Send size={20} />
|
|
53
|
+
</Button>
|
|
54
|
+
</div>
|
|
55
|
+
</Flex>
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type { ChatFooterProps }
|
|
61
|
+
|
|
62
|
+
export default ChatFooter;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AiAgent } from '@dashx/browser';
|
|
3
|
+
|
|
4
|
+
import { Flex, Heading } from '../components';
|
|
5
|
+
|
|
6
|
+
type ChatHeaderProps = {
|
|
7
|
+
agent: AiAgent;
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const ChatHeader = ({ agent, children }: ChatHeaderProps) => {
|
|
12
|
+
return (
|
|
13
|
+
<Flex
|
|
14
|
+
align="center"
|
|
15
|
+
className="border-b border-b-gray-400/40 px-6 py-4"
|
|
16
|
+
justify="between"
|
|
17
|
+
>
|
|
18
|
+
<Heading size={3}>{agent.name}</Heading>
|
|
19
|
+
{children}
|
|
20
|
+
</Flex>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type { ChatHeaderProps }
|
|
25
|
+
|
|
26
|
+
export default ChatHeader;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Chat, type ChatWrapperProps } from './Chat.js';
|
|
4
|
+
import { Button, Flex, Popover, Theme } from '../components';
|
|
5
|
+
import { BotMessageSquareIcon } from '../icons/index.js';
|
|
6
|
+
import useAgent from '../hooks/use-agent.js';
|
|
7
|
+
|
|
8
|
+
const ChatPopup = ({ publicEmbedKey, ...props }: ChatWrapperProps) => {
|
|
9
|
+
const { agent, messages, isThinking, error, sendMessage, conversationId } = useAgent({ publicEmbedKey });
|
|
10
|
+
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<Theme>
|
|
14
|
+
<Flex className="fixed right-4 bottom-4 z-50">
|
|
15
|
+
<Popover.Root onOpenChange={setIsPopoverOpen}>
|
|
16
|
+
<Popover.Trigger>
|
|
17
|
+
<Button shape="square" roundness="full" variant="fill" size="large">
|
|
18
|
+
<BotMessageSquareIcon />
|
|
19
|
+
</Button>
|
|
20
|
+
</Popover.Trigger>
|
|
21
|
+
<Popover.Content spacing="large" width="350px" height="450px">
|
|
22
|
+
<Chat
|
|
23
|
+
agent={agent}
|
|
24
|
+
conversationId={conversationId}
|
|
25
|
+
messages={messages}
|
|
26
|
+
isThinking={isThinking}
|
|
27
|
+
error={error}
|
|
28
|
+
sendMessage={sendMessage}
|
|
29
|
+
borderless
|
|
30
|
+
withChatHeader
|
|
31
|
+
withPopoverClose
|
|
32
|
+
isPopoverOpen={isPopoverOpen}
|
|
33
|
+
{...props}
|
|
34
|
+
/>
|
|
35
|
+
</Popover.Content>
|
|
36
|
+
</Popover.Root>
|
|
37
|
+
</Flex>
|
|
38
|
+
</Theme>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default ChatPopup;
|
|
@@ -42,7 +42,7 @@ const NotificationBell = () => {
|
|
|
42
42
|
</Popover.Header>
|
|
43
43
|
<Popover.Body>
|
|
44
44
|
<Flex direction="column" gap={1}>
|
|
45
|
-
{notifications.length
|
|
45
|
+
{notifications.length === 0 && (
|
|
46
46
|
<Flex justify="center" align="center">
|
|
47
47
|
<Text variant="tertiary" size={2}>
|
|
48
48
|
No notifications yet.
|
package/src/widgets/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { default as Chat } from './Chat.js';
|
|
2
|
+
export { default as ChatPopover } from './ChatPopover.js';
|
|
1
3
|
export { default as NotificationBell } from './NotificationBell.js';
|
|
2
4
|
export { default as Preference } from './Preference.js';
|
|
3
5
|
export { default as Preferences } from './Preferences.js';
|