@inappai/react 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +128 -80
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -8,11 +8,11 @@ Beautiful, customizable AI chat component for React applications. Built by [InAp
8
8
  ## Features
9
9
 
10
10
  - ✨ **Beautiful UI** - Polished interface out of the box
11
- - 🎨 **Fully Customizable** - 7 built-in themes + custom styling support
11
+ - 🎨 **7 Built-in Themes** - Light, dark, professional, playful, minimal, ocean, sunset
12
12
  - 📱 **Responsive Design** - Works seamlessly on desktop and mobile
13
13
  - 🎯 **Multiple Display Modes** - Popup, sidebar, panel, or embedded
14
- - 🎛️ **Controlled Mode** - External message management for multi-conversation support
15
- - 🔧 **Tool Support** - Register custom tools for AI agent interactions
14
+ - 🎛️ **Controlled Mode** - Full control over message state
15
+ - 🔧 **Tool Support** - Function calling for AI agent interactions
16
16
  - ⚡ **Zero Config** - Works with sensible defaults
17
17
  - 📦 **Lightweight** - Minimal bundle size (~60KB)
18
18
  - 🔷 **TypeScript** - Full type safety included
@@ -27,33 +27,38 @@ npm install @inappai/react
27
27
  ## Quick Start
28
28
 
29
29
  ```tsx
30
- import { InAppAI } from '@inappai/react';
30
+ import { useState } from 'react';
31
+ import { InAppAI, Message } from '@inappai/react';
31
32
  import '@inappai/react/styles.css';
32
33
 
33
34
  function App() {
35
+ const [messages, setMessages] = useState<Message[]>([]);
36
+
34
37
  return (
35
38
  <InAppAI
36
- endpoint="https://api.inappai.com/api"
37
39
  agentId="your-agent-id"
38
- position="bottom-right"
39
- theme="light"
40
+ messages={messages}
41
+ onMessagesChange={setMessages}
40
42
  />
41
43
  );
42
44
  }
43
45
  ```
44
46
 
47
+ Get your agent ID from [inappai.com](https://www.inappai.com).
48
+
45
49
  ## Display Modes
46
50
 
47
51
  ### Popup Mode (Default)
48
52
 
49
- Chat appears as a floating bubble in the corner of your app:
53
+ Chat appears as a floating bubble in the corner:
50
54
 
51
55
  ```tsx
52
56
  <InAppAI
53
- endpoint="https://api.inappai.com/api"
54
57
  agentId="your-agent-id"
55
- position="bottom-right"
58
+ messages={messages}
59
+ onMessagesChange={setMessages}
56
60
  displayMode="popup"
61
+ position="bottom-right"
57
62
  />
58
63
  ```
59
64
 
@@ -63,22 +68,24 @@ Chat slides in from the side:
63
68
 
64
69
  ```tsx
65
70
  <InAppAI
66
- endpoint="https://api.inappai.com/api"
67
71
  agentId="your-agent-id"
68
- position="right"
69
- displayMode="sidebar"
72
+ messages={messages}
73
+ onMessagesChange={setMessages}
74
+ displayMode="sidebar-right"
70
75
  />
71
76
  ```
72
77
 
73
78
  ### Panel Mode
74
79
 
75
- Overlay panel that covers the screen:
80
+ Resizable panel overlay:
76
81
 
77
82
  ```tsx
78
83
  <InAppAI
79
- endpoint="https://api.inappai.com/api"
80
84
  agentId="your-agent-id"
81
- displayMode="panel"
85
+ messages={messages}
86
+ onMessagesChange={setMessages}
87
+ displayMode="panel-right"
88
+ panelDefaultWidth="400px"
82
89
  />
83
90
  ```
84
91
 
@@ -89,8 +96,9 @@ Embed chat directly in your layout:
89
96
  ```tsx
90
97
  <div style={{ height: '600px', width: '400px' }}>
91
98
  <InAppAI
92
- endpoint="https://api.inappai.com/api"
93
99
  agentId="your-agent-id"
100
+ messages={messages}
101
+ onMessagesChange={setMessages}
94
102
  displayMode="embedded"
95
103
  showHeader={false}
96
104
  />
@@ -103,9 +111,10 @@ Choose from 7 built-in themes:
103
111
 
104
112
  ```tsx
105
113
  <InAppAI
106
- endpoint="https://api.inappai.com/api"
107
114
  agentId="your-agent-id"
108
- theme="dark" // light | dark | ocean | forest | sunset | midnight | rose
115
+ messages={messages}
116
+ onMessagesChange={setMessages}
117
+ theme="dark" // light | dark | professional | playful | minimal | ocean | sunset
109
118
  />
110
119
  ```
111
120
 
@@ -115,98 +124,138 @@ Override styles with custom CSS:
115
124
 
116
125
  ```tsx
117
126
  <InAppAI
118
- endpoint="https://api.inappai.com/api"
119
127
  agentId="your-agent-id"
128
+ messages={messages}
129
+ onMessagesChange={setMessages}
120
130
  customStyles={{
121
131
  primaryColor: '#FF6B6B',
122
- backgroundColor: '#FFFFFF',
123
- textColor: '#333333',
124
- bubbleBgColor: '#F0F0F0',
132
+ headerTitle: 'Support Chat',
133
+ buttonIcon: '💬',
125
134
  }}
126
135
  />
127
136
  ```
128
137
 
129
- ## Controlled Mode
138
+ ## Tool Support
130
139
 
131
- Manage messages externally for multi-conversation support:
140
+ Register custom tools for AI function calling:
132
141
 
133
142
  ```tsx
134
- import { InAppAI, Message } from '@inappai/react';
135
- import { useState } from 'react';
143
+ import { InAppAI, Tool } from '@inappai/react';
144
+
145
+ const tools: Tool[] = [
146
+ {
147
+ name: 'get_weather',
148
+ description: 'Get current weather for a location',
149
+ parameters: {
150
+ type: 'object',
151
+ properties: {
152
+ location: { type: 'string', description: 'City name' },
153
+ },
154
+ required: ['location'],
155
+ },
156
+ handler: async ({ location }) => {
157
+ const weather = await fetchWeather(location);
158
+ return { temperature: weather.temp, condition: weather.condition };
159
+ },
160
+ },
161
+ ];
136
162
 
137
- function MultiChatApp() {
163
+ function App() {
138
164
  const [messages, setMessages] = useState<Message[]>([]);
139
- const [conversationId, setConversationId] = useState('chat-1');
140
165
 
141
166
  return (
142
167
  <InAppAI
143
- endpoint="https://api.inappai.com/api"
144
168
  agentId="your-agent-id"
145
- displayMode="embedded"
146
- conversationId={conversationId}
147
169
  messages={messages}
148
170
  onMessagesChange={setMessages}
171
+ tools={tools}
149
172
  />
150
173
  );
151
174
  }
152
175
  ```
153
176
 
154
- ## Tool Support
177
+ ## Context Passing
155
178
 
156
- Register custom tools for AI agent interactions:
179
+ Send application context to make responses more relevant:
157
180
 
158
181
  ```tsx
159
- import { InAppAI, useToolRegistry } from '@inappai/react';
160
-
161
- function AppWithTools() {
162
- const tools = [
163
- {
164
- name: 'get_weather',
165
- description: 'Get current weather for a location',
166
- parameters: {
167
- type: 'object',
168
- properties: {
169
- location: { type: 'string', description: 'City name' },
170
- },
171
- required: ['location'],
172
- },
173
- handler: async ({ location }) => {
174
- const weather = await fetchWeather(location);
175
- return { temperature: weather.temp, condition: weather.condition };
176
- },
177
- },
178
- ];
182
+ <InAppAI
183
+ agentId="your-agent-id"
184
+ messages={messages}
185
+ onMessagesChange={setMessages}
186
+ context={{
187
+ page: 'dashboard',
188
+ userId: user.id,
189
+ userRole: user.role,
190
+ }}
191
+ />
192
+ ```
179
193
 
180
- return (
181
- <InAppAI
182
- endpoint="https://api.inappai.com/api"
183
- agentId="your-agent-id"
184
- tools={tools}
185
- />
186
- );
187
- }
194
+ Or use dynamic context:
195
+
196
+ ```tsx
197
+ <InAppAI
198
+ agentId="your-agent-id"
199
+ messages={messages}
200
+ onMessagesChange={setMessages}
201
+ context={() => ({
202
+ currentUrl: window.location.pathname,
203
+ selectedText: window.getSelection()?.toString(),
204
+ })}
205
+ />
188
206
  ```
189
207
 
190
208
  ## API Reference
191
209
 
192
- ### Props
210
+ ### Required Props
211
+
212
+ | Prop | Type | Description |
213
+ |------|------|-------------|
214
+ | `agentId` | `string` | Your agent ID from InAppAI platform |
215
+ | `messages` | `Message[]` | Array of conversation messages |
216
+ | `onMessagesChange` | `(messages: Message[]) => void` | Callback when messages change |
217
+
218
+ ### Display Props
193
219
 
194
220
  | Prop | Type | Default | Description |
195
221
  |------|------|---------|-------------|
196
- | `endpoint` | `string` | **required** | Backend API endpoint |
197
- | `agentId` | `string` | **required** | Your agent ID |
198
- | `displayMode` | `'popup' \| 'sidebar' \| 'panel' \| 'embedded'` | `'popup'` | Display mode |
199
- | `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left' \| 'left' \| 'right'` | `'bottom-right'` | Position for popup/sidebar |
200
- | `theme` | `'light' \| 'dark' \| 'ocean' \| 'forest' \| 'sunset' \| 'midnight' \| 'rose'` | `'light'` | Color theme |
201
- | `title` | `string` | `'AI Assistant'` | Chat header title |
202
- | `placeholder` | `string` | `'Type a message...'` | Input placeholder |
222
+ | `displayMode` | `'popup' \| 'sidebar-left' \| 'sidebar-right' \| 'panel-left' \| 'panel-right' \| 'embedded'` | `'popup'` | Layout mode |
223
+ | `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Button position (popup only) |
224
+ | `defaultFolded` | `boolean` | `false` | Start folded (sidebar/panel only) |
203
225
  | `showHeader` | `boolean` | `true` | Show/hide header |
204
- | `initialOpen` | `boolean` | `false` | Initially open state |
226
+
227
+ ### Styling Props
228
+
229
+ | Prop | Type | Default | Description |
230
+ |------|------|---------|-------------|
231
+ | `theme` | `'light' \| 'dark' \| 'professional' \| 'playful' \| 'minimal' \| 'ocean' \| 'sunset'` | `'light'` | Built-in theme |
205
232
  | `customStyles` | `CustomStyles` | `{}` | Custom style overrides |
206
- | `tools` | `Tool[]` | `[]` | Custom tools for AI agent |
207
- | `conversationId` | `string` | - | Conversation ID for controlled mode |
208
- | `messages` | `Message[]` | - | Messages for controlled mode |
209
- | `onMessagesChange` | `(messages: Message[]) => void` | - | Message update callback |
233
+
234
+ ### Data Props
235
+
236
+ | Prop | Type | Default | Description |
237
+ |------|------|---------|-------------|
238
+ | `context` | `Record<string, any> \| (() => Record<string, any>)` | - | App context sent with messages |
239
+ | `conversationId` | `string` | Auto-generated | Conversation identifier |
240
+ | `authToken` | `string` | - | JWT token for authentication |
241
+ | `tools` | `Tool[]` | `[]` | Custom tools for function calling |
242
+
243
+ ### Panel Props
244
+
245
+ | Prop | Type | Default | Description |
246
+ |------|------|---------|-------------|
247
+ | `panelMinWidth` | `string` | `'20%'` | Minimum panel width |
248
+ | `panelMaxWidth` | `string` | `'33.33%'` | Maximum panel width |
249
+ | `panelDefaultWidth` | `string` | `'25%'` | Initial panel width |
250
+ | `onPanelResize` | `(width: number) => void` | - | Panel resize callback |
251
+
252
+ ### Event Hooks
253
+
254
+ | Prop | Type | Description |
255
+ |------|------|-------------|
256
+ | `onMessageSent` | `(message: Message) => void` | Called when user sends message |
257
+ | `onMessageReceived` | `(message: Message) => void` | Called when AI responds |
258
+ | `onError` | `(error: Error) => void` | Called on errors |
210
259
 
211
260
  ### Types
212
261
 
@@ -226,11 +275,10 @@ interface Tool {
226
275
 
227
276
  interface CustomStyles {
228
277
  primaryColor?: string;
229
- backgroundColor?: string;
230
- textColor?: string;
231
- bubbleBgColor?: string;
232
- borderRadius?: string;
233
- fontFamily?: string;
278
+ headerTitle?: string;
279
+ buttonIcon?: string;
280
+ windowWidth?: string;
281
+ // ... and many more
234
282
  }
235
283
  ```
236
284
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inappai/react",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Beautiful, customizable AI chat component for React applications",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",