@avalw/search-worker 2.2.0 → 2.3.1

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.
Files changed (3) hide show
  1. package/bin/cli.js +15 -9
  2. package/index.js +31 -18
  3. package/package.json +2 -2
package/bin/cli.js CHANGED
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * AVALW Search Worker CLI v2.1.0
4
+ * AVALW Search Worker CLI v2.3.1
5
5
  * Distributed Cache Worker for AVALW Search Network
6
6
  *
7
+ * IMPORTANT: From v2.2.0, this worker can ONLY run from Cronos Browser.
8
+ * Running via npx from terminal will be rejected by the server.
9
+ *
7
10
  * Features:
8
11
  * - Intelligent cache with configurable size limits (100MB - 2GB)
9
12
  * - Time-based eviction (1-30 days, default 7)
@@ -54,7 +57,7 @@ for (let i = 0; i < args.length; i++) {
54
57
 
55
58
  function showHelp() {
56
59
  console.log(`
57
- AVALW Search Worker v2.2.0 - Intelligent Distributed Cache
60
+ AVALW Search Worker v2.1.0 - Intelligent Distributed Cache
58
61
 
59
62
  USAGE:
60
63
  npx @avalw/search-worker [options]
@@ -133,9 +136,12 @@ Or set environment variable:
133
136
  // Print banner
134
137
  console.log('');
135
138
  console.log('===============================================================');
136
- console.log(' AVALW SEARCH WORKER v2.1.0 - Intelligent Distributed Cache');
139
+ console.log(' AVALW SEARCH WORKER v2.3.1 - Intelligent Distributed Cache');
137
140
  console.log('===============================================================');
138
141
  console.log('');
142
+ console.log(' NOTE: This worker can ONLY run from Cronos Browser.');
143
+ console.log(' Download Cronos at: https://cronos.avalw.com');
144
+ console.log('');
139
145
 
140
146
  // Print system info
141
147
  const cpus = os.cpus();
@@ -184,14 +190,14 @@ const worker = new SearchWorker({
184
190
  console.log(' [DISCONNECTED] Lost connection to coordinator');
185
191
  },
186
192
 
187
- onCacheHit: () => {
188
- // Privacy: Don't show search queries to workers
189
- console.log(` [CACHE HIT] Served a cached result`);
193
+ onCacheHit: (key) => {
194
+ const query = key.split(':')[0];
195
+ console.log(` [CACHE HIT] Served: "${query.substring(0, 30)}..."`);
190
196
  },
191
197
 
192
- onCacheStore: () => {
193
- // Privacy: Don't show search queries to workers
194
- console.log(` [CACHED] Stored a new result`);
198
+ onCacheStore: (key) => {
199
+ const query = key.split(':')[0];
200
+ console.log(` [CACHED] Stored: "${query.substring(0, 30)}..."`);
195
201
  },
196
202
 
197
203
  onError: (err) => {
package/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  /**
2
- * @avalw/search-worker v2.2.0
2
+ * @avalw/search-worker v2.3.1
3
3
  * Distributed Cache Worker for AVALW Search Network
4
4
  *
5
+ * IMPORTANT: From v2.2.0, connections require Cronos Browser authentication.
6
+ * Workers can only run from Cronos Browser, not from terminal/npx.
7
+ *
5
8
  * Workers connect to the coordinator via WebSocket and serve as
6
9
  * distributed cache nodes, reducing load on AVALW servers.
7
10
  *
@@ -416,6 +419,9 @@ class SearchWorker {
416
419
  this.dashboardUrl = options.dashboardUrl || 'https://worker.avalw.org';
417
420
  this.wsUrl = options.wsUrl || 'wss://worker.avalw.org/ws/cache';
418
421
 
422
+ // Cronos Browser authentication (required for connection)
423
+ this.cronosKey = options.cronosKey || process.env.CRONOS_WORKER_KEY;
424
+
419
425
  // Worker state
420
426
  this.workerId = null;
421
427
  this.isConnected = false;
@@ -522,7 +528,15 @@ class SearchWorker {
522
528
  this.onLog(`Connecting to ${this.wsUrl}...`);
523
529
 
524
530
  try {
525
- this.ws = new WebSocket(this.wsUrl);
531
+ // Add Cronos authentication headers
532
+ const wsOptions = {};
533
+ if (this.cronosKey) {
534
+ wsOptions.headers = {
535
+ 'X-Cronos-Key': this.cronosKey
536
+ };
537
+ }
538
+
539
+ this.ws = new WebSocket(this.wsUrl, wsOptions);
526
540
 
527
541
  this.ws.on('open', () => {
528
542
  this.onLog('Connected to coordinator');
@@ -596,8 +610,7 @@ class SearchWorker {
596
610
  // Invalidate a cache key
597
611
  if (message.key) {
598
612
  this.cache._evict(message.key, 'invalidate');
599
- // Privacy: Don't log the key
600
- this.onLog(`Cache entry invalidated`);
613
+ this.onLog(`Cache invalidated: ${message.key.substring(0, 30)}...`);
601
614
  }
602
615
  break;
603
616
 
@@ -638,8 +651,7 @@ class SearchWorker {
638
651
  value
639
652
  });
640
653
 
641
- // Privacy: Don't log the search query
642
- this.onLog(`Cache HIT - served result #${this.stats.cacheHits}`);
654
+ this.onLog(`Cache HIT: ${key.substring(0, 30)}...`);
643
655
  } else {
644
656
  this.stats.cacheMisses++;
645
657
 
@@ -669,8 +681,7 @@ class SearchWorker {
669
681
  this.onCacheStore(key);
670
682
 
671
683
  const cacheStats = this.cache.getStats();
672
- // Privacy: Don't log the search query, only show stats
673
- this.onLog(`Cached result #${this.stats.cacheStored} (${cacheStats.entries} entries, ${cacheStats.sizeFormatted})`);
684
+ this.onLog(`Cached: ${key.substring(0, 30)}... (${cacheStats.entries} entries, ${cacheStats.sizeFormatted})`);
674
685
  }
675
686
 
676
687
  // Send cache registry to coordinator
@@ -730,33 +741,35 @@ class SearchWorker {
730
741
 
731
742
  // Send heartbeat to HTTP dashboard
732
743
  _sendHttpHeartbeat(cpuUsage, systemInfo) {
733
- const cacheStats = this.cache.getStats();
734
744
  const data = JSON.stringify({
735
745
  worker_token: this.workerToken,
736
746
  system_info: {
737
747
  ...systemInfo,
738
748
  cpu_usage: cpuUsage,
739
749
  memory_usage: Math.round((1 - os.freemem() / os.totalmem()) * 100 * 10) / 10,
740
- session_core_hours: this._calculateCoreHours(),
741
- // Cache stats for dashboard
742
- cache_entries: cacheStats.entries,
743
- cache_bytes: cacheStats.sizeBytes,
744
- cache_served: this.stats.requestsServed
750
+ session_core_hours: this._calculateCoreHours()
745
751
  }
746
752
  });
747
753
 
748
754
  const url = new URL('/api/worker/heartbeat', this.dashboardUrl);
749
755
  const isHttps = url.protocol === 'https:';
750
756
 
757
+ const headers = {
758
+ 'Content-Type': 'application/json',
759
+ 'Content-Length': Buffer.byteLength(data)
760
+ };
761
+
762
+ // Add Cronos authentication header if available
763
+ if (this.cronosKey) {
764
+ headers['X-Cronos-Key'] = this.cronosKey;
765
+ }
766
+
751
767
  const options = {
752
768
  hostname: url.hostname,
753
769
  port: url.port || (isHttps ? 443 : 80),
754
770
  path: url.pathname,
755
771
  method: 'POST',
756
- headers: {
757
- 'Content-Type': 'application/json',
758
- 'Content-Length': Buffer.byteLength(data)
759
- }
772
+ headers
760
773
  };
761
774
 
762
775
  const req = (isHttps ? https : http).request(options, (res) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@avalw/search-worker",
3
- "version": "2.2.0",
4
- "description": "AVALW Distributed Cache Worker - Privacy-focused intelligent caching",
3
+ "version": "2.3.1",
4
+ "description": "AVALW Distributed Cache Worker - Intelligent caching with size limits and auto-cleanup",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "avalw-worker": "./bin/cli.js"