@astermind/cybernetic-chatbot-client 1.0.6
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 +21 -0
- package/README.md +667 -0
- package/dist/ApiClient.d.ts +86 -0
- package/dist/ApiClient.d.ts.map +1 -0
- package/dist/CyberneticCache.d.ts +56 -0
- package/dist/CyberneticCache.d.ts.map +1 -0
- package/dist/CyberneticClient.d.ts +207 -0
- package/dist/CyberneticClient.d.ts.map +1 -0
- package/dist/CyberneticLocalRAG.d.ts +59 -0
- package/dist/CyberneticLocalRAG.d.ts.map +1 -0
- package/dist/agentic/CyberneticAgent.d.ts +111 -0
- package/dist/agentic/CyberneticAgent.d.ts.map +1 -0
- package/dist/agentic/CyberneticIntentClassifier.d.ts +78 -0
- package/dist/agentic/CyberneticIntentClassifier.d.ts.map +1 -0
- package/dist/agentic/index.d.ts +13 -0
- package/dist/agentic/index.d.ts.map +1 -0
- package/dist/agentic/register.d.ts +32 -0
- package/dist/agentic/register.d.ts.map +1 -0
- package/dist/agentic/tools/ClickTool.d.ts +41 -0
- package/dist/agentic/tools/ClickTool.d.ts.map +1 -0
- package/dist/agentic/tools/FillTool.d.ts +59 -0
- package/dist/agentic/tools/FillTool.d.ts.map +1 -0
- package/dist/agentic/tools/NavigateTool.d.ts +87 -0
- package/dist/agentic/tools/NavigateTool.d.ts.map +1 -0
- package/dist/agentic/tools/ScrollTool.d.ts +74 -0
- package/dist/agentic/tools/ScrollTool.d.ts.map +1 -0
- package/dist/agentic/tools/index.d.ts +9 -0
- package/dist/agentic/tools/index.d.ts.map +1 -0
- package/dist/agentic/types.d.ts +112 -0
- package/dist/agentic/types.d.ts.map +1 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/cybernetic-chatbot-client-full.esm.js +3271 -0
- package/dist/cybernetic-chatbot-client-full.esm.js.map +1 -0
- package/dist/cybernetic-chatbot-client-full.min.js +2 -0
- package/dist/cybernetic-chatbot-client-full.min.js.map +1 -0
- package/dist/cybernetic-chatbot-client-full.umd.js +3296 -0
- package/dist/cybernetic-chatbot-client-full.umd.js.map +1 -0
- package/dist/cybernetic-chatbot-client.esm.js +3265 -0
- package/dist/cybernetic-chatbot-client.esm.js.map +1 -0
- package/dist/cybernetic-chatbot-client.min.js +2 -0
- package/dist/cybernetic-chatbot-client.min.js.map +1 -0
- package/dist/cybernetic-chatbot-client.umd.js +3290 -0
- package/dist/cybernetic-chatbot-client.umd.js.map +1 -0
- package/dist/full.d.ts +15 -0
- package/dist/full.d.ts.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/license/base64url.d.ts +24 -0
- package/dist/license/base64url.d.ts.map +1 -0
- package/dist/license/index.d.ts +5 -0
- package/dist/license/index.d.ts.map +1 -0
- package/dist/license/licenseManager.d.ts +124 -0
- package/dist/license/licenseManager.d.ts.map +1 -0
- package/dist/license/types.d.ts +72 -0
- package/dist/license/types.d.ts.map +1 -0
- package/dist/license/verifier.d.ts +19 -0
- package/dist/license/verifier.d.ts.map +1 -0
- package/dist/types.d.ts +163 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AsterMind Team
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
# @astermind/cybernetic-chatbot-client
|
|
2
|
+
|
|
3
|
+
Offline-capable AI chatbot client with local RAG fallback and agentic capabilities for [AsterMind](https://astermind.ai).
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@astermind/cybernetic-chatbot-client)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
## What is Cybernetic Chatbot Client?
|
|
10
|
+
|
|
11
|
+
Cybernetic Chatbot Client is the official JavaScript SDK for integrating [AsterMind](https://astermind.ai) AI chatbot capabilities into your web applications. It provides a robust, offline-first architecture that ensures your users always get answers, even when disconnected from the server.
|
|
12
|
+
|
|
13
|
+
## Key Features
|
|
14
|
+
|
|
15
|
+
- **Offline-First Architecture** - IndexedDB caching with TF-IDF local search
|
|
16
|
+
- **SSE Streaming** - Real-time token-by-token responses
|
|
17
|
+
- **Session Management** - Multi-turn conversation continuity
|
|
18
|
+
- **Configurable Retry Logic** - Exponential backoff with customizable settings
|
|
19
|
+
- **Connection Status Monitoring** - Real-time online/offline detection
|
|
20
|
+
- **Maintenance Mode Support** - Graceful degradation per ADR-200
|
|
21
|
+
- **Agentic Capabilities** - Intent classification and DOM automation (full bundle)
|
|
22
|
+
- **Tree-Shakeable** - Import only what you need
|
|
23
|
+
|
|
24
|
+
## Table of Contents
|
|
25
|
+
|
|
26
|
+
- [Installation](#installation)
|
|
27
|
+
- [Quick Start](#quick-start)
|
|
28
|
+
- [Licensing](#licensing)
|
|
29
|
+
- [Configuration](#configuration)
|
|
30
|
+
- [Features](#features)
|
|
31
|
+
- [Offline-First Architecture](#offline-first-architecture)
|
|
32
|
+
- [Streaming Responses](#streaming-responses)
|
|
33
|
+
- [Session Management](#session-management)
|
|
34
|
+
- [Agentic Capabilities](#agentic-capabilities)
|
|
35
|
+
- [Maintenance Mode Support](#maintenance-mode-support)
|
|
36
|
+
- [Bundle Options](#bundle-options)
|
|
37
|
+
- [API Reference](#api-reference)
|
|
38
|
+
- [Browser Support](#browser-support)
|
|
39
|
+
- [Integration with Cybernetic Chatbot Backend](#integration-with-cybernetic-chatbot-backend)
|
|
40
|
+
- [License](#license)
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
### npm / yarn / pnpm
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install @astermind/cybernetic-chatbot-client
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
yarn add @astermind/cybernetic-chatbot-client
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pnpm add @astermind/cybernetic-chatbot-client
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### CDN (Script Tag)
|
|
59
|
+
|
|
60
|
+
```html
|
|
61
|
+
<!-- Core bundle -->
|
|
62
|
+
<script src="https://unpkg.com/@astermind/cybernetic-chatbot-client/dist/cybernetic-chatbot-client.umd.js"></script>
|
|
63
|
+
|
|
64
|
+
<!-- Or full bundle with agentic capabilities -->
|
|
65
|
+
<script src="https://unpkg.com/@astermind/cybernetic-chatbot-client/dist/cybernetic-chatbot-client-full.umd.js"></script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Quick Start
|
|
69
|
+
|
|
70
|
+
> **Note:** No license key is required for development. See [Licensing](#licensing) for production requirements.
|
|
71
|
+
|
|
72
|
+
### Basic Usage
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { CyberneticClient } from '@astermind/cybernetic-chatbot-client';
|
|
76
|
+
|
|
77
|
+
const client = new CyberneticClient({
|
|
78
|
+
apiUrl: 'https://api.astermind.ai',
|
|
79
|
+
apiKey: 'am_your_api_key',
|
|
80
|
+
// licenseKey: 'your-license-key', // Optional in development, required in production
|
|
81
|
+
fallback: {
|
|
82
|
+
enabled: true,
|
|
83
|
+
cacheOnConnect: true
|
|
84
|
+
},
|
|
85
|
+
onStatusChange: (status) => {
|
|
86
|
+
console.log('Connection status:', status);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Simple question
|
|
91
|
+
const response = await client.ask('What is AsterMind?');
|
|
92
|
+
console.log(response.reply);
|
|
93
|
+
|
|
94
|
+
// With streaming
|
|
95
|
+
await client.askStream('Tell me about RAG', {
|
|
96
|
+
onToken: (token) => process.stdout.write(token),
|
|
97
|
+
onSources: (sources) => console.log('Sources:', sources),
|
|
98
|
+
onComplete: (response) => console.log('\nDone:', response.sessionId)
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Script Tag Integration
|
|
103
|
+
|
|
104
|
+
```html
|
|
105
|
+
<script
|
|
106
|
+
src="https://unpkg.com/@astermind/cybernetic-chatbot-client/dist/cybernetic-chatbot-client.umd.js"
|
|
107
|
+
data-astermind-key="am_your_api_key"
|
|
108
|
+
data-astermind-url="https://api.astermind.ai"
|
|
109
|
+
></script>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Global Config Object
|
|
113
|
+
|
|
114
|
+
```html
|
|
115
|
+
<script>
|
|
116
|
+
window.astermindConfig = {
|
|
117
|
+
apiUrl: 'https://api.astermind.ai',
|
|
118
|
+
apiKey: 'am_your_api_key',
|
|
119
|
+
fallback: { enabled: true }
|
|
120
|
+
};
|
|
121
|
+
</script>
|
|
122
|
+
<script src="https://unpkg.com/@astermind/cybernetic-chatbot-client/dist/cybernetic-chatbot-client.umd.js"></script>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Licensing
|
|
126
|
+
|
|
127
|
+
**Free for Development** — This package is free to use during development and testing. No license key is required for local development environments.
|
|
128
|
+
|
|
129
|
+
**License Required for Production** — A valid license key is required for production deployments. Without a license, chatbot responses in production will include a visible license notice. Licenses are available at [https://astermind.ai](https://astermind.ai).
|
|
130
|
+
|
|
131
|
+
### License Products
|
|
132
|
+
|
|
133
|
+
| Product | Feature Flag | Included With |
|
|
134
|
+
|---------|--------------|---------------|
|
|
135
|
+
| **Cybernetic Chatbot Client** | `cybernetic-chatbot-client` | Cybernetic Chatbot purchase |
|
|
136
|
+
| **Agentic Add-On** | `agentic` | Separate Agentic Add-On purchase |
|
|
137
|
+
|
|
138
|
+
- **Cybernetic Chatbot**: Includes the `cybernetic-chatbot-client` feature, enabling all core client functionality (API communication, offline caching, streaming, session management).
|
|
139
|
+
- **Agentic Add-On**: Requires a separate purchase. Enables the `agentic` feature for intent classification and DOM automation capabilities.
|
|
140
|
+
|
|
141
|
+
### Applying Your License Key
|
|
142
|
+
|
|
143
|
+
Add your license key to the client configuration:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { CyberneticClient } from '@astermind/cybernetic-chatbot-client';
|
|
147
|
+
|
|
148
|
+
const client = new CyberneticClient({
|
|
149
|
+
apiUrl: 'https://api.astermind.ai',
|
|
150
|
+
apiKey: 'am_your_api_key',
|
|
151
|
+
licenseKey: 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9...' // Your license key (JWT)
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
For script tag integration:
|
|
156
|
+
|
|
157
|
+
```html
|
|
158
|
+
<script>
|
|
159
|
+
window.astermindConfig = {
|
|
160
|
+
apiUrl: 'https://api.astermind.ai',
|
|
161
|
+
apiKey: 'am_your_api_key',
|
|
162
|
+
licenseKey: 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
163
|
+
};
|
|
164
|
+
</script>
|
|
165
|
+
<script src="https://unpkg.com/@astermind/cybernetic-chatbot-client/dist/cybernetic-chatbot-client.umd.js"></script>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Enforcement Behavior
|
|
169
|
+
|
|
170
|
+
The license system uses environment-aware enforcement:
|
|
171
|
+
|
|
172
|
+
| Environment | Detection | License Required? | Behavior |
|
|
173
|
+
|-------------|-----------|-------------------|----------|
|
|
174
|
+
| **Development** | `localhost`, `127.0.0.1`, `.local`, `.dev`, dev ports (3000, 5173, 8080, etc.) | **No** | Free to use. Console warnings only. |
|
|
175
|
+
| **Production** | All other URLs | **Yes** | License warning appended to responses if missing/invalid. |
|
|
176
|
+
|
|
177
|
+
**Development Mode** (free, soft enforcement):
|
|
178
|
+
- **No license key required** — develop and test without any restrictions
|
|
179
|
+
- Console warnings are logged when license is missing, expired, or invalid (for awareness)
|
|
180
|
+
- Console warnings when using features not included in your license
|
|
181
|
+
- All functionality works normally — responses are returned unchanged
|
|
182
|
+
|
|
183
|
+
**Production Mode** (license required, hard enforcement):
|
|
184
|
+
- A valid license key is required for production use
|
|
185
|
+
- Without a valid license, chatbot responses include a visible notice:
|
|
186
|
+
|
|
187
|
+
*"⚠️ License Notice: Your AsterMind license key needs to be updated. Please contact support@astermind.ai or visit https://astermind.ai/license to renew your license."*
|
|
188
|
+
|
|
189
|
+
- With a valid license, responses are returned normally without any modifications
|
|
190
|
+
|
|
191
|
+
### Checking License Status
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
// Get current status including license state
|
|
195
|
+
const status = client.getStatus();
|
|
196
|
+
console.log(status.license);
|
|
197
|
+
// {
|
|
198
|
+
// status: 'valid' | 'invalid' | 'expired' | 'missing' | 'eval',
|
|
199
|
+
// payload: { plan, features, exp, ... },
|
|
200
|
+
// daysRemaining: 30,
|
|
201
|
+
// inGracePeriod: false
|
|
202
|
+
// }
|
|
203
|
+
|
|
204
|
+
// Get license manager for advanced operations
|
|
205
|
+
const license = client.getLicenseManager();
|
|
206
|
+
|
|
207
|
+
// Check if license is valid
|
|
208
|
+
license.isValid();
|
|
209
|
+
|
|
210
|
+
// Check specific features
|
|
211
|
+
license.hasFeature('cybernetic-chatbot-client');
|
|
212
|
+
license.hasFeature('agentic');
|
|
213
|
+
|
|
214
|
+
// Get human-readable status
|
|
215
|
+
license.getStatusMessage();
|
|
216
|
+
// "License valid (30 days remaining)"
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Feature Validation
|
|
220
|
+
|
|
221
|
+
The client automatically validates features:
|
|
222
|
+
|
|
223
|
+
- **Client feature** (`cybernetic-chatbot-client`): Checked on client initialization
|
|
224
|
+
- **Agentic feature** (`agentic`): Checked only when agentic capabilities are used
|
|
225
|
+
|
|
226
|
+
If a required feature is missing, the console displays:
|
|
227
|
+
- Current license plan
|
|
228
|
+
- Available features in your license
|
|
229
|
+
- The missing feature name
|
|
230
|
+
- Link to upgrade at https://astermind.ai/license
|
|
231
|
+
|
|
232
|
+
### Obtaining a License
|
|
233
|
+
|
|
234
|
+
1. Visit [https://astermind.ai](https://astermind.ai)
|
|
235
|
+
2. Purchase **Cybernetic Chatbot** for core client functionality
|
|
236
|
+
3. Optionally purchase the **Agentic Add-On** for DOM automation features
|
|
237
|
+
4. Your license key (JWT token) will be provided in your account dashboard
|
|
238
|
+
5. Add the license key to your client configuration
|
|
239
|
+
|
|
240
|
+
For licensing questions, contact support@astermind.ai.
|
|
241
|
+
|
|
242
|
+
## Configuration
|
|
243
|
+
|
|
244
|
+
### Full Configuration Interface
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
interface CyberneticConfig {
|
|
248
|
+
/** Backend API URL (required) */
|
|
249
|
+
apiUrl: string;
|
|
250
|
+
|
|
251
|
+
/** API key for authentication - must start with 'am_' (required) */
|
|
252
|
+
apiKey: string;
|
|
253
|
+
|
|
254
|
+
/** License key (JWT token) from https://astermind.ai */
|
|
255
|
+
licenseKey?: string;
|
|
256
|
+
|
|
257
|
+
/** Fallback/offline configuration */
|
|
258
|
+
fallback?: {
|
|
259
|
+
/** Enable offline fallback (default: true) */
|
|
260
|
+
enabled?: boolean;
|
|
261
|
+
|
|
262
|
+
/** Cache max age in milliseconds (default: 86400000 = 24 hours) */
|
|
263
|
+
cacheMaxAge?: number;
|
|
264
|
+
|
|
265
|
+
/** Sync documents on connect (default: true) */
|
|
266
|
+
cacheOnConnect?: boolean;
|
|
267
|
+
|
|
268
|
+
/** Storage type (default: 'indexeddb') */
|
|
269
|
+
cacheStorage?: 'indexeddb' | 'localstorage';
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/** Retry configuration */
|
|
273
|
+
retry?: {
|
|
274
|
+
/** Max retries before fallback (default: 2) */
|
|
275
|
+
maxRetries?: number;
|
|
276
|
+
|
|
277
|
+
/** Initial delay in ms (default: 1000) */
|
|
278
|
+
initialDelay?: number;
|
|
279
|
+
|
|
280
|
+
/** Use exponential backoff (default: true) */
|
|
281
|
+
exponentialBackoff?: boolean;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/** Event callbacks */
|
|
285
|
+
onStatusChange?: (status: ConnectionStatus) => void;
|
|
286
|
+
onError?: (error: CyberneticError) => void;
|
|
287
|
+
|
|
288
|
+
/** Agentic capabilities configuration (requires full bundle) */
|
|
289
|
+
agentic?: AgenticConfig;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
type ConnectionStatus = 'online' | 'offline' | 'connecting' | 'error';
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Agentic Configuration
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
interface AgenticConfig {
|
|
299
|
+
/** Enable agentic DOM interactions (default: false) */
|
|
300
|
+
enabled: boolean;
|
|
301
|
+
|
|
302
|
+
/** Confidence threshold for action execution (default: 0.8) */
|
|
303
|
+
confidenceThreshold?: number;
|
|
304
|
+
|
|
305
|
+
/** Allowed DOM actions */
|
|
306
|
+
allowedActions?: ('click' | 'fill' | 'scroll' | 'navigate' | 'select')[];
|
|
307
|
+
|
|
308
|
+
/** Require user confirmation before actions (default: true) */
|
|
309
|
+
requireConfirmation?: boolean;
|
|
310
|
+
|
|
311
|
+
/** Maximum actions per conversation turn (default: 5) */
|
|
312
|
+
maxActionsPerTurn?: number;
|
|
313
|
+
|
|
314
|
+
/** CSS selectors to never interact with */
|
|
315
|
+
blockedSelectors?: string[];
|
|
316
|
+
|
|
317
|
+
/** Only allow actions within these selectors */
|
|
318
|
+
allowedSelectors?: string[];
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Features
|
|
323
|
+
|
|
324
|
+
### Offline-First Architecture
|
|
325
|
+
|
|
326
|
+
The client uses IndexedDB for local caching and TF-IDF for similarity search, enabling offline functionality:
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
const client = new CyberneticClient({
|
|
330
|
+
apiUrl: 'https://api.astermind.ai',
|
|
331
|
+
apiKey: 'am_your_api_key',
|
|
332
|
+
fallback: {
|
|
333
|
+
enabled: true,
|
|
334
|
+
cacheOnConnect: true, // Cache responses for offline use
|
|
335
|
+
cacheMaxAge: 86400000, // 24 hours
|
|
336
|
+
cacheStorage: 'indexeddb'
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
// Check connection status
|
|
341
|
+
const status = client.getStatus();
|
|
342
|
+
console.log(status.connection); // 'online' | 'offline' | 'connecting'
|
|
343
|
+
console.log(status.cache); // { documentCount, lastSyncAt, cacheSize, isStale }
|
|
344
|
+
|
|
345
|
+
// Response includes offline indicator
|
|
346
|
+
const response = await client.ask('cached question');
|
|
347
|
+
if (response.offline) {
|
|
348
|
+
console.log('Response from local cache');
|
|
349
|
+
console.log('Confidence:', response.confidence); // 'medium' or 'low' when offline
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Manually sync cache
|
|
353
|
+
await client.syncCache();
|
|
354
|
+
|
|
355
|
+
// Clear cache
|
|
356
|
+
await client.clearCache();
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
**Cache Validation**: The server controls cache retention via `cacheRetentionHours` (default: 168 hours / 7 days). The client respects this setting and marks responses as stale when appropriate.
|
|
360
|
+
|
|
361
|
+
### Streaming Responses
|
|
362
|
+
|
|
363
|
+
Real-time token streaming via Server-Sent Events (SSE):
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
await client.askStream('Explain quantum computing', {
|
|
367
|
+
onToken: (token) => {
|
|
368
|
+
// Called for each token as it arrives
|
|
369
|
+
document.getElementById('output').textContent += token;
|
|
370
|
+
},
|
|
371
|
+
onSources: (sources) => {
|
|
372
|
+
// Called when sources are available
|
|
373
|
+
console.log('Sources:', sources);
|
|
374
|
+
},
|
|
375
|
+
onComplete: (response) => {
|
|
376
|
+
// Called when streaming is complete
|
|
377
|
+
console.log('Session ID:', response.sessionId);
|
|
378
|
+
},
|
|
379
|
+
onError: (error) => {
|
|
380
|
+
// Called on error
|
|
381
|
+
console.error('Error:', error.message);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### Session Management
|
|
387
|
+
|
|
388
|
+
Maintain conversation context across multiple turns:
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
// First message establishes session
|
|
392
|
+
const response1 = await client.ask('Hello!');
|
|
393
|
+
const sessionId = response1.sessionId;
|
|
394
|
+
|
|
395
|
+
// Continue conversation with session ID
|
|
396
|
+
const response2 = await client.ask('Tell me more', { sessionId });
|
|
397
|
+
const response3 = await client.ask('Can you clarify?', { sessionId });
|
|
398
|
+
|
|
399
|
+
// Optionally pass page context
|
|
400
|
+
const response = await client.ask('Help me with this page', {
|
|
401
|
+
sessionId,
|
|
402
|
+
context: {
|
|
403
|
+
currentPage: '/products/widget',
|
|
404
|
+
pageTitle: 'Widget Product Page'
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Agentic Capabilities
|
|
410
|
+
|
|
411
|
+
The full bundle includes intent classification and DOM automation:
|
|
412
|
+
|
|
413
|
+
```typescript
|
|
414
|
+
import {
|
|
415
|
+
CyberneticClient,
|
|
416
|
+
CyberneticAgent,
|
|
417
|
+
CyberneticIntentClassifier
|
|
418
|
+
} from '@astermind/cybernetic-chatbot-client/full';
|
|
419
|
+
|
|
420
|
+
const client = new CyberneticClient({
|
|
421
|
+
apiUrl: 'https://api.astermind.ai',
|
|
422
|
+
apiKey: 'am_your_api_key',
|
|
423
|
+
agentic: {
|
|
424
|
+
enabled: true,
|
|
425
|
+
confidenceThreshold: 0.8,
|
|
426
|
+
requireConfirmation: true,
|
|
427
|
+
allowedActions: ['click', 'fill', 'navigate', 'scroll'],
|
|
428
|
+
blockedSelectors: ['.admin-panel', '#dangerous-button'],
|
|
429
|
+
maxActionsPerTurn: 5
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Smart ask - checks for action intent first, then falls back to RAG
|
|
434
|
+
const result = await client.smartAsk('Take me to the settings page');
|
|
435
|
+
|
|
436
|
+
if (result.action) {
|
|
437
|
+
// Action detected
|
|
438
|
+
console.log('Action:', result.action.type, result.action.target);
|
|
439
|
+
console.log('Confidence:', result.action.confidence);
|
|
440
|
+
|
|
441
|
+
// If requireConfirmation is true, action is returned but not executed
|
|
442
|
+
// Your UI can show a confirmation dialog, then execute:
|
|
443
|
+
if (userConfirmed) {
|
|
444
|
+
const actionResult = await client.executeAction(result.action);
|
|
445
|
+
console.log('Result:', actionResult.message);
|
|
446
|
+
}
|
|
447
|
+
} else if (result.response) {
|
|
448
|
+
// Standard RAG response
|
|
449
|
+
console.log('Reply:', result.response.reply);
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
#### Supported Action Types
|
|
454
|
+
|
|
455
|
+
| Action | Description | Example Phrases |
|
|
456
|
+
|--------|-------------|-----------------|
|
|
457
|
+
| `navigate` | Navigate to URL/route | "go to settings", "take me to dashboard" |
|
|
458
|
+
| `fillForm` | Fill form input fields | "search for products", "enter my email" |
|
|
459
|
+
| `clickElement` | Click buttons/links | "click submit", "press the save button" |
|
|
460
|
+
| `scroll` | Scroll to element/position | "scroll to top", "jump to pricing section" |
|
|
461
|
+
| `highlight` | Highlight elements | "show me the login button" |
|
|
462
|
+
| `triggerModal` | Open modal dialogs | "open help modal", "show settings dialog" |
|
|
463
|
+
| `custom` | Custom action handlers | "export data", "refresh dashboard" |
|
|
464
|
+
|
|
465
|
+
#### Intent Classification
|
|
466
|
+
|
|
467
|
+
The classifier uses a hybrid approach with regex patterns and Jaccard similarity for fuzzy matching:
|
|
468
|
+
|
|
469
|
+
```typescript
|
|
470
|
+
import { CyberneticIntentClassifier } from '@astermind/cybernetic-chatbot-client/full';
|
|
471
|
+
|
|
472
|
+
const classifier = new CyberneticIntentClassifier({
|
|
473
|
+
enabled: true,
|
|
474
|
+
confidenceThreshold: 0.8,
|
|
475
|
+
siteMap: [
|
|
476
|
+
{ path: '/settings', name: 'Settings', aliases: ['preferences', 'config'] },
|
|
477
|
+
{ path: '/dashboard', name: 'Dashboard', aliases: ['home', 'main'] }
|
|
478
|
+
]
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
const intent = classifier.classify('take me to the settings page');
|
|
482
|
+
// { action: { type: 'navigate', target: '/settings', confidence: 0.92 }, ... }
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
#### Security Features
|
|
486
|
+
|
|
487
|
+
- **Selector Sanitization**: Removes potentially dangerous characters from CSS selectors
|
|
488
|
+
- **URL Validation**: Blocks `javascript:` and `data:` URLs
|
|
489
|
+
- **Blocked Selectors**: Configure selectors that should never be interacted with
|
|
490
|
+
- **Allowed Selectors**: Optionally whitelist specific selectors
|
|
491
|
+
- **Rate Limiting**: Maximum actions per minute (default: 5)
|
|
492
|
+
- **Confirmation Flow**: Optional user approval before action execution
|
|
493
|
+
|
|
494
|
+
### Maintenance Mode Support
|
|
495
|
+
|
|
496
|
+
The client handles backend maintenance mode gracefully (per ADR-200):
|
|
497
|
+
|
|
498
|
+
```typescript
|
|
499
|
+
// Check if maintenance mode is active
|
|
500
|
+
if (client.isMaintenanceMode()) {
|
|
501
|
+
const message = client.getMaintenanceMessage();
|
|
502
|
+
console.log('Maintenance:', message);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// Get full system status
|
|
506
|
+
const status = client.getStatus();
|
|
507
|
+
console.log(status.systemSettings);
|
|
508
|
+
// {
|
|
509
|
+
// maintenanceMode: boolean,
|
|
510
|
+
// maintenanceMessage?: string,
|
|
511
|
+
// cacheRetentionHours: number,
|
|
512
|
+
// forceOfflineClients: boolean
|
|
513
|
+
// }
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
When maintenance mode is active:
|
|
517
|
+
- The client automatically uses cached data
|
|
518
|
+
- New requests are served from local RAG
|
|
519
|
+
- `response.offline` will be `true`
|
|
520
|
+
- `response.degradedReason` will indicate maintenance mode
|
|
521
|
+
|
|
522
|
+
## Bundle Options
|
|
523
|
+
|
|
524
|
+
| Entry Point | Import Path | Description | Size (minified) |
|
|
525
|
+
|-------------|-------------|-------------|-----------------|
|
|
526
|
+
| Core | `@astermind/cybernetic-chatbot-client` | Client, caching, local RAG | ~15KB |
|
|
527
|
+
| Full | `@astermind/cybernetic-chatbot-client/full` | Core + agentic capabilities | ~25KB |
|
|
528
|
+
|
|
529
|
+
### Tree-Shakeable Imports
|
|
530
|
+
|
|
531
|
+
```typescript
|
|
532
|
+
// Import only core client (smaller bundle)
|
|
533
|
+
import { CyberneticClient } from '@astermind/cybernetic-chatbot-client';
|
|
534
|
+
|
|
535
|
+
// Import agentic features when needed
|
|
536
|
+
import {
|
|
537
|
+
CyberneticClient,
|
|
538
|
+
CyberneticAgent,
|
|
539
|
+
CyberneticIntentClassifier
|
|
540
|
+
} from '@astermind/cybernetic-chatbot-client/full';
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
## API Reference
|
|
544
|
+
|
|
545
|
+
### CyberneticClient
|
|
546
|
+
|
|
547
|
+
```typescript
|
|
548
|
+
class CyberneticClient {
|
|
549
|
+
constructor(config: CyberneticConfig);
|
|
550
|
+
|
|
551
|
+
// Core methods
|
|
552
|
+
ask(message: string, options?: AskOptions): Promise<CyberneticResponse>;
|
|
553
|
+
askStream(message: string, callbacks: StreamCallbacks, options?: AskOptions): Promise<void>;
|
|
554
|
+
|
|
555
|
+
// Agentic methods (requires agentic config and license)
|
|
556
|
+
smartAsk(message: string, options?: AskOptions): Promise<SmartAskResult>;
|
|
557
|
+
classifyIntent(message: string): IntentClassification | null;
|
|
558
|
+
executeAction(action: AgentAction): Promise<ActionResult>;
|
|
559
|
+
isAgenticEnabled(): boolean;
|
|
560
|
+
|
|
561
|
+
// Status methods (includes license state)
|
|
562
|
+
getStatus(): { connection: ConnectionStatus; cache: CacheStatus; lastError: CyberneticError | null; systemSettings: SystemSettings | null; license: LicenseState | null };
|
|
563
|
+
checkConnection(): Promise<boolean>;
|
|
564
|
+
checkSystemStatus(): Promise<SystemSettings>;
|
|
565
|
+
isMaintenanceMode(): boolean;
|
|
566
|
+
getMaintenanceMessage(): string | undefined;
|
|
567
|
+
isCacheValid(): boolean;
|
|
568
|
+
|
|
569
|
+
// License methods
|
|
570
|
+
getLicenseManager(): LicenseManager;
|
|
571
|
+
|
|
572
|
+
// Cache methods
|
|
573
|
+
syncCache(): Promise<void>;
|
|
574
|
+
clearCache(): Promise<void>;
|
|
575
|
+
}
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
### Response Types
|
|
579
|
+
|
|
580
|
+
```typescript
|
|
581
|
+
interface CyberneticResponse {
|
|
582
|
+
reply: string;
|
|
583
|
+
confidence: 'high' | 'medium' | 'low' | 'none';
|
|
584
|
+
sources: Source[];
|
|
585
|
+
offline: boolean;
|
|
586
|
+
sessionId?: string;
|
|
587
|
+
retryAfter?: number;
|
|
588
|
+
degradedReason?: string;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
interface Source {
|
|
592
|
+
title: string;
|
|
593
|
+
snippet: string;
|
|
594
|
+
relevance: number;
|
|
595
|
+
documentId?: string;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
interface StreamCallbacks {
|
|
599
|
+
onToken?: (token: string) => void;
|
|
600
|
+
onSources?: (sources: Source[]) => void;
|
|
601
|
+
onComplete?: (response: CyberneticResponse) => void;
|
|
602
|
+
onError?: (error: CyberneticError) => void;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
interface CyberneticError {
|
|
606
|
+
code: 'NETWORK_ERROR' | 'AUTH_ERROR' | 'RATE_LIMIT' | 'SERVER_ERROR' | 'CACHE_ERROR' | 'LOCAL_RAG_ERROR';
|
|
607
|
+
message: string;
|
|
608
|
+
retryAfter?: number;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
interface LicenseState {
|
|
612
|
+
status: 'valid' | 'invalid' | 'expired' | 'missing' | 'eval';
|
|
613
|
+
payload: LicensePayload | null;
|
|
614
|
+
error?: string;
|
|
615
|
+
inGracePeriod: boolean;
|
|
616
|
+
daysRemaining: number | null;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
interface LicensePayload {
|
|
620
|
+
iss: string; // Issuer
|
|
621
|
+
sub: string; // Subject (license ID)
|
|
622
|
+
aud: string; // Audience (product)
|
|
623
|
+
iat: number; // Issued at
|
|
624
|
+
exp: number; // Expiration
|
|
625
|
+
plan: 'free' | 'pro' | 'business' | 'enterprise' | 'eval';
|
|
626
|
+
org?: string; // Organization
|
|
627
|
+
seats: number; // Number of seats
|
|
628
|
+
features: string[]; // Enabled features
|
|
629
|
+
graceUntil?: number; // Grace period end
|
|
630
|
+
licenseVersion: number;
|
|
631
|
+
}
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
## Browser Support
|
|
635
|
+
|
|
636
|
+
| Browser | Version | Notes |
|
|
637
|
+
|---------|---------|-------|
|
|
638
|
+
| Chrome | 80+ | Full support |
|
|
639
|
+
| Firefox | 75+ | Full support |
|
|
640
|
+
| Safari | 13.1+ | Full support |
|
|
641
|
+
| Edge | 80+ | Full support |
|
|
642
|
+
|
|
643
|
+
Requires IndexedDB support for offline caching.
|
|
644
|
+
|
|
645
|
+
## Integration with Cybernetic Chatbot Backend
|
|
646
|
+
|
|
647
|
+
This client is designed to work with the AsterMind Cybernetic Chatbot backend. The following endpoints are used:
|
|
648
|
+
|
|
649
|
+
| Endpoint | Method | Description |
|
|
650
|
+
|----------|--------|-------------|
|
|
651
|
+
| `/api/external/chat` | POST | Send message, get complete response |
|
|
652
|
+
| `/api/external/chat/stream` | POST | Send message, get SSE streaming response |
|
|
653
|
+
| `/api/external/docs` | GET | Fetch documents for offline caching |
|
|
654
|
+
| `/api/external/status` | GET | Check API status, quota, and system settings |
|
|
655
|
+
| `/api/external/health` | GET | Health check (no auth required) |
|
|
656
|
+
|
|
657
|
+
**Authentication**: All authenticated endpoints require an `X-API-Key` header with a valid API key (prefixed with `am_`).
|
|
658
|
+
|
|
659
|
+
**Rate Limiting**: The backend enforces rate limits. The client handles 429 responses gracefully and includes `retryAfter` in responses when applicable.
|
|
660
|
+
|
|
661
|
+
## Links
|
|
662
|
+
|
|
663
|
+
- [AsterMind Website](https://astermind.ai)
|
|
664
|
+
|
|
665
|
+
## License
|
|
666
|
+
|
|
667
|
+
MIT License - see [LICENSE](LICENSE) for details.
|