@courseecho/ai-core-sdk 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 +263 -0
- package/package.json +37 -37
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,263 @@
|
|
|
1
|
+
# 🤖 @courseecho/ai-core-sdk
|
|
2
|
+
|
|
3
|
+
**Framework-agnostic core AI chat SDK** - The foundation for all CourseEcho AI widgets.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@courseecho/ai-core-sdk)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
## 📖 Overview
|
|
9
|
+
|
|
10
|
+
This is the **core SDK** that powers all CourseEcho AI widgets. It handles:
|
|
11
|
+
- 🔄 State management (chat messages, context, charts)
|
|
12
|
+
- 🌐 HTTP communication with your AI backend
|
|
13
|
+
- 🔐 Authentication (JWT tokens, API keys)
|
|
14
|
+
- 📊 Data transformation and validation
|
|
15
|
+
|
|
16
|
+
**Perfect for:** React, Vue, Angular, Node.js, jQuery - build your own integrations!
|
|
17
|
+
|
|
18
|
+
## 🚀 Quick Start
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @courseecho/ai-core-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Basic Usage
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { AiWidgetSDK } from '@courseecho/ai-core-sdk';
|
|
30
|
+
|
|
31
|
+
const sdk = new AiWidgetSDK({
|
|
32
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
33
|
+
context: {
|
|
34
|
+
pageType: 'course',
|
|
35
|
+
entityId: 'course-123',
|
|
36
|
+
userId: 'user-456'
|
|
37
|
+
},
|
|
38
|
+
jwtToken: 'your-jwt-token'
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Send a message
|
|
42
|
+
const response = await sdk.sendQuery('What is this course about?');
|
|
43
|
+
console.log(response.answer);
|
|
44
|
+
|
|
45
|
+
// Listen to state changes
|
|
46
|
+
sdk.onStateChange((state) => {
|
|
47
|
+
console.log('Messages:', state.messages);
|
|
48
|
+
console.log('Loading:', state.loading);
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 📦 What's Included
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
dist/
|
|
56
|
+
├── index.mjs # ES Module (modern)
|
|
57
|
+
├── index.cjs # CommonJS (Node.js)
|
|
58
|
+
├── index.d.ts # TypeScript definitions
|
|
59
|
+
└── ...
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 🎯 Use Cases
|
|
63
|
+
|
|
64
|
+
### 1. React App
|
|
65
|
+
```bash
|
|
66
|
+
npm install @courseecho/ai-widget-react @courseecho/ai-core-sdk
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2. Vue 3 App
|
|
70
|
+
```bash
|
|
71
|
+
npm install @courseecho/ai-widget-vue @courseecho/ai-core-sdk
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. Angular 19+ App
|
|
75
|
+
```bash
|
|
76
|
+
npm install @courseecho/ai-widget-angular @courseecho/ai-core-sdk
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 4. Custom Implementation
|
|
80
|
+
```typescript
|
|
81
|
+
import { AiWidgetSDK, ChatMessage, ContextData } from '@courseecho/ai-core-sdk';
|
|
82
|
+
|
|
83
|
+
// Build your own UI with the core SDK
|
|
84
|
+
const sdk = new AiWidgetSDK({ /* config */ });
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 🔌 API Reference
|
|
88
|
+
|
|
89
|
+
### Constructor Options
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
interface AiWidgetConfig {
|
|
93
|
+
apiEndpoint: string; // Your API server URL
|
|
94
|
+
context: ContextData; // Page/entity context
|
|
95
|
+
jwtToken?: string; // Optional JWT token
|
|
96
|
+
apiKey?: string; // Optional API key
|
|
97
|
+
theme?: 'light' | 'dark'; // UI theme
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface ContextData {
|
|
101
|
+
pageType: string; // e.g., 'course', 'lesson'
|
|
102
|
+
entityId?: string; // e.g., 'course-123'
|
|
103
|
+
userId?: string; // User identifier
|
|
104
|
+
customData?: Record<string, any>;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Methods
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// Send a query
|
|
112
|
+
await sdk.sendQuery(message: string, context?: ContextData): Promise<ChatResponse>
|
|
113
|
+
|
|
114
|
+
// Send batch queries
|
|
115
|
+
await sdk.sendBatchQueries(messages: string[]): Promise<ChatResponse[]>
|
|
116
|
+
|
|
117
|
+
// Get current state
|
|
118
|
+
const state = sdk.getState(): AiWidgetState
|
|
119
|
+
|
|
120
|
+
// Update context
|
|
121
|
+
sdk.setContext(context: ContextData): void
|
|
122
|
+
|
|
123
|
+
// Listen to changes
|
|
124
|
+
sdk.onStateChange(callback: (state: AiWidgetState) => void): void
|
|
125
|
+
|
|
126
|
+
// Clear history
|
|
127
|
+
sdk.clearHistory(): void
|
|
128
|
+
|
|
129
|
+
// Destroy SDK
|
|
130
|
+
sdk.destroy(): void
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## 📊 State Management
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
interface AiWidgetState {
|
|
137
|
+
messages: ChatMessage[]; // All messages
|
|
138
|
+
loading: boolean; // Is loading?
|
|
139
|
+
error: string | null; // Error message
|
|
140
|
+
context: ContextData; // Current context
|
|
141
|
+
charts: ChartData[]; // Data visualizations
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface ChatMessage {
|
|
145
|
+
id: string;
|
|
146
|
+
content: string;
|
|
147
|
+
role: 'user' | 'assistant';
|
|
148
|
+
timestamp: Date;
|
|
149
|
+
metadata?: Record<string, any>;
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 🔐 Authentication
|
|
154
|
+
|
|
155
|
+
### JWT Token
|
|
156
|
+
```typescript
|
|
157
|
+
const sdk = new AiWidgetSDK({
|
|
158
|
+
apiEndpoint: 'https://api.example.com/api',
|
|
159
|
+
context: { pageType: 'course' },
|
|
160
|
+
jwtToken: 'eyJhbGciOiJIUzI1NiIs...'
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### API Key
|
|
165
|
+
```typescript
|
|
166
|
+
const sdk = new AiWidgetSDK({
|
|
167
|
+
apiEndpoint: 'https://api.example.com/api',
|
|
168
|
+
context: { pageType: 'course' },
|
|
169
|
+
apiKey: 'sk-123456789...'
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 🎨 Framework Integrations
|
|
174
|
+
|
|
175
|
+
| Framework | Package | Docs |
|
|
176
|
+
|-----------|---------|------|
|
|
177
|
+
| **React** | `@courseecho/ai-widget-react` | [React Docs](../ai-widget-react) |
|
|
178
|
+
| **Vue** | `@courseecho/ai-widget-vue` | [Vue Docs](../ai-widget-vue) |
|
|
179
|
+
| **Angular** | `@courseecho/ai-widget-angular` | [Angular Docs](../ai-widget-angular) |
|
|
180
|
+
| **Node.js** | `@courseecho/ai-client-node` | [Node.js Docs](../ai-client-node) |
|
|
181
|
+
| **jQuery** | `@courseecho/ai-widget-jquery` | [jQuery Docs](../ai-widget-jquery) |
|
|
182
|
+
|
|
183
|
+
## 📚 Examples
|
|
184
|
+
|
|
185
|
+
### Example 1: Custom Vue Composable
|
|
186
|
+
```typescript
|
|
187
|
+
import { AiWidgetSDK } from '@courseecho/ai-core-sdk';
|
|
188
|
+
import { ref } from 'vue';
|
|
189
|
+
|
|
190
|
+
export function useAiChat() {
|
|
191
|
+
const sdk = new AiWidgetSDK({
|
|
192
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
193
|
+
context: { pageType: 'course' }
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const messages = ref([]);
|
|
197
|
+
const loading = ref(false);
|
|
198
|
+
|
|
199
|
+
sdk.onStateChange((state) => {
|
|
200
|
+
messages.value = state.messages;
|
|
201
|
+
loading.value = state.loading;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
messages,
|
|
206
|
+
loading,
|
|
207
|
+
sendMessage: (msg: string) => sdk.sendQuery(msg)
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Example 2: Custom React Hook
|
|
213
|
+
```typescript
|
|
214
|
+
import { AiWidgetSDK } from '@courseecho/ai-core-sdk';
|
|
215
|
+
import { useState, useEffect } from 'react';
|
|
216
|
+
|
|
217
|
+
export function useAiChat() {
|
|
218
|
+
const [state, setState] = useState(null);
|
|
219
|
+
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
const sdk = new AiWidgetSDK({
|
|
222
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
223
|
+
context: { pageType: 'course' }
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
sdk.onStateChange(setState);
|
|
227
|
+
return () => sdk.destroy();
|
|
228
|
+
}, []);
|
|
229
|
+
|
|
230
|
+
return state;
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## 🌍 About CourseEcho
|
|
235
|
+
|
|
236
|
+
[CourseEcho](https://courseecho.com) is an AI-powered educational platform that provides intelligent tutoring and course assistance.
|
|
237
|
+
|
|
238
|
+
- 🌐 Website: https://courseecho.com
|
|
239
|
+
- 📧 Support: support@courseecho.com
|
|
240
|
+
- 📱 Product: https://courseecho.com/products/ai-widget
|
|
241
|
+
|
|
242
|
+
## 📄 License
|
|
243
|
+
|
|
244
|
+
MIT © 2026 CourseEcho
|
|
245
|
+
|
|
246
|
+
## 🤝 Contributing
|
|
247
|
+
|
|
248
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md)
|
|
249
|
+
|
|
250
|
+
## 📞 Support
|
|
251
|
+
|
|
252
|
+
- 📖 Documentation: https://courseecho.com/docs
|
|
253
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/courseecho/ai-widget-sdk/issues)
|
|
254
|
+
- 💬 Community: [Discord](https://discord.gg/courseecho)
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
**Other CourseEcho Packages:**
|
|
259
|
+
- [@courseecho/ai-widget-react](../ai-widget-react)
|
|
260
|
+
- [@courseecho/ai-widget-vue](../ai-widget-vue)
|
|
261
|
+
- [@courseecho/ai-widget-angular](../ai-widget-angular)
|
|
262
|
+
- [@courseecho/ai-widget-jquery](../ai-widget-jquery)
|
|
263
|
+
- [@courseecho/ai-client-node](../ai-client-node)
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
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
|
-
|
|
2
|
+
"name": "@courseecho/ai-core-sdk",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Framework-agnostic core AI chat SDK. Shared logic for all framework wrappers.",
|
|
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
|
+
"dependencies": {
|
|
27
|
+
"rxjs": "^7.8.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "^5.3.0",
|
|
31
|
+
"@types/node": "^20.0.0",
|
|
32
|
+
"jest": "^29.0.0",
|
|
33
|
+
"@types/jest": "^29.0.0",
|
|
34
|
+
"ts-jest": "^29.0.0",
|
|
35
|
+
"eslint": "^8.0.0",
|
|
36
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0"
|
|
38
|
+
}
|
|
39
39
|
}
|