@courseecho/ai-widget-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.
- package/LICENSE +25 -0
- package/README.md +281 -0
- package/package.json +47 -47
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CourseEcho
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
For more information about CourseEcho, visit https://courseecho.com
|
package/README.md
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# ⚛️ @courseecho/ai-widget-react
|
|
2
|
+
|
|
3
|
+
**React component for AI chat widget** - Drop-in AI assistance for your React app.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@courseecho/ai-widget-react)
|
|
6
|
+
[](https://reactjs.org)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
## 📖 Overview
|
|
10
|
+
|
|
11
|
+
A **production-ready React component** for integrating CourseEcho AI chat into your React applications.
|
|
12
|
+
|
|
13
|
+
- ✅ React 16.8+ (hooks support)
|
|
14
|
+
- ✅ TypeScript fully typed
|
|
15
|
+
- ✅ Zero external dependencies
|
|
16
|
+
- ✅ 15KB minified
|
|
17
|
+
- ✅ Works with Next.js, Vite, CRA
|
|
18
|
+
|
|
19
|
+
## 🚀 Quick Start
|
|
20
|
+
|
|
21
|
+
### Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @courseecho/ai-widget-react @courseecho/ai-core-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Basic Usage
|
|
28
|
+
|
|
29
|
+
```jsx
|
|
30
|
+
import { AiChatWidget } from '@courseecho/ai-widget-react';
|
|
31
|
+
|
|
32
|
+
export default function Course() {
|
|
33
|
+
return (
|
|
34
|
+
<AiChatWidget
|
|
35
|
+
apiEndpoint="https://api.courseecho.com/api"
|
|
36
|
+
context={{
|
|
37
|
+
pageType: 'course',
|
|
38
|
+
entityId: 'course-123',
|
|
39
|
+
userId: 'user-456'
|
|
40
|
+
}}
|
|
41
|
+
jwtToken="your-jwt-token"
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 🎯 Props
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
interface AiChatWidgetProps {
|
|
51
|
+
apiEndpoint: string; // Your API endpoint
|
|
52
|
+
context: ContextData; // Page context
|
|
53
|
+
jwtToken?: string; // JWT authentication
|
|
54
|
+
apiKey?: string; // Alternative: API key
|
|
55
|
+
theme?: 'light' | 'dark'; // Theme (default: 'light')
|
|
56
|
+
position?: PositionType; // Widget position
|
|
57
|
+
className?: string; // Custom CSS class
|
|
58
|
+
onMessage?: (msg: string) => void;
|
|
59
|
+
onError?: (err: Error) => void;
|
|
60
|
+
onLoading?: (isLoading: boolean) => void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type PositionType = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 🪝 Custom Hooks
|
|
67
|
+
|
|
68
|
+
Use individual hooks for fine-grained control:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import {
|
|
72
|
+
useAiChat,
|
|
73
|
+
useAiMessages,
|
|
74
|
+
useAiLoading,
|
|
75
|
+
useAiError,
|
|
76
|
+
useAiContext,
|
|
77
|
+
useAiWidget
|
|
78
|
+
} from '@courseecho/ai-widget-react';
|
|
79
|
+
|
|
80
|
+
export function CustomChat() {
|
|
81
|
+
const { sendMessage } = useAiChat({
|
|
82
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
83
|
+
context: { pageType: 'course' }
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const messages = useAiMessages();
|
|
87
|
+
const loading = useAiLoading();
|
|
88
|
+
const error = useAiError();
|
|
89
|
+
const { setContext } = useAiContext();
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div>
|
|
93
|
+
{messages.map(msg => (
|
|
94
|
+
<p key={msg.id}>{msg.content}</p>
|
|
95
|
+
))}
|
|
96
|
+
{loading && <p>Loading...</p>}
|
|
97
|
+
{error && <p>Error: {error}</p>}
|
|
98
|
+
<button onClick={() => sendMessage('Hello!')}>
|
|
99
|
+
Send
|
|
100
|
+
</button>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Available Hooks
|
|
107
|
+
|
|
108
|
+
| Hook | Returns | Purpose |
|
|
109
|
+
|------|---------|---------|
|
|
110
|
+
| `useAiChat()` | `{ sendMessage, state }` | Main chat hook |
|
|
111
|
+
| `useAiMessages()` | `ChatMessage[]` | Get all messages |
|
|
112
|
+
| `useAiLoading()` | `boolean` | Get loading state |
|
|
113
|
+
| `useAiError()` | `string \| null` | Get error message |
|
|
114
|
+
| `useAiContext()` | `{ context, setContext }` | Manage context |
|
|
115
|
+
| `useAiWidget()` | `Widget` | Full SDK access |
|
|
116
|
+
|
|
117
|
+
## 💡 Examples
|
|
118
|
+
|
|
119
|
+
### Example 1: In a Course Page
|
|
120
|
+
|
|
121
|
+
```jsx
|
|
122
|
+
import { AiChatWidget } from '@courseecho/ai-widget-react';
|
|
123
|
+
import { useParams } from 'react-router-dom';
|
|
124
|
+
|
|
125
|
+
export function CoursePage() {
|
|
126
|
+
const { courseId } = useParams();
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div>
|
|
130
|
+
<h1>Course Material</h1>
|
|
131
|
+
<main>
|
|
132
|
+
{/* Course content */}
|
|
133
|
+
</main>
|
|
134
|
+
|
|
135
|
+
<AiChatWidget
|
|
136
|
+
apiEndpoint="https://api.courseecho.com/api"
|
|
137
|
+
context={{
|
|
138
|
+
pageType: 'course',
|
|
139
|
+
entityId: courseId,
|
|
140
|
+
userId: currentUser.id
|
|
141
|
+
}}
|
|
142
|
+
jwtToken={currentUser.token}
|
|
143
|
+
position="bottom-right"
|
|
144
|
+
theme="light"
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Example 2: Theme Based on User Preference
|
|
152
|
+
|
|
153
|
+
```jsx
|
|
154
|
+
import { AiChatWidget } from '@courseecho/ai-widget-react';
|
|
155
|
+
import { useTheme } from './hooks/useTheme';
|
|
156
|
+
|
|
157
|
+
export function App() {
|
|
158
|
+
const { isDark } = useTheme();
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<AiChatWidget
|
|
162
|
+
apiEndpoint="https://api.courseecho.com/api"
|
|
163
|
+
context={{ pageType: 'app' }}
|
|
164
|
+
theme={isDark ? 'dark' : 'light'}
|
|
165
|
+
/>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Example 3: Custom Error Handling
|
|
171
|
+
|
|
172
|
+
```jsx
|
|
173
|
+
import { useAiChat, useAiError } from '@courseecho/ai-widget-react';
|
|
174
|
+
import { toast } from 'react-hot-toast';
|
|
175
|
+
|
|
176
|
+
export function ChatWithNotifications() {
|
|
177
|
+
const sdk = useAiChat({
|
|
178
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
179
|
+
context: { pageType: 'course' }
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const error = useAiError();
|
|
183
|
+
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (error) {
|
|
186
|
+
toast.error(`Chat error: ${error}`);
|
|
187
|
+
}
|
|
188
|
+
}, [error]);
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
// Your custom UI
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## 🎨 Styling
|
|
197
|
+
|
|
198
|
+
The component comes with default styles. Override with custom CSS:
|
|
199
|
+
|
|
200
|
+
```css
|
|
201
|
+
.ai-chat-widget {
|
|
202
|
+
/* Your custom styles */
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.ai-chat-message {
|
|
206
|
+
/* Message styling */
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.ai-chat-input {
|
|
210
|
+
/* Input styling */
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Or use the className prop:
|
|
215
|
+
|
|
216
|
+
```jsx
|
|
217
|
+
<AiChatWidget
|
|
218
|
+
apiEndpoint="..."
|
|
219
|
+
context={{}}
|
|
220
|
+
className="my-custom-chat"
|
|
221
|
+
/>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## 🔐 Authentication
|
|
225
|
+
|
|
226
|
+
### Using JWT
|
|
227
|
+
|
|
228
|
+
```jsx
|
|
229
|
+
<AiChatWidget
|
|
230
|
+
apiEndpoint="..."
|
|
231
|
+
context={{}}
|
|
232
|
+
jwtToken={user.jwtToken}
|
|
233
|
+
/>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Using API Key
|
|
237
|
+
|
|
238
|
+
```jsx
|
|
239
|
+
<AiChatWidget
|
|
240
|
+
apiEndpoint="..."
|
|
241
|
+
context={{}}
|
|
242
|
+
apiKey="sk-123456789..."
|
|
243
|
+
/>
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 📦 What's Included
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
dist/
|
|
250
|
+
├── index.mjs # ES Module
|
|
251
|
+
├── index.cjs # CommonJS
|
|
252
|
+
├── index.d.ts # TypeScript definitions
|
|
253
|
+
└── ...
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## 🌍 About CourseEcho
|
|
257
|
+
|
|
258
|
+
[CourseEcho](https://courseecho.com) provides AI-powered educational assistance.
|
|
259
|
+
|
|
260
|
+
- 🌐 Website: https://courseecho.com
|
|
261
|
+
- 📧 Support: support@courseecho.com
|
|
262
|
+
- 📱 Product: https://courseecho.com/products/ai-widget
|
|
263
|
+
|
|
264
|
+
## 📄 License
|
|
265
|
+
|
|
266
|
+
MIT © 2026 CourseEcho
|
|
267
|
+
|
|
268
|
+
## 📞 Support
|
|
269
|
+
|
|
270
|
+
- 📖 Docs: https://courseecho.com/docs
|
|
271
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/courseecho/ai-widget-sdk/issues)
|
|
272
|
+
- 💬 Chat: [Discord](https://discord.gg/courseecho)
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
**More integrations:**
|
|
277
|
+
- [Vue 3](../ai-widget-vue)
|
|
278
|
+
- [Angular 19+](../ai-widget-angular)
|
|
279
|
+
- [jQuery](../ai-widget-jquery)
|
|
280
|
+
- [Node.js](../ai-client-node)
|
|
281
|
+
- [Core SDK](../ai-core-sdk)
|
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
2
|
+
"name": "@courseecho/ai-widget-react",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "React component for AI chat widget. Use the SDK in any React app.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "CourseEcho",
|
|
7
|
+
"main": "dist/index.cjs",
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"dev": "tsc --watch",
|
|
23
|
+
"test": "jest",
|
|
24
|
+
"lint": "eslint src/**/*.ts*"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
28
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
29
|
+
"@courseecho/ai-core-sdk": "^1.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"react": "^18.2.0",
|
|
33
|
+
"react-dom": "^18.2.0",
|
|
34
|
+
"@courseecho/ai-core-sdk": "^1.0.0",
|
|
35
|
+
"typescript": "^5.3.0",
|
|
36
|
+
"@types/react": "^18.2.0",
|
|
37
|
+
"@types/react-dom": "^18.2.0",
|
|
38
|
+
"@types/node": "^20.0.0",
|
|
39
|
+
"jest": "^29.0.0",
|
|
40
|
+
"@types/jest": "^29.0.0",
|
|
41
|
+
"ts-jest": "^29.0.0",
|
|
42
|
+
"eslint": "^8.0.0",
|
|
43
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@courseecho/ai-core-sdk": "^1.0.0"
|
|
48
|
+
}
|
|
49
49
|
}
|