@0xbot/chat-react 1.0.8

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/README.md ADDED
@@ -0,0 +1,203 @@
1
+ # Chat Library React
2
+
3
+ A React component for building chat interfaces with streaming support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @0xbot/chat-react
9
+ # or
10
+ yarn add @0xbot/chat-react
11
+ # or
12
+ pnpm add @0xbot/chat-react
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import React from 'react'
19
+ import { ChatLibrary } from '@0xbot/chat-react'
20
+ import '@0xbot/chat-react/dist/style.css' // Import the CSS
21
+
22
+ const App = () => {
23
+ return (
24
+ <ChatLibrary
25
+ apiKey="your-api-key" // required
26
+ serverUrl="your-server-url" // not required
27
+ UserAvatar={<YourUserAvatar />} // required
28
+ AgentAvatar={<YourAgentAvatar />} // required
29
+ loadingText="AI is thinking..." // not required
30
+ emptyText="No messages yet" // not required
31
+ />
32
+ )
33
+ }
34
+
35
+ export default App
36
+ ```
37
+
38
+ ## Props
39
+
40
+ | Prop | Type | Required | Default | Description |
41
+ |------|------|----------|---------|-------------|
42
+ | apiKey | string | Yes | - | Your API key for authentication |
43
+ | serverUrl | string | Yes | - | The server URL for API requests |
44
+ | UserAvatar | ReactNode | Yes | - | The avatar component for user messages |
45
+ | AgentAvatar | ReactNode | Yes | - | The avatar component for agent messages |
46
+ | loadingText | string | No | 'AI is thinking...' | Text to display while loading |
47
+ | emptyText | string | No | 'No messages yet' | Text to display when there are no messages |
48
+ | theme | object | No | {} | Theme configuration object |
49
+
50
+ ## Features
51
+
52
+ - Real-time message streaming
53
+ - Markdown support
54
+ - Customizable theme
55
+ - Responsive design
56
+ - Built-in loading states
57
+ - Error handling
58
+
59
+ ## Dependencies
60
+
61
+ This library requires the following peer dependencies:
62
+
63
+ - React 16.8 or higher
64
+ - React DOM 16.8 or higher
65
+
66
+ ## Styling
67
+
68
+ ```css
69
+ /* Main container */
70
+ .chat-library {
71
+ box-sizing: border-box;
72
+ height: 100%;
73
+ position: relative;
74
+ display: flex;
75
+ flex-direction: column;
76
+ justify-content: space-between;
77
+ gap: 16px;
78
+ }
79
+
80
+ /* Bottom bar */
81
+ .chat-bar {
82
+ display: flex;
83
+ align-items: center;
84
+ gap: 16px;
85
+ }
86
+
87
+ /* Input field */
88
+ .chat-bar-input {
89
+ flex: 1;
90
+ height: 44px;
91
+ outline: none;
92
+ border-radius: 99999px;
93
+ border: 1px solid #ccc;
94
+ background-color: transparent;
95
+ color: #fff;
96
+ padding: 0 16px;
97
+ min-width: 0;
98
+ }
99
+
100
+ /* Send button */
101
+ .chat-bar-send {
102
+ flex: none;
103
+ width: auto;
104
+ border: 1px solid;
105
+ height: 48px;
106
+ padding: 0 32px;
107
+ border-radius: 99999px;
108
+ cursor: pointer;
109
+ background-color: transparent;
110
+ transition: all 0.2s ease-in-out;
111
+ }
112
+
113
+ /* Send button hover */
114
+ .chat-bar-send:hover {
115
+ background-color: var(--primary-color);
116
+ color: white !important;
117
+ }
118
+
119
+ /* Chat container (excluding bottom bar) */
120
+ .chat-container {
121
+ flex: 1;
122
+ overflow-y: scroll;
123
+ scrollbar-width: none;
124
+ -ms-overflow-style: none;
125
+ }
126
+
127
+ /* Hide scrollbar */
128
+ .chat-container::-webkit-scrollbar {
129
+ display: none;
130
+ }
131
+
132
+ /* Chat message list */
133
+ .chat-container-list {
134
+ display: flex;
135
+ flex-direction: column;
136
+ gap: 16px;
137
+ }
138
+
139
+ /* Message bubble */
140
+ .message-bubble {
141
+ padding: 12px 16px;
142
+ border-radius: 8px;
143
+ max-width: 90%;
144
+ font-size: 14px;
145
+ word-break: break-all;
146
+ line-height: 24px;
147
+ }
148
+
149
+ @media (min-width: 768px) {
150
+ .message-bubble {
151
+ max-width: 70%;
152
+ font-size: 13px;
153
+ }
154
+ }
155
+
156
+ /* Avatar */
157
+ .chat-avatar {
158
+ width: 44px;
159
+ height: 44px;
160
+ max-width:44px;
161
+ max-height:44px;
162
+ min-width: 44px;
163
+ min-height: 44px;
164
+ border-radius: 8px;
165
+ }
166
+
167
+ /* Message bubble background */
168
+ .chat-message {
169
+ background-color: rgba(255, 255, 255, 0.1)
170
+ }
171
+
172
+ /* Message container */
173
+ .message-container {
174
+ display: flex;
175
+ }
176
+
177
+ /* Delete button */
178
+ .chat-bar-trash {
179
+ width: 24px;
180
+ height: 24px;
181
+ min-width: 24px;
182
+ min-height: 24px;
183
+ color: #fff;
184
+ cursor: pointer;
185
+ }
186
+
187
+ /* Loading state */
188
+ .message-loading {
189
+ color: #fff;
190
+ font-style: italic;
191
+ }
192
+
193
+ /* Empty message state */
194
+ .message-empty {
195
+ color: #fff;
196
+ font-style: italic;
197
+ text-align: center;
198
+ }
199
+ ```
200
+
201
+ ## License
202
+
203
+ MIT
@@ -0,0 +1,8 @@
1
+ import { ResponseData } from '../utils/request';
2
+ import { loginWithDeviceProps, conversationHistoryProps, authProps, AuthDataRes, upsertConversationProps } from './types';
3
+
4
+ export declare const login_with_device: (data: loginWithDeviceProps) => Promise<ResponseData<AuthDataRes>>;
5
+ export declare const sdk_sdk_get_token: (data: authProps) => Promise<ResponseData<AuthDataRes>>;
6
+ export declare const app_conversation_history: (data: conversationHistoryProps) => Promise<ResponseData>;
7
+ export declare const app_upsert_conversation: (data: upsertConversationProps) => Promise<ResponseData>;
8
+ export declare const app_delete_one_conversation_history: (id: string) => Promise<ResponseData>;
@@ -0,0 +1,81 @@
1
+ export interface loginWithDeviceProps {
2
+ device_id: string;
3
+ location: string;
4
+ }
5
+ export interface conversationHistoryProps {
6
+ page: number;
7
+ pagesize: number;
8
+ app_id: string;
9
+ conversation_id: string;
10
+ }
11
+ export interface authProps {
12
+ api_key: string;
13
+ unique_id: string;
14
+ }
15
+ export interface AuthDataRes {
16
+ auth: Auth;
17
+ agent: Agent;
18
+ }
19
+ export interface DataProps {
20
+ auth: Auth;
21
+ agent: Agent;
22
+ }
23
+ export interface Agent {
24
+ id: string;
25
+ name: string;
26
+ description: string;
27
+ nickname: string;
28
+ icon: string;
29
+ user_pay_bill: boolean;
30
+ conversation_id: string;
31
+ app_id: string;
32
+ agent_type: string;
33
+ visibility: number;
34
+ category: string;
35
+ base_url: string;
36
+ api_key: string;
37
+ twitter_cookie: string;
38
+ twitter_username: string;
39
+ shortcuts: any[];
40
+ user_prompt: string;
41
+ opening_text: string;
42
+ role_user_id: string;
43
+ }
44
+ export interface Auth {
45
+ token: string;
46
+ user_id: string;
47
+ invite_code: string;
48
+ invite_link: string;
49
+ parent_user_id: string;
50
+ avatar: string;
51
+ phone: string;
52
+ email: string;
53
+ is_agent: boolean;
54
+ name: string;
55
+ }
56
+ export interface upsertConversationProps {
57
+ id: string;
58
+ app_id: string;
59
+ name: string;
60
+ }
61
+ export interface StramProps {
62
+ q: string;
63
+ app_id: string;
64
+ conversation_id: string;
65
+ is_debug: boolean;
66
+ medias: any[];
67
+ tool?: Tool;
68
+ knowledge?: Knowledge;
69
+ }
70
+ export interface Knowledge {
71
+ id: string;
72
+ type: string;
73
+ q: string;
74
+ }
75
+ export interface Tool {
76
+ id: string;
77
+ params: Params;
78
+ json: Params;
79
+ }
80
+ export interface Params {
81
+ }
@@ -0,0 +1,5 @@
1
+ import { default as React } from 'react';
2
+ import { ChatLibraryProps } from '../types';
3
+
4
+ declare const ChatLibrary: React.FC<ChatLibraryProps>;
5
+ export default ChatLibrary;
@@ -0,0 +1,5 @@
1
+ import { default as React } from 'react';
2
+ import { MessageItemProps } from '../types';
3
+
4
+ declare const MessageItem: React.FC<MessageItemProps>;
5
+ export default MessageItem;
@@ -0,0 +1,6 @@
1
+ export declare const useEventStream: () => {
2
+ loading: boolean;
3
+ error: Error | null;
4
+ connect: (data: any, SERVER_URL: string, onMessage: (message: any) => void) => Promise<void>;
5
+ close: () => void;
6
+ };
@@ -0,0 +1,11 @@
1
+ interface UseStorageOptions {
2
+ prefix?: string;
3
+ }
4
+ export declare function useStorage(options?: UseStorageOptions): {
5
+ getStorage: <T>(key: string) => Promise<T | null>;
6
+ setStorage: <T>(key: string, value: T) => Promise<void>;
7
+ removeStorage: (key: string) => Promise<void>;
8
+ clearStorage: () => Promise<void>;
9
+ useStorageState: <T>(key: string, defaultValue: T) => readonly [T, import('react').Dispatch<import('react').SetStateAction<T>>];
10
+ };
11
+ export {};
@@ -0,0 +1,8 @@
1
+ import { default as ChatLibrary } from './components/ChatLibrary';
2
+ import { default as MessageItem } from './components/MessageItem';
3
+ import { ChatLibraryProps, ChatMessage } from './types';
4
+ import { Agent, authProps, conversationHistoryProps, StramProps } from './api/types';
5
+
6
+ export { ChatLibrary, MessageItem };
7
+ export type { ChatLibraryProps, ChatMessage, Agent, authProps, conversationHistoryProps, StramProps };
8
+ export default ChatLibrary;