@object-ui/plugin-chatbot 3.3.0 → 3.3.2

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/src/index.tsx DELETED
@@ -1,267 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- import * as React from "react"
10
- import { cn } from "@object-ui/components"
11
- import { Button, Input, ScrollArea, Avatar, AvatarFallback, AvatarImage } from "@object-ui/components"
12
- import { Send } from "lucide-react"
13
-
14
- // Message type definition
15
- export interface ChatMessage {
16
- id: string
17
- role: "user" | "assistant" | "system"
18
- content: string
19
- timestamp?: string
20
- avatar?: string
21
- avatarFallback?: string
22
- }
23
-
24
- // Chatbot container props
25
- export interface ChatbotProps extends React.HTMLAttributes<HTMLDivElement> {
26
- messages?: ChatMessage[]
27
- placeholder?: string
28
- onSendMessage?: (message: string) => void
29
- disabled?: boolean
30
- showTimestamp?: boolean
31
- userAvatarUrl?: string
32
- userAvatarFallback?: string
33
- assistantAvatarUrl?: string
34
- assistantAvatarFallback?: string
35
- maxHeight?: string
36
- }
37
-
38
- // Chatbot container component
39
- const Chatbot = React.forwardRef<HTMLDivElement, ChatbotProps>(
40
- (
41
- {
42
- className,
43
- messages = [],
44
- placeholder = "Type your message...",
45
- onSendMessage,
46
- disabled = false,
47
- showTimestamp = false,
48
- userAvatarUrl,
49
- userAvatarFallback = "You",
50
- assistantAvatarUrl,
51
- assistantAvatarFallback = "AI",
52
- maxHeight = "500px",
53
- ...props
54
- },
55
- ref
56
- ) => {
57
- const [inputValue, setInputValue] = React.useState("")
58
- const scrollRef = React.useRef<HTMLDivElement>(null)
59
- const inputRef = React.useRef<HTMLInputElement>(null)
60
-
61
- // Auto-scroll to bottom when new messages arrive
62
- React.useEffect(() => {
63
- if (scrollRef.current) {
64
- const scrollElement = scrollRef.current.querySelector('[data-radix-scroll-area-viewport]')
65
- if (scrollElement) {
66
- scrollElement.scrollTop = scrollElement.scrollHeight
67
- }
68
- }
69
- }, [messages])
70
-
71
- const handleSend = () => {
72
- if (inputValue.trim() && onSendMessage) {
73
- onSendMessage(inputValue.trim())
74
- setInputValue("")
75
- inputRef.current?.focus()
76
- }
77
- }
78
-
79
- const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
80
- if (e.key === "Enter" && !e.shiftKey) {
81
- e.preventDefault()
82
- handleSend()
83
- }
84
- }
85
-
86
- return (
87
- <div
88
- ref={ref}
89
- className={cn(
90
- "flex flex-col border rounded-lg bg-background overflow-hidden",
91
- className
92
- )}
93
- style={{ maxHeight }}
94
- {...props}
95
- >
96
- {/* Messages area */}
97
- <ScrollArea ref={scrollRef} className="flex-1 p-4">
98
- <div className="space-y-4">
99
- {messages.length === 0 ? (
100
- <div className="flex items-center justify-center h-32 text-muted-foreground text-sm">
101
- No messages yet. Start a conversation!
102
- </div>
103
- ) : (
104
- messages.map((message) => (
105
- <ChatMessageItem
106
- key={message.id}
107
- message={message}
108
- showTimestamp={showTimestamp}
109
- userAvatarUrl={userAvatarUrl}
110
- userAvatarFallback={userAvatarFallback}
111
- assistantAvatarUrl={assistantAvatarUrl}
112
- assistantAvatarFallback={assistantAvatarFallback}
113
- />
114
- ))
115
- )}
116
- </div>
117
- </ScrollArea>
118
-
119
- {/* Input area */}
120
- <div className="border-t p-4">
121
- <div className="flex gap-2">
122
- <Input
123
- ref={inputRef}
124
- value={inputValue}
125
- onChange={(e) => setInputValue(e.target.value)}
126
- onKeyDown={handleKeyDown}
127
- placeholder={placeholder}
128
- disabled={disabled}
129
- className="flex-1"
130
- />
131
- <Button
132
- onClick={handleSend}
133
- disabled={disabled || !inputValue.trim()}
134
- size="icon"
135
- >
136
- <Send className="h-4 w-4" />
137
- </Button>
138
- </div>
139
- </div>
140
- </div>
141
- )
142
- }
143
- )
144
- Chatbot.displayName = "Chatbot"
145
-
146
- // Individual message component
147
- export interface ChatMessageProps {
148
- message: ChatMessage
149
- showTimestamp?: boolean
150
- userAvatarUrl?: string
151
- userAvatarFallback?: string
152
- assistantAvatarUrl?: string
153
- assistantAvatarFallback?: string
154
- }
155
-
156
- const ChatMessageItem: React.FC<ChatMessageProps> = ({
157
- message,
158
- showTimestamp,
159
- userAvatarUrl,
160
- userAvatarFallback,
161
- assistantAvatarUrl,
162
- assistantAvatarFallback,
163
- }) => {
164
- const isUser = message.role === "user"
165
- const isSystem = message.role === "system"
166
-
167
- if (isSystem) {
168
- return (
169
- <div className="flex justify-center">
170
- <div className="text-xs text-muted-foreground bg-muted px-3 py-1 rounded-full">
171
- {message.content}
172
- </div>
173
- </div>
174
- )
175
- }
176
-
177
- const avatar = isUser
178
- ? (message.avatar || userAvatarUrl)
179
- : (message.avatar || assistantAvatarUrl)
180
-
181
- const avatarFallback = isUser
182
- ? (message.avatarFallback || userAvatarFallback)
183
- : (message.avatarFallback || assistantAvatarFallback)
184
-
185
- return (
186
- <div
187
- className={cn(
188
- "flex gap-3",
189
- isUser ? "flex-row-reverse" : "flex-row"
190
- )}
191
- >
192
- <Avatar className="h-8 w-8">
193
- <AvatarImage src={avatar} />
194
- <AvatarFallback className="text-xs">{avatarFallback}</AvatarFallback>
195
- </Avatar>
196
-
197
- <div className={cn("flex flex-col gap-1", isUser ? "items-end" : "items-start")}>
198
- <div
199
- className={cn(
200
- "rounded-lg px-4 py-2 max-w-[70%] break-words",
201
- isUser
202
- ? "bg-primary text-primary-foreground"
203
- : "bg-muted"
204
- )}
205
- >
206
- <p className="text-sm whitespace-pre-wrap">{message.content}</p>
207
- </div>
208
- {showTimestamp && message.timestamp && (
209
- <span className="text-xs text-muted-foreground">
210
- {message.timestamp}
211
- </span>
212
- )}
213
- </div>
214
- </div>
215
- )
216
- }
217
-
218
- // Typing indicator component
219
- export interface TypingIndicatorProps extends React.HTMLAttributes<HTMLDivElement> {
220
- avatarSrc?: string
221
- avatarFallback?: string
222
- }
223
-
224
- const TypingIndicator = React.forwardRef<HTMLDivElement, TypingIndicatorProps>(
225
- ({ className, avatarSrc, avatarFallback = "AI", ...props }, ref) => {
226
- return (
227
- <div ref={ref} className={cn("flex gap-3", className)} {...props}>
228
- <Avatar className="h-8 w-8">
229
- <AvatarImage src={avatarSrc} />
230
- <AvatarFallback className="text-xs">{avatarFallback}</AvatarFallback>
231
- </Avatar>
232
- <div className="flex items-center bg-muted rounded-lg px-4 py-2">
233
- <div className="flex gap-1">
234
- <span className="w-2 h-2 bg-muted-foreground rounded-full animate-bounce [animation-delay:-0.3s]"></span>
235
- <span className="w-2 h-2 bg-muted-foreground rounded-full animate-bounce [animation-delay:-0.15s]"></span>
236
- <span className="w-2 h-2 bg-muted-foreground rounded-full animate-bounce"></span>
237
- </div>
238
- </div>
239
- </div>
240
- )
241
- }
242
- )
243
- TypingIndicator.displayName = "TypingIndicator"
244
-
245
- export { Chatbot, TypingIndicator }
246
-
247
- // Export the composable chat hook for custom integrations
248
- export { useObjectChat } from './useObjectChat';
249
- export type { UseObjectChatOptions, UseObjectChatReturn } from './useObjectChat';
250
-
251
- // Export floating chatbot components
252
- export { FloatingChatbot } from './FloatingChatbot';
253
- export type { FloatingChatbotProps } from './FloatingChatbot';
254
- export { FloatingChatbotProvider, useFloatingChatbot } from './FloatingChatbotProvider';
255
- export type {
256
- FloatingChatbotProviderProps,
257
- FloatingChatbotState,
258
- FloatingChatbotActions,
259
- FloatingChatbotContextValue,
260
- } from './FloatingChatbotProvider';
261
- export { FloatingChatbotTrigger } from './FloatingChatbotTrigger';
262
- export type { FloatingChatbotTriggerProps } from './FloatingChatbotTrigger';
263
- export { FloatingChatbotPanel } from './FloatingChatbotPanel';
264
- export type { FloatingChatbotPanelProps } from './FloatingChatbotPanel';
265
-
266
- // Export renderer to register the component with ObjectUI
267
- export * from './renderer';