@okf/ootils 1.5.3 → 1.5.5

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/node.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Client } from '@elastic/elasticsearch';
1
2
  import mongoose, { Connection, Document, Types } from 'mongoose';
2
3
  import IORedis from 'ioredis';
3
4
  import * as bullmq from 'bullmq';
@@ -187,6 +188,26 @@ declare namespace MongoConnector {
187
188
  let instance: any;
188
189
  }
189
190
 
191
+ declare class ElasticSearchConnector {
192
+ static getInstance(): any;
193
+ static getClient(): any;
194
+ constructor(options?: {});
195
+ client: Client | null;
196
+ cloudId: any;
197
+ apiKey: any;
198
+ /**
199
+ * Initialize Elasticsearch client
200
+ */
201
+ connect(): Client;
202
+ /**
203
+ * Close the Elasticsearch client
204
+ */
205
+ close(): Promise<void>;
206
+ }
207
+ declare namespace ElasticSearchConnector {
208
+ let instance: any;
209
+ }
210
+
190
211
  /**
191
212
  * Get database connection by tenant
192
213
  * @param tenant - Tenant identifier for the database
@@ -322,7 +343,7 @@ interface IAnnotation extends Document {
322
343
  meta: IMeta;
323
344
  main?: any;
324
345
  annotations?: IAnnotations;
325
- embeddings?: any[];
346
+ embeddings?: number[] | undefined;
326
347
  contentEnhancedText?: string;
327
348
  clusterId?: string;
328
349
  kp_date_published?: Date;
@@ -572,4 +593,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
572
593
  };
573
594
  }): Object;
574
595
 
575
- export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
596
+ export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
package/dist/node.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Client } from '@elastic/elasticsearch';
1
2
  import mongoose, { Connection, Document, Types } from 'mongoose';
2
3
  import IORedis from 'ioredis';
3
4
  import * as bullmq from 'bullmq';
@@ -187,6 +188,26 @@ declare namespace MongoConnector {
187
188
  let instance: any;
188
189
  }
189
190
 
191
+ declare class ElasticSearchConnector {
192
+ static getInstance(): any;
193
+ static getClient(): any;
194
+ constructor(options?: {});
195
+ client: Client | null;
196
+ cloudId: any;
197
+ apiKey: any;
198
+ /**
199
+ * Initialize Elasticsearch client
200
+ */
201
+ connect(): Client;
202
+ /**
203
+ * Close the Elasticsearch client
204
+ */
205
+ close(): Promise<void>;
206
+ }
207
+ declare namespace ElasticSearchConnector {
208
+ let instance: any;
209
+ }
210
+
190
211
  /**
191
212
  * Get database connection by tenant
192
213
  * @param tenant - Tenant identifier for the database
@@ -322,7 +343,7 @@ interface IAnnotation extends Document {
322
343
  meta: IMeta;
323
344
  main?: any;
324
345
  annotations?: IAnnotations;
325
- embeddings?: any[];
346
+ embeddings?: number[] | undefined;
326
347
  contentEnhancedText?: string;
327
348
  clusterId?: string;
328
349
  kp_date_published?: Date;
@@ -572,4 +593,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
572
593
  };
573
594
  }): Object;
574
595
 
575
- export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
596
+ export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
package/dist/node.js CHANGED
@@ -108,7 +108,10 @@ var init_Annotations = __esm({
108
108
  name: String
109
109
  }
110
110
  },
111
- embeddings: Array,
111
+ embeddings: {
112
+ type: [Number],
113
+ default: void 0
114
+ },
112
115
  contentEnhancedText: String,
113
116
  // // Optional chunk related fields
114
117
  // chunk: {
@@ -515,6 +518,71 @@ var require_MongoConnector = __commonJS({
515
518
  }
516
519
  });
517
520
 
521
+ // src/ElasticSearchConnector.js
522
+ var require_ElasticSearchConnector = __commonJS({
523
+ "src/ElasticSearchConnector.js"(exports2, module2) {
524
+ "use strict";
525
+ var { Client } = require("@elastic/elasticsearch");
526
+ var ElasticSearchConnector2 = class _ElasticSearchConnector {
527
+ constructor(options = {}) {
528
+ this.client = null;
529
+ this.cloudId = options.cloudId;
530
+ this.apiKey = options.apiKey;
531
+ _ElasticSearchConnector.instance = this;
532
+ if (!this.cloudId) {
533
+ throw new Error("Cloud ID must be provided in constructor options or ELASTIC_CLOUD_ID environment variable");
534
+ }
535
+ if (!this.apiKey) {
536
+ throw new Error("API Key must be provided in constructor options or ELASTIC_API_KEY environment variable");
537
+ }
538
+ }
539
+ /**
540
+ * Initialize Elasticsearch client
541
+ */
542
+ connect() {
543
+ this.client = new Client({
544
+ cloud: {
545
+ id: this.cloudId
546
+ },
547
+ auth: {
548
+ apiKey: this.apiKey
549
+ }
550
+ });
551
+ console.log("\u2705 Elasticsearch client initialized");
552
+ return this.client;
553
+ }
554
+ // Static method to get the instance
555
+ static getInstance() {
556
+ if (!_ElasticSearchConnector.instance) {
557
+ throw new Error("ElasticSearchConnector not initialized");
558
+ }
559
+ return _ElasticSearchConnector.instance;
560
+ }
561
+ // Static method to get the client
562
+ static getClient() {
563
+ if (!_ElasticSearchConnector.instance || !_ElasticSearchConnector.instance.client) {
564
+ throw new Error("ElasticSearchConnector not initialized or client not connected");
565
+ }
566
+ return _ElasticSearchConnector.instance.client;
567
+ }
568
+ /**
569
+ * Close the Elasticsearch client
570
+ */
571
+ async close() {
572
+ if (this.client) {
573
+ await this.client.close();
574
+ console.log("\u2705 Elasticsearch client closed");
575
+ this.client = null;
576
+ }
577
+ }
578
+ };
579
+ ElasticSearchConnector2.instance = null;
580
+ module2.exports = {
581
+ ElasticSearchConnector: ElasticSearchConnector2
582
+ };
583
+ }
584
+ });
585
+
518
586
  // src/db/getDbByTenant.js
519
587
  var getDbByTenant_exports = {};
520
588
  __export(getDbByTenant_exports, {
@@ -959,7 +1027,6 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
959
1027
  },
960
1028
  workerConfig: {
961
1029
  concurrency: 1,
962
- // Process 10 jobs at once for chunk processing
963
1030
  limiter: {
964
1031
  max: 5,
965
1032
  // Max 50 jobs per...
@@ -1005,7 +1072,36 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
1005
1072
  }
1006
1073
  },
1007
1074
  workerConfig: {
1008
- concurrency: 1
1075
+ concurrency: 1,
1076
+ limiter: {
1077
+ max: 5,
1078
+ // Max 5 jobs per...
1079
+ duration: 6e4
1080
+ // ...60 seconds (higher throughput for chunking)
1081
+ }
1082
+ }
1083
+ },
1084
+ ANNOS_ELASTIC_SYNC_QUEUE: {
1085
+ id: "annos-elastic-sync-queue",
1086
+ queueConfig: {
1087
+ defaultJobOptions: {
1088
+ attempts: 3,
1089
+ backoff: {
1090
+ type: "exponential",
1091
+ delay: 2e3
1092
+ },
1093
+ removeOnComplete: 50,
1094
+ removeOnFail: 100
1095
+ }
1096
+ },
1097
+ workerConfig: {
1098
+ concurrency: 5,
1099
+ limiter: {
1100
+ max: 5,
1101
+ // Max 5 jobs per...
1102
+ duration: 6e4
1103
+ // ...60 seconds (higher throughput for chunking)
1104
+ }
1009
1105
  }
1010
1106
  }
1011
1107
  };
@@ -1053,6 +1149,7 @@ __export(node_exports, {
1053
1149
  AnnotationSchema: () => Annotations_default,
1054
1150
  BaseProducer: () => import_BaseProducer.BaseProducer,
1055
1151
  BaseWorker: () => import_BaseWorker.BaseWorker,
1152
+ ElasticSearchConnector: () => import_ElasticSearchConnector.ElasticSearchConnector,
1056
1153
  GET_GLOBAL_BULLMQ_CONFIG: () => import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG,
1057
1154
  MongoConnector: () => import_MongoConnector2.MongoConnector,
1058
1155
  PlatformConfigsSchema: () => PlatformConfigs_default,
@@ -1357,6 +1454,7 @@ var _extractBlocksFromSomeBuilders = ({
1357
1454
 
1358
1455
  // src/node.ts
1359
1456
  var import_MongoConnector2 = __toESM(require_MongoConnector());
1457
+ var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
1360
1458
  init_getDbByTenant();
1361
1459
 
1362
1460
  // src/db/getGlobalConfig.ts
@@ -1505,6 +1603,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
1505
1603
  AnnotationSchema,
1506
1604
  BaseProducer,
1507
1605
  BaseWorker,
1606
+ ElasticSearchConnector,
1508
1607
  GET_GLOBAL_BULLMQ_CONFIG,
1509
1608
  MongoConnector,
1510
1609
  PlatformConfigsSchema,
package/dist/node.mjs CHANGED
@@ -113,7 +113,10 @@ var init_Annotations = __esm({
113
113
  name: String
114
114
  }
115
115
  },
116
- embeddings: Array,
116
+ embeddings: {
117
+ type: [Number],
118
+ default: void 0
119
+ },
117
120
  contentEnhancedText: String,
118
121
  // // Optional chunk related fields
119
122
  // chunk: {
@@ -520,6 +523,71 @@ var require_MongoConnector = __commonJS({
520
523
  }
521
524
  });
522
525
 
526
+ // src/ElasticSearchConnector.js
527
+ var require_ElasticSearchConnector = __commonJS({
528
+ "src/ElasticSearchConnector.js"(exports, module) {
529
+ "use strict";
530
+ var { Client } = __require("@elastic/elasticsearch");
531
+ var ElasticSearchConnector2 = class _ElasticSearchConnector {
532
+ constructor(options = {}) {
533
+ this.client = null;
534
+ this.cloudId = options.cloudId;
535
+ this.apiKey = options.apiKey;
536
+ _ElasticSearchConnector.instance = this;
537
+ if (!this.cloudId) {
538
+ throw new Error("Cloud ID must be provided in constructor options or ELASTIC_CLOUD_ID environment variable");
539
+ }
540
+ if (!this.apiKey) {
541
+ throw new Error("API Key must be provided in constructor options or ELASTIC_API_KEY environment variable");
542
+ }
543
+ }
544
+ /**
545
+ * Initialize Elasticsearch client
546
+ */
547
+ connect() {
548
+ this.client = new Client({
549
+ cloud: {
550
+ id: this.cloudId
551
+ },
552
+ auth: {
553
+ apiKey: this.apiKey
554
+ }
555
+ });
556
+ console.log("\u2705 Elasticsearch client initialized");
557
+ return this.client;
558
+ }
559
+ // Static method to get the instance
560
+ static getInstance() {
561
+ if (!_ElasticSearchConnector.instance) {
562
+ throw new Error("ElasticSearchConnector not initialized");
563
+ }
564
+ return _ElasticSearchConnector.instance;
565
+ }
566
+ // Static method to get the client
567
+ static getClient() {
568
+ if (!_ElasticSearchConnector.instance || !_ElasticSearchConnector.instance.client) {
569
+ throw new Error("ElasticSearchConnector not initialized or client not connected");
570
+ }
571
+ return _ElasticSearchConnector.instance.client;
572
+ }
573
+ /**
574
+ * Close the Elasticsearch client
575
+ */
576
+ async close() {
577
+ if (this.client) {
578
+ await this.client.close();
579
+ console.log("\u2705 Elasticsearch client closed");
580
+ this.client = null;
581
+ }
582
+ }
583
+ };
584
+ ElasticSearchConnector2.instance = null;
585
+ module.exports = {
586
+ ElasticSearchConnector: ElasticSearchConnector2
587
+ };
588
+ }
589
+ });
590
+
523
591
  // src/db/getDbByTenant.js
524
592
  var getDbByTenant_exports = {};
525
593
  __export(getDbByTenant_exports, {
@@ -964,7 +1032,6 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
964
1032
  },
965
1033
  workerConfig: {
966
1034
  concurrency: 1,
967
- // Process 10 jobs at once for chunk processing
968
1035
  limiter: {
969
1036
  max: 5,
970
1037
  // Max 50 jobs per...
@@ -1010,7 +1077,36 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
1010
1077
  }
1011
1078
  },
1012
1079
  workerConfig: {
1013
- concurrency: 1
1080
+ concurrency: 1,
1081
+ limiter: {
1082
+ max: 5,
1083
+ // Max 5 jobs per...
1084
+ duration: 6e4
1085
+ // ...60 seconds (higher throughput for chunking)
1086
+ }
1087
+ }
1088
+ },
1089
+ ANNOS_ELASTIC_SYNC_QUEUE: {
1090
+ id: "annos-elastic-sync-queue",
1091
+ queueConfig: {
1092
+ defaultJobOptions: {
1093
+ attempts: 3,
1094
+ backoff: {
1095
+ type: "exponential",
1096
+ delay: 2e3
1097
+ },
1098
+ removeOnComplete: 50,
1099
+ removeOnFail: 100
1100
+ }
1101
+ },
1102
+ workerConfig: {
1103
+ concurrency: 5,
1104
+ limiter: {
1105
+ max: 5,
1106
+ // Max 5 jobs per...
1107
+ duration: 6e4
1108
+ // ...60 seconds (higher throughput for chunking)
1109
+ }
1014
1110
  }
1015
1111
  }
1016
1112
  };
@@ -1328,6 +1424,7 @@ var _extractBlocksFromSomeBuilders = ({
1328
1424
 
1329
1425
  // src/node.ts
1330
1426
  var import_MongoConnector2 = __toESM(require_MongoConnector());
1427
+ var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
1331
1428
  init_getDbByTenant();
1332
1429
 
1333
1430
  // src/db/getGlobalConfig.ts
@@ -1472,6 +1569,7 @@ var import_BaseWorker = __toESM(require_BaseWorker());
1472
1569
  var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
1473
1570
  var export_BaseProducer = import_BaseProducer.BaseProducer;
1474
1571
  var export_BaseWorker = import_BaseWorker.BaseWorker;
1572
+ var export_ElasticSearchConnector = import_ElasticSearchConnector.ElasticSearchConnector;
1475
1573
  var export_GET_GLOBAL_BULLMQ_CONFIG = import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG;
1476
1574
  var export_MongoConnector = import_MongoConnector2.MongoConnector;
1477
1575
  var export_WorkerManager = import_WorkerManager.WorkerManager;
@@ -1485,6 +1583,7 @@ export {
1485
1583
  Annotations_default as AnnotationSchema,
1486
1584
  export_BaseProducer as BaseProducer,
1487
1585
  export_BaseWorker as BaseWorker,
1586
+ export_ElasticSearchConnector as ElasticSearchConnector,
1488
1587
  export_GET_GLOBAL_BULLMQ_CONFIG as GET_GLOBAL_BULLMQ_CONFIG,
1489
1588
  export_MongoConnector as MongoConnector,
1490
1589
  PlatformConfigs_default as PlatformConfigsSchema,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.5.3",
6
+ "version": "1.5.5",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",
@@ -74,6 +74,7 @@
74
74
  "typescript": "^5.8.2"
75
75
  },
76
76
  "dependencies": {
77
+ "@elastic/elasticsearch": "^8.2.1",
77
78
  "bullmq": "^5.58.2",
78
79
  "ioredis": "^5.6.1",
79
80
  "mongodb": "^6.13.0",