@astermind/cybernetic-chatbot-client 2.2.74 → 2.3.4
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/dist/CyberneticClient.d.ts +54 -1
- package/dist/CyberneticClient.d.ts.map +1 -1
- package/dist/SalesApiClient.d.ts +64 -0
- package/dist/SalesApiClient.d.ts.map +1 -0
- package/dist/cybernetic-chatbot-client-full.esm.js +177 -32
- package/dist/cybernetic-chatbot-client-full.esm.js.map +1 -1
- package/dist/cybernetic-chatbot-client-full.min.js +1 -1
- package/dist/cybernetic-chatbot-client-full.min.js.map +1 -1
- package/dist/cybernetic-chatbot-client-full.umd.js +177 -32
- package/dist/cybernetic-chatbot-client-full.umd.js.map +1 -1
- package/dist/cybernetic-chatbot-client.esm.js +178 -33
- package/dist/cybernetic-chatbot-client.esm.js.map +1 -1
- package/dist/cybernetic-chatbot-client.min.js +1 -1
- package/dist/cybernetic-chatbot-client.min.js.map +1 -1
- package/dist/cybernetic-chatbot-client.umd.js +178 -32
- package/dist/cybernetic-chatbot-client.umd.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/license/licenseManager.d.ts +3 -5
- package/dist/license/licenseManager.d.ts.map +1 -1
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -214,6 +214,89 @@ class ApiClient {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
// src/SalesApiClient.ts
|
|
218
|
+
// API client for Sales Agent external endpoints (/api/external/sales/*)
|
|
219
|
+
/**
|
|
220
|
+
* Client for the Sales Agent external API endpoints.
|
|
221
|
+
* Handles visitor tracking, sales-aware chat, and lead capture.
|
|
222
|
+
*/
|
|
223
|
+
class SalesApiClient {
|
|
224
|
+
constructor(apiUrl, apiKey) {
|
|
225
|
+
// Normalize base URL (strip trailing slash)
|
|
226
|
+
this.baseUrl = apiUrl.replace(/\/$/, '');
|
|
227
|
+
this.apiKey = apiKey;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Initialize or resume a visitor session.
|
|
231
|
+
* Call on first page load to register the visitor with the backend.
|
|
232
|
+
*/
|
|
233
|
+
async initVisitor(visitorId, pageUrl, referrer, utmParams) {
|
|
234
|
+
return this.post('visitor/init', {
|
|
235
|
+
visitorId,
|
|
236
|
+
pageUrl,
|
|
237
|
+
referrer,
|
|
238
|
+
utmParams,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Track a page view event.
|
|
243
|
+
* Call when the visitor navigates to a new page.
|
|
244
|
+
*/
|
|
245
|
+
async trackPageView(visitorId, url, title, timeOnPageMs, scrollDepth) {
|
|
246
|
+
return this.post('visitor/pageview', {
|
|
247
|
+
visitorId,
|
|
248
|
+
url,
|
|
249
|
+
title,
|
|
250
|
+
timeOnPageMs,
|
|
251
|
+
scrollDepth,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Associate a visitor with identity data (email, name, etc.).
|
|
256
|
+
* Call when the visitor provides identifying information.
|
|
257
|
+
*/
|
|
258
|
+
async identifyVisitor(visitorId, data) {
|
|
259
|
+
return this.post('visitor/identify', {
|
|
260
|
+
visitorId,
|
|
261
|
+
...data,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Send a sales-aware chat message.
|
|
266
|
+
* Returns the assistant reply along with sales context (lead score, CTA buttons, etc.).
|
|
267
|
+
*/
|
|
268
|
+
async salesChat(message, options = {}) {
|
|
269
|
+
return this.post('chat', {
|
|
270
|
+
message,
|
|
271
|
+
...options,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Submit a lead capture form.
|
|
276
|
+
* Creates or updates a lead record in the backend.
|
|
277
|
+
*/
|
|
278
|
+
async captureLeadForm(data) {
|
|
279
|
+
return this.post('lead/capture', data);
|
|
280
|
+
}
|
|
281
|
+
// ─── Private ─────────────────────────────────────────────────────────────────
|
|
282
|
+
async post(path, body) {
|
|
283
|
+
const url = `${this.baseUrl}/api/external/sales/${path}`;
|
|
284
|
+
const response = await fetch(url, {
|
|
285
|
+
method: 'POST',
|
|
286
|
+
headers: {
|
|
287
|
+
'Content-Type': 'application/json',
|
|
288
|
+
'X-Api-Key': this.apiKey,
|
|
289
|
+
},
|
|
290
|
+
body: JSON.stringify(body),
|
|
291
|
+
});
|
|
292
|
+
if (!response.ok) {
|
|
293
|
+
const err = await response.json().catch(() => ({ error: 'Unknown error' }));
|
|
294
|
+
throw new Error(err.error || `Sales API error: ${response.status}`);
|
|
295
|
+
}
|
|
296
|
+
return response.json();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
217
300
|
const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
|
|
218
301
|
|
|
219
302
|
let idbProxyableTypes;
|
|
@@ -2184,8 +2267,10 @@ const REQUIRED_FEATURES = {
|
|
|
2184
2267
|
/**
|
|
2185
2268
|
* License enforcement message shown in production when license is invalid
|
|
2186
2269
|
*/
|
|
2187
|
-
|
|
2188
|
-
|
|
2270
|
+
// TODO: Re-enable when license key system is fully implemented
|
|
2271
|
+
// const LICENSE_WARNING_MESSAGE =
|
|
2272
|
+
// '\n\n---\n⚠️ License Notice: Your AsterMind license key needs to be updated. ' +
|
|
2273
|
+
// 'Please contact support@astermind.ai or visit https://astermind.ai/license to renew your license.';
|
|
2189
2274
|
/**
|
|
2190
2275
|
* Detect current environment based on URL and other signals
|
|
2191
2276
|
*/
|
|
@@ -2253,7 +2338,8 @@ class LicenseManager {
|
|
|
2253
2338
|
constructor(config = {}) {
|
|
2254
2339
|
this.state = null;
|
|
2255
2340
|
this.verificationPromise = null;
|
|
2256
|
-
|
|
2341
|
+
// TODO: Re-enable when license key system is fully implemented
|
|
2342
|
+
// private hasLoggedWarning = false;
|
|
2257
2343
|
this.loggedMissingFeatures = new Set();
|
|
2258
2344
|
this.config = config;
|
|
2259
2345
|
this.environment = config.environment || detectEnvironment();
|
|
@@ -2330,25 +2416,30 @@ class LicenseManager {
|
|
|
2330
2416
|
* @returns Modified response (or original if license valid)
|
|
2331
2417
|
*/
|
|
2332
2418
|
processResponse(response) {
|
|
2333
|
-
// License
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
//
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
//
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
//
|
|
2351
|
-
|
|
2419
|
+
// TODO: License enforcement disabled until license key system is fully implemented
|
|
2420
|
+
return response;
|
|
2421
|
+
// // License not verified yet - allow through
|
|
2422
|
+
// if (!this.state) {
|
|
2423
|
+
// return response;
|
|
2424
|
+
// }
|
|
2425
|
+
//
|
|
2426
|
+
// // Valid license - no modification
|
|
2427
|
+
// if (this.isValid() && !this.state.inGracePeriod) {
|
|
2428
|
+
// return response;
|
|
2429
|
+
// }
|
|
2430
|
+
//
|
|
2431
|
+
// // Handle based on enforcement mode
|
|
2432
|
+
// if (this.enforcementMode === 'soft') {
|
|
2433
|
+
// // Development: just log warning (once)
|
|
2434
|
+
// if (!this.hasLoggedWarning) {
|
|
2435
|
+
// this.logDevelopmentWarning();
|
|
2436
|
+
// this.hasLoggedWarning = true;
|
|
2437
|
+
// }
|
|
2438
|
+
// return response;
|
|
2439
|
+
// }
|
|
2440
|
+
//
|
|
2441
|
+
// // Production: append warning to response
|
|
2442
|
+
// return response + LICENSE_WARNING_MESSAGE;
|
|
2352
2443
|
}
|
|
2353
2444
|
/**
|
|
2354
2445
|
* Get a human-readable license status message
|
|
@@ -2380,7 +2471,7 @@ class LicenseManager {
|
|
|
2380
2471
|
*/
|
|
2381
2472
|
async reVerify() {
|
|
2382
2473
|
this.state = null;
|
|
2383
|
-
this.hasLoggedWarning = false;
|
|
2474
|
+
// this.hasLoggedWarning = false;
|
|
2384
2475
|
this.loggedMissingFeatures.clear();
|
|
2385
2476
|
return this.verify();
|
|
2386
2477
|
}
|
|
@@ -2485,15 +2576,6 @@ class LicenseManager {
|
|
|
2485
2576
|
break;
|
|
2486
2577
|
}
|
|
2487
2578
|
}
|
|
2488
|
-
/**
|
|
2489
|
-
* Log development-only warning
|
|
2490
|
-
*/
|
|
2491
|
-
logDevelopmentWarning() {
|
|
2492
|
-
console.warn('[Cybernetic License] Running in development mode with ' +
|
|
2493
|
-
`${this.state?.status || 'unknown'} license. ` +
|
|
2494
|
-
'In production, a warning will be appended to chatbot responses. ' +
|
|
2495
|
-
'Get a license at https://astermind.ai/license');
|
|
2496
|
-
}
|
|
2497
2579
|
}
|
|
2498
2580
|
/**
|
|
2499
2581
|
* Create a pre-configured license manager and verify immediately
|
|
@@ -2527,6 +2609,8 @@ class CyberneticClient {
|
|
|
2527
2609
|
this.offlineStorage = null;
|
|
2528
2610
|
// Omega RAG (optional, loaded dynamically)
|
|
2529
2611
|
this.omegaRAG = null;
|
|
2612
|
+
// Sales API client (optional, enabled via salesMode config)
|
|
2613
|
+
this.salesClient = null;
|
|
2530
2614
|
// Track if offline warning has been shown
|
|
2531
2615
|
this.offlineWarningShown = false;
|
|
2532
2616
|
// Resolve WebSocket URL (explicit → env → auto-derived from apiUrl)
|
|
@@ -2596,6 +2680,10 @@ class CyberneticClient {
|
|
|
2596
2680
|
// Silent failure on init - cache may be stale but usable
|
|
2597
2681
|
});
|
|
2598
2682
|
}
|
|
2683
|
+
// Initialize sales client if configured
|
|
2684
|
+
if (config.salesMode?.enabled) {
|
|
2685
|
+
this.salesClient = new SalesApiClient(config.apiUrl, config.apiKey);
|
|
2686
|
+
}
|
|
2599
2687
|
// Initialize offline vector support if configured
|
|
2600
2688
|
if (this.config.offline?.enabled) {
|
|
2601
2689
|
this.initializeOffline(this.config.offline).catch((error) => {
|
|
@@ -2910,6 +2998,63 @@ class CyberneticClient {
|
|
|
2910
2998
|
startNewSession(sessionId) {
|
|
2911
2999
|
this.sessionStorage.startNewSession(sessionId);
|
|
2912
3000
|
}
|
|
3001
|
+
// ==================== SALES API METHODS ====================
|
|
3002
|
+
/**
|
|
3003
|
+
* Check if sales mode is enabled
|
|
3004
|
+
*/
|
|
3005
|
+
isSalesModeEnabled() {
|
|
3006
|
+
return this.salesClient !== null;
|
|
3007
|
+
}
|
|
3008
|
+
/**
|
|
3009
|
+
* Get the sales API client for direct access
|
|
3010
|
+
*/
|
|
3011
|
+
getSalesClient() {
|
|
3012
|
+
return this.salesClient;
|
|
3013
|
+
}
|
|
3014
|
+
/**
|
|
3015
|
+
* Send a sales-aware chat message.
|
|
3016
|
+
* Returns the assistant reply with sales context (lead score, CTA buttons, etc.).
|
|
3017
|
+
* Requires salesMode to be enabled in config.
|
|
3018
|
+
*/
|
|
3019
|
+
async salesChat(message, options = {}) {
|
|
3020
|
+
if (!this.salesClient) {
|
|
3021
|
+
throw new Error('Sales mode is not enabled. Set salesMode.enabled = true in config.');
|
|
3022
|
+
}
|
|
3023
|
+
return this.salesClient.salesChat(message, options);
|
|
3024
|
+
}
|
|
3025
|
+
/**
|
|
3026
|
+
* Initialize or resume a visitor session.
|
|
3027
|
+
* Call on first page load to register the visitor with the backend.
|
|
3028
|
+
* Requires salesMode to be enabled in config.
|
|
3029
|
+
*/
|
|
3030
|
+
async initVisitor(visitorId, pageUrl, referrer, utmParams) {
|
|
3031
|
+
if (!this.salesClient) {
|
|
3032
|
+
throw new Error('Sales mode is not enabled. Set salesMode.enabled = true in config.');
|
|
3033
|
+
}
|
|
3034
|
+
return this.salesClient.initVisitor(visitorId, pageUrl, referrer, utmParams);
|
|
3035
|
+
}
|
|
3036
|
+
/**
|
|
3037
|
+
* Track a page view event for a visitor.
|
|
3038
|
+
* Call when the visitor navigates to a new page.
|
|
3039
|
+
* Requires salesMode to be enabled in config.
|
|
3040
|
+
*/
|
|
3041
|
+
async trackPageView(visitorId, url, title, timeOnPageMs, scrollDepth) {
|
|
3042
|
+
if (!this.salesClient) {
|
|
3043
|
+
throw new Error('Sales mode is not enabled. Set salesMode.enabled = true in config.');
|
|
3044
|
+
}
|
|
3045
|
+
return this.salesClient.trackPageView(visitorId, url, title, timeOnPageMs, scrollDepth);
|
|
3046
|
+
}
|
|
3047
|
+
/**
|
|
3048
|
+
* Submit a lead capture form.
|
|
3049
|
+
* Creates or updates a lead record in the backend.
|
|
3050
|
+
* Requires salesMode to be enabled in config.
|
|
3051
|
+
*/
|
|
3052
|
+
async captureLeadForm(data) {
|
|
3053
|
+
if (!this.salesClient) {
|
|
3054
|
+
throw new Error('Sales mode is not enabled. Set salesMode.enabled = true in config.');
|
|
3055
|
+
}
|
|
3056
|
+
return this.salesClient.captureLeadForm(data);
|
|
3057
|
+
}
|
|
2913
3058
|
// ==================== CORE METHODS ====================
|
|
2914
3059
|
/**
|
|
2915
3060
|
* Send a message to the chatbot
|
|
@@ -7470,5 +7615,5 @@ function createClient(config) {
|
|
|
7470
7615
|
return new CyberneticClient(config);
|
|
7471
7616
|
}
|
|
7472
7617
|
|
|
7473
|
-
export { ApiClient, CyberneticAgent, CyberneticCache, CyberneticClient, CyberneticIntentClassifier, CyberneticLocalRAG, CyberneticOfflineStorage, CyberneticSessionStorage, LicenseManager, OmegaOfflineRAG, REQUIRED_FEATURES, SiteMapDiscovery, WebSocketTransport, configLoaders, createClient, createDiscoveryConfig, createLicenseManager, deriveWsUrl, detectEnvironment, getEnforcementMode, getTokenExpiration, isValidJWTFormat, loadConfig, registerAgenticCapabilities, resolveWsUrl, useSiteMapDiscovery, validateConfig, verifyLicenseToken };
|
|
7618
|
+
export { ApiClient, CyberneticAgent, CyberneticCache, CyberneticClient, CyberneticIntentClassifier, CyberneticLocalRAG, CyberneticOfflineStorage, CyberneticSessionStorage, LicenseManager, OmegaOfflineRAG, REQUIRED_FEATURES, SalesApiClient, SiteMapDiscovery, WebSocketTransport, configLoaders, createClient, createDiscoveryConfig, createLicenseManager, deriveWsUrl, detectEnvironment, getEnforcementMode, getTokenExpiration, isValidJWTFormat, loadConfig, registerAgenticCapabilities, resolveWsUrl, useSiteMapDiscovery, validateConfig, verifyLicenseToken };
|
|
7474
7619
|
//# sourceMappingURL=cybernetic-chatbot-client.esm.js.map
|