@astermind/cybernetic-chatbot-client 2.3.12 → 2.3.21

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.
@@ -902,7 +902,7 @@
902
902
  this.loadedFromExport = true;
903
903
  this.exportVersion = exportData.version;
904
904
  this.exportedAt = exportData.meta.exportedAt;
905
- console.log(`[CyberneticLocalRAG] Loaded ${this.documents.length} documents from export (v${exportData.version})`);
905
+ // Debug: loaded ${this.documents.length} documents from export
906
906
  }
907
907
  /**
908
908
  * Get export status information
@@ -1053,7 +1053,7 @@
1053
1053
  type: exportData.type,
1054
1054
  data: exportData
1055
1055
  });
1056
- console.log(`[CyberneticOfflineStorage] Stored ${exportData.meta.chunkCount} chunks`);
1056
+ // Debug: stored chunks
1057
1057
  }
1058
1058
  /**
1059
1059
  * Retrieve vector export from IndexedDB
@@ -1118,7 +1118,7 @@
1118
1118
  async clear() {
1119
1119
  const db = await this.getDB();
1120
1120
  await db.clear('vectors');
1121
- console.log('[CyberneticOfflineStorage] Cache cleared');
1121
+ // Debug: cache cleared
1122
1122
  }
1123
1123
  /**
1124
1124
  * Get the database connection
@@ -1339,7 +1339,7 @@
1339
1339
  }
1340
1340
  const delay = this.reconnectDelay * Math.pow(2, this.reconnectAttempts);
1341
1341
  this.reconnectAttempts++;
1342
- console.log(`[Cybernetic WS] Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`);
1342
+ // Reconnection is logged only in debug mode (via CyberneticClient)
1343
1343
  await new Promise(resolve => setTimeout(resolve, delay));
1344
1344
  // Ensure old connection is cleaned up
1345
1345
  if (this.ws) {
@@ -2606,6 +2606,13 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
2606
2606
  * Always returns a response, never throws exceptions.
2607
2607
  */
2608
2608
  class CyberneticClient {
2609
+ /** Debug logger — only outputs when config.debug is true */
2610
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2611
+ log(...args) {
2612
+ if (this.config.debug) {
2613
+ console.log(...args);
2614
+ }
2615
+ }
2609
2616
  constructor(config) {
2610
2617
  this.wsTransport = null;
2611
2618
  this.status = 'connecting';
@@ -2655,7 +2662,8 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
2655
2662
  maxSources: config.sources?.maxSources ?? 5
2656
2663
  },
2657
2664
  onStatusChange: config.onStatusChange || (() => { }),
2658
- onError: config.onError || (() => { })
2665
+ onError: config.onError || (() => { }),
2666
+ debug: config.debug ?? false,
2659
2667
  };
2660
2668
  // Initialize components
2661
2669
  this.apiClient = new ApiClient(this.config.apiUrl, this.config.apiKey);
@@ -2681,7 +2689,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
2681
2689
  // Initialize WebSocket transport if configured and not forced to REST
2682
2690
  if (wsUrl && transport !== 'rest' && typeof WebSocket !== 'undefined') {
2683
2691
  this.wsTransport = new WebSocketTransport(wsUrl, config.apiKey, config.websocket);
2684
- console.log(`[Cybernetic] WebSocket transport enabled: ${wsUrl}`);
2692
+ this.log(`[Cybernetic] WebSocket transport enabled: ${wsUrl}`);
2685
2693
  }
2686
2694
  // Monitor connection status
2687
2695
  this.monitorConnection();
@@ -2716,7 +2724,6 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
2716
2724
  */
2717
2725
  registerAgentic(capabilities) {
2718
2726
  this.agenticCapabilities = capabilities;
2719
- console.log('[Cybernetic] Agentic capabilities registered');
2720
2727
  }
2721
2728
  /**
2722
2729
  * Check if agentic capabilities are available and enabled
@@ -2849,11 +2856,11 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
2849
2856
  if (this.offlineStorage && storageMode !== 'memory') {
2850
2857
  const cacheId = 'default';
2851
2858
  if (await this.offlineStorage.isValid(cacheId, maxAge)) {
2852
- console.log('[Cybernetic] Loading vectors from IndexedDB cache');
2859
+ this.log('[Cybernetic] Loading vectors from IndexedDB cache');
2853
2860
  const cached = await this.offlineStorage.retrieve(cacheId);
2854
2861
  if (cached) {
2855
2862
  await this.localRAG.loadFromExport(cached);
2856
- console.log('[Cybernetic] Loaded vectors from IndexedDB cache');
2863
+ this.log('[Cybernetic] Loaded vectors from IndexedDB cache');
2857
2864
  return;
2858
2865
  }
2859
2866
  }
@@ -2876,7 +2883,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
2876
2883
  if (config.omega?.enabled) {
2877
2884
  await this.initializeOmega(config);
2878
2885
  }
2879
- console.log('[Cybernetic] Loaded vectors from URL:', config.vectorFileUrl);
2886
+ this.log('[Cybernetic] Loaded vectors from URL:', config.vectorFileUrl);
2880
2887
  return;
2881
2888
  }
2882
2889
  catch (error) {
@@ -2890,7 +2897,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
2890
2897
  if (config.omega?.enabled) {
2891
2898
  await this.initializeOmega(config);
2892
2899
  }
2893
- console.log('[Cybernetic] Loaded inline vector data');
2900
+ this.log('[Cybernetic] Loaded inline vector data');
2894
2901
  return;
2895
2902
  }
2896
2903
  // No vectors available - log warning (one-time)
@@ -2924,7 +2931,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
2924
2931
  // Convert our type to the astermind type
2925
2932
  await this.omegaRAG.loadModel(config.omega.modelData);
2926
2933
  }
2927
- console.log('[Cybernetic] Omega RAG initialized');
2934
+ this.log('[Cybernetic] Omega RAG initialized');
2928
2935
  }
2929
2936
  catch (error) {
2930
2937
  console.warn('[Cybernetic] Failed to initialize Omega RAG:', error);
@@ -3087,7 +3094,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
3087
3094
  // Check maintenance mode before API call (ADR-200)
3088
3095
  const settings = await this.checkSystemStatus();
3089
3096
  if (settings.maintenanceMode || settings.forceOfflineClients) {
3090
- console.log('[Cybernetic] Maintenance mode active, using cached data');
3097
+ this.log('[Cybernetic] Maintenance mode active, using cached data');
3091
3098
  // Return maintenance response if no cached data
3092
3099
  if (!this.isCacheValid()) {
3093
3100
  return {
@@ -3169,7 +3176,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
3169
3176
  // Check maintenance mode before API call (ADR-200)
3170
3177
  const settings = await this.checkSystemStatus();
3171
3178
  if (settings.maintenanceMode || settings.forceOfflineClients) {
3172
- console.log('[Cybernetic] Maintenance mode active, falling back to offline');
3179
+ this.log('[Cybernetic] Maintenance mode active, falling back to offline');
3173
3180
  const response = await this.fallbackAsk(message);
3174
3181
  callbacks.onComplete?.(response);
3175
3182
  return;
@@ -3288,7 +3295,6 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
3288
3295
  if (docs.length > 0) {
3289
3296
  await this.cache.store(docs);
3290
3297
  await this.localRAG.index(docs);
3291
- console.log(`[Cybernetic] Cache synced: ${docs.length} documents`);
3292
3298
  }
3293
3299
  this.setStatus('online');
3294
3300
  }
@@ -3378,6 +3384,28 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
3378
3384
  };
3379
3385
  }
3380
3386
  }
3387
+ /**
3388
+ * Fetch widget configuration (including persona) from the backend.
3389
+ * Requires apiKey and apiUrl to be configured.
3390
+ * Returns null on any error (network, auth, server) — callers should
3391
+ * fall back to static config when null is returned.
3392
+ */
3393
+ async fetchConfig() {
3394
+ try {
3395
+ const response = await fetch(`${this.config.apiUrl}/api/external/config`, {
3396
+ headers: {
3397
+ 'X-API-Key': this.config.apiKey,
3398
+ 'Accept': 'application/json',
3399
+ },
3400
+ });
3401
+ if (!response.ok)
3402
+ return null;
3403
+ return await response.json();
3404
+ }
3405
+ catch {
3406
+ return null;
3407
+ }
3408
+ }
3381
3409
  /**
3382
3410
  * Check if maintenance mode is active
3383
3411
  */
@@ -3756,7 +3784,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
3756
3784
  const cachedEntries = this.loadFromLocalStorage();
3757
3785
  if (cachedEntries) {
3758
3786
  this.discoveredEntries = cachedEntries;
3759
- console.log(`[SiteMapDiscovery] Loaded ${cachedEntries.length} entries from cache`);
3787
+ // Debug: [SiteMapDiscovery] Loaded ${cachedEntries.length} entries from cache`);
3760
3788
  // Still run discovery in background to refresh cache
3761
3789
  this.refreshInBackground();
3762
3790
  return;
@@ -3789,8 +3817,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
3789
3817
  }
3790
3818
  // Set up popstate listener for SPA navigation
3791
3819
  this.setupPopstateListener();
3792
- const total = this.staticEntries.length + this.discoveredEntries.length + this.backendEntries.length;
3793
- console.log(`[SiteMapDiscovery] Initialized with ${total} total entries (${this.staticEntries.length} static, ${this.discoveredEntries.length} discovered, ${this.backendEntries.length} backend)`);
3820
+ // Debug: [SiteMapDiscovery] Initialized with ${this.staticEntries.length + this.discoveredEntries.length + this.backendEntries.length} total entries`);
3794
3821
  }
3795
3822
  /**
3796
3823
  * Wait for DOM to be ready before scanning
@@ -3989,7 +4016,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
3989
4016
  entries.push(this.enhanceEntry(entry, 'discovery'));
3990
4017
  }
3991
4018
  }
3992
- console.log(`[SiteMapDiscovery] Discovered ${entries.length} routes from ${framework}`);
4019
+ // Debug: [SiteMapDiscovery] Discovered ${entries.length} routes from ${framework}`);
3993
4020
  }
3994
4021
  catch (error) {
3995
4022
  console.warn('[SiteMapDiscovery] Framework discovery failed:', error);
@@ -4203,7 +4230,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
4203
4230
  // Invalid selector - skip
4204
4231
  }
4205
4232
  }
4206
- console.log(`[SiteMapDiscovery] DOM scan found ${routes.length} routes (limit: ${maxLinks})`);
4233
+ // Debug: [SiteMapDiscovery] DOM scan found ${routes.length} routes (limit: ${maxLinks})`);
4207
4234
  return routes;
4208
4235
  }
4209
4236
  // ==================== SOURCE 3: BACKEND API ====================
@@ -4247,7 +4274,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
4247
4274
  fetchedAt: Date.now(),
4248
4275
  expiresAt: Date.now() + ttl
4249
4276
  };
4250
- console.log(`[SiteMapDiscovery] Loaded ${entries.length} routes from backend`);
4277
+ // Debug: [SiteMapDiscovery] Loaded ${entries.length} routes from backend`);
4251
4278
  return {
4252
4279
  entries,
4253
4280
  source: 'backend',
@@ -4499,10 +4526,6 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
4499
4526
  // Initialize multi-source sitemap discovery
4500
4527
  if (siteMapConfig) {
4501
4528
  this.siteMapDiscovery = new SiteMapDiscovery(siteMapConfig, apiUrl, apiKey);
4502
- // Log zero-config mode activation
4503
- if (!config.siteMapConfig && config.enabled) {
4504
- console.log('[CyberneticIntentClassifier] Zero-config mode: auto-discovery enabled');
4505
- }
4506
4529
  }
4507
4530
  }
4508
4531
  /**
@@ -5062,7 +5085,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
5062
5085
  if (exportData.sitemap) {
5063
5086
  this.loadSitemapEntries(exportData.sitemap);
5064
5087
  }
5065
- console.log(`[CyberneticIntentClassifier] Trained with ${this.categories.length} categories, ${this.topicKeywords.size} topics`);
5088
+ // Debug: [CyberneticIntentClassifier] Trained with ${this.categories.length} categories, ${this.topicKeywords.size} topics`);
5066
5089
  }
5067
5090
  /**
5068
5091
  * Load sitemap from configuration
@@ -5122,7 +5145,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
5122
5145
  this.siteMapIndex.set(key, siteMapEntry);
5123
5146
  }
5124
5147
  }
5125
- console.log(`[CyberneticIntentClassifier] Loaded ${entries.length} sitemap entries`);
5148
+ // Debug: [CyberneticIntentClassifier] Loaded ${entries.length} sitemap entries`);
5126
5149
  }
5127
5150
  /**
5128
5151
  * Extract topics and keywords from document content
@@ -5208,13 +5231,13 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
5208
5231
  */
5209
5232
  async initializeDiscovery() {
5210
5233
  if (!this.siteMapDiscovery) {
5211
- console.log('[CyberneticIntentClassifier] No siteMapConfig provided, skipping discovery');
5234
+ // Debug: [CyberneticIntentClassifier] No siteMapConfig provided, skipping discovery');
5212
5235
  return;
5213
5236
  }
5214
5237
  try {
5215
5238
  await this.siteMapDiscovery.initialize();
5216
5239
  this.rebuildIndexesFromDiscovery();
5217
- console.log(`[CyberneticIntentClassifier] Discovery complete, indexed ${this.siteMapIndex.size} entries`);
5240
+ // Debug: [CyberneticIntentClassifier] Discovery complete, indexed ${this.siteMapIndex.size} entries`);
5218
5241
  }
5219
5242
  catch (error) {
5220
5243
  console.error('[CyberneticIntentClassifier] Discovery initialization failed:', error);
@@ -5291,7 +5314,7 @@ LJ5AZXvOhHaXdHzMuYKX5BpK4w7TqbPvJ6QPvKmLKvHh1VKcUJ6mJQgJJw==
5291
5314
  */
5292
5315
  async refreshSiteMap() {
5293
5316
  if (!this.siteMapDiscovery) {
5294
- console.log('[CyberneticIntentClassifier] No siteMapConfig provided, cannot refresh');
5317
+ // Debug: [CyberneticIntentClassifier] No siteMapConfig provided, cannot refresh');
5295
5318
  return;
5296
5319
  }
5297
5320
  await this.siteMapDiscovery.refresh();