@okf/ootils 1.5.4 → 1.5.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/dist/node.d.mts +58 -1
- package/dist/node.d.ts +58 -1
- package/dist/node.js +246 -6
- package/dist/node.mjs +246 -6
- package/package.json +2 -1
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
|
|
@@ -495,6 +516,42 @@ declare class WorkerManager {
|
|
|
495
516
|
}[];
|
|
496
517
|
}
|
|
497
518
|
|
|
519
|
+
declare class ProducerManager {
|
|
520
|
+
static instance: null;
|
|
521
|
+
static initialize(producerClasses?: any[]): any;
|
|
522
|
+
static addJob(producerClassName: any, jobName: any, jobData: any, opts?: {}): Promise<any>;
|
|
523
|
+
static addBulkJobs(producerClassName: any, jobs: any): Promise<any>;
|
|
524
|
+
static getStatus(): Promise<any>;
|
|
525
|
+
static shutdown(): Promise<void>;
|
|
526
|
+
constructor(producerClasses?: any[]);
|
|
527
|
+
producerClasses: any[] | undefined;
|
|
528
|
+
activeProducers: Map<any, any> | undefined;
|
|
529
|
+
/**
|
|
530
|
+
* Initialize all producers as singletons
|
|
531
|
+
*/
|
|
532
|
+
initializeAllProducers(): any[];
|
|
533
|
+
/**
|
|
534
|
+
* Get a specific producer instance
|
|
535
|
+
*/
|
|
536
|
+
getProducer(producerClassName: any): any;
|
|
537
|
+
/**
|
|
538
|
+
* Add a job using a specific producer
|
|
539
|
+
*/
|
|
540
|
+
addJob(producerClassName: any, jobData: any, opts?: {}): Promise<any>;
|
|
541
|
+
/**
|
|
542
|
+
* Add bulk jobs using a specific producer
|
|
543
|
+
*/
|
|
544
|
+
addBulkJobs(producerClassName: any, jobs: any): Promise<any>;
|
|
545
|
+
/**
|
|
546
|
+
* Get status of all producers
|
|
547
|
+
*/
|
|
548
|
+
getStatus(): Promise<any[]>;
|
|
549
|
+
/**
|
|
550
|
+
* Gracefully shutdown all producers
|
|
551
|
+
*/
|
|
552
|
+
shutdown(): Promise<void>;
|
|
553
|
+
}
|
|
554
|
+
|
|
498
555
|
declare class BaseProducer {
|
|
499
556
|
constructor(config: any);
|
|
500
557
|
config: any;
|
|
@@ -572,4 +629,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
|
572
629
|
};
|
|
573
630
|
}): Object;
|
|
574
631
|
|
|
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 };
|
|
632
|
+
export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, ProducerManager, 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
|
|
@@ -495,6 +516,42 @@ declare class WorkerManager {
|
|
|
495
516
|
}[];
|
|
496
517
|
}
|
|
497
518
|
|
|
519
|
+
declare class ProducerManager {
|
|
520
|
+
static instance: null;
|
|
521
|
+
static initialize(producerClasses?: any[]): any;
|
|
522
|
+
static addJob(producerClassName: any, jobName: any, jobData: any, opts?: {}): Promise<any>;
|
|
523
|
+
static addBulkJobs(producerClassName: any, jobs: any): Promise<any>;
|
|
524
|
+
static getStatus(): Promise<any>;
|
|
525
|
+
static shutdown(): Promise<void>;
|
|
526
|
+
constructor(producerClasses?: any[]);
|
|
527
|
+
producerClasses: any[] | undefined;
|
|
528
|
+
activeProducers: Map<any, any> | undefined;
|
|
529
|
+
/**
|
|
530
|
+
* Initialize all producers as singletons
|
|
531
|
+
*/
|
|
532
|
+
initializeAllProducers(): any[];
|
|
533
|
+
/**
|
|
534
|
+
* Get a specific producer instance
|
|
535
|
+
*/
|
|
536
|
+
getProducer(producerClassName: any): any;
|
|
537
|
+
/**
|
|
538
|
+
* Add a job using a specific producer
|
|
539
|
+
*/
|
|
540
|
+
addJob(producerClassName: any, jobData: any, opts?: {}): Promise<any>;
|
|
541
|
+
/**
|
|
542
|
+
* Add bulk jobs using a specific producer
|
|
543
|
+
*/
|
|
544
|
+
addBulkJobs(producerClassName: any, jobs: any): Promise<any>;
|
|
545
|
+
/**
|
|
546
|
+
* Get status of all producers
|
|
547
|
+
*/
|
|
548
|
+
getStatus(): Promise<any[]>;
|
|
549
|
+
/**
|
|
550
|
+
* Gracefully shutdown all producers
|
|
551
|
+
*/
|
|
552
|
+
shutdown(): Promise<void>;
|
|
553
|
+
}
|
|
554
|
+
|
|
498
555
|
declare class BaseProducer {
|
|
499
556
|
constructor(config: any);
|
|
500
557
|
config: any;
|
|
@@ -572,4 +629,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
|
572
629
|
};
|
|
573
630
|
}): Object;
|
|
574
631
|
|
|
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 };
|
|
632
|
+
export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, ProducerManager, 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
|
@@ -518,6 +518,71 @@ var require_MongoConnector = __commonJS({
|
|
|
518
518
|
}
|
|
519
519
|
});
|
|
520
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
|
+
|
|
521
586
|
// src/db/getDbByTenant.js
|
|
522
587
|
var getDbByTenant_exports = {};
|
|
523
588
|
__export(getDbByTenant_exports, {
|
|
@@ -714,6 +779,145 @@ var require_WorkerManager = __commonJS({
|
|
|
714
779
|
}
|
|
715
780
|
});
|
|
716
781
|
|
|
782
|
+
// src/bullmq/ProducerManager.js
|
|
783
|
+
var require_ProducerManager = __commonJS({
|
|
784
|
+
"src/bullmq/ProducerManager.js"(exports2, module2) {
|
|
785
|
+
"use strict";
|
|
786
|
+
var _ProducerManager = class _ProducerManager {
|
|
787
|
+
constructor(producerClasses = []) {
|
|
788
|
+
if (_ProducerManager.instance) {
|
|
789
|
+
return _ProducerManager.instance;
|
|
790
|
+
}
|
|
791
|
+
this.producerClasses = producerClasses;
|
|
792
|
+
this.activeProducers = /* @__PURE__ */ new Map();
|
|
793
|
+
_ProducerManager.instance = this;
|
|
794
|
+
}
|
|
795
|
+
// Static methods that delegate to singleton instance
|
|
796
|
+
static initialize(producerClasses = []) {
|
|
797
|
+
if (!this.instance) {
|
|
798
|
+
this.instance = new _ProducerManager(producerClasses);
|
|
799
|
+
}
|
|
800
|
+
return this.instance.initializeAllProducers();
|
|
801
|
+
}
|
|
802
|
+
static async addJob(producerClassName, jobName, jobData, opts = {}) {
|
|
803
|
+
if (!this.instance) {
|
|
804
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
805
|
+
}
|
|
806
|
+
return await this.instance.addJob(producerClassName, jobName, jobData, opts);
|
|
807
|
+
}
|
|
808
|
+
static async addBulkJobs(producerClassName, jobs) {
|
|
809
|
+
if (!this.instance) {
|
|
810
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
811
|
+
}
|
|
812
|
+
return await this.instance.addBulkJobs(producerClassName, jobs);
|
|
813
|
+
}
|
|
814
|
+
static async getStatus() {
|
|
815
|
+
if (!this.instance) {
|
|
816
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
817
|
+
}
|
|
818
|
+
return await this.instance.getStatus();
|
|
819
|
+
}
|
|
820
|
+
static async shutdown() {
|
|
821
|
+
if (this.instance) {
|
|
822
|
+
await this.instance.shutdown();
|
|
823
|
+
this.instance = null;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Initialize all producers as singletons
|
|
828
|
+
*/
|
|
829
|
+
initializeAllProducers() {
|
|
830
|
+
if (this.producerClasses.length === 0) {
|
|
831
|
+
console.log("No producers provided to initialize");
|
|
832
|
+
return [];
|
|
833
|
+
}
|
|
834
|
+
console.log("\u{1F680} Initializing all producers...");
|
|
835
|
+
this.producerClasses.forEach((ProducerClass) => {
|
|
836
|
+
try {
|
|
837
|
+
const producerInstance = new ProducerClass();
|
|
838
|
+
this.activeProducers.set(ProducerClass.name, {
|
|
839
|
+
class: ProducerClass,
|
|
840
|
+
instance: producerInstance
|
|
841
|
+
});
|
|
842
|
+
console.log(`\u2705 Initialized ${ProducerClass.name}`);
|
|
843
|
+
} catch (error) {
|
|
844
|
+
console.error(`\u274C Failed to initialize ${ProducerClass.name}:`, error);
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
console.log(`\u{1F389} Successfully initialized ${this.activeProducers.size} producers`);
|
|
848
|
+
return Array.from(this.activeProducers.values());
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Get a specific producer instance
|
|
852
|
+
*/
|
|
853
|
+
getProducer(producerClassName) {
|
|
854
|
+
const producer = this.activeProducers.get(producerClassName);
|
|
855
|
+
if (!producer) {
|
|
856
|
+
throw new Error(`Producer ${producerClassName} not found. Make sure it's initialized.`);
|
|
857
|
+
}
|
|
858
|
+
return producer.instance;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Add a job using a specific producer
|
|
862
|
+
*/
|
|
863
|
+
async addJob(producerClassName, jobData, opts = {}) {
|
|
864
|
+
const producer = this.getProducer(producerClassName);
|
|
865
|
+
return await producer.addJobWithName(jobData, opts);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Add bulk jobs using a specific producer
|
|
869
|
+
*/
|
|
870
|
+
async addBulkJobs(producerClassName, jobs) {
|
|
871
|
+
const producer = this.getProducer(producerClassName);
|
|
872
|
+
return await producer.addBulkJobs(jobs);
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Get status of all producers
|
|
876
|
+
*/
|
|
877
|
+
async getStatus() {
|
|
878
|
+
const statusPromises = Array.from(this.activeProducers.entries()).map(
|
|
879
|
+
async ([name, { instance }]) => {
|
|
880
|
+
try {
|
|
881
|
+
const status = await instance.getStatus();
|
|
882
|
+
return {
|
|
883
|
+
name,
|
|
884
|
+
queueId: instance.config?.id || "unknown",
|
|
885
|
+
isActive: !!instance.queue,
|
|
886
|
+
...status
|
|
887
|
+
};
|
|
888
|
+
} catch (error) {
|
|
889
|
+
return {
|
|
890
|
+
name,
|
|
891
|
+
queueId: instance.config?.id || "unknown",
|
|
892
|
+
isActive: false,
|
|
893
|
+
error: error.message
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
return await Promise.all(statusPromises);
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Gracefully shutdown all producers
|
|
902
|
+
*/
|
|
903
|
+
async shutdown() {
|
|
904
|
+
console.log("\u{1F6D1} Stopping all producers...");
|
|
905
|
+
const stopPromises = Array.from(this.activeProducers.entries()).map(
|
|
906
|
+
([name, { instance }]) => instance.stop().catch(
|
|
907
|
+
(err) => console.error(`\u274C Error stopping ${name}:`, err)
|
|
908
|
+
)
|
|
909
|
+
);
|
|
910
|
+
await Promise.all(stopPromises);
|
|
911
|
+
this.activeProducers.clear();
|
|
912
|
+
console.log("\u2705 All producers stopped");
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
__publicField(_ProducerManager, "instance", null);
|
|
916
|
+
var ProducerManager2 = _ProducerManager;
|
|
917
|
+
module2.exports = { ProducerManager: ProducerManager2 };
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
|
|
717
921
|
// src/bullmq/BaseProducer.js
|
|
718
922
|
var require_BaseProducer = __commonJS({
|
|
719
923
|
"src/bullmq/BaseProducer.js"(exports2, module2) {
|
|
@@ -796,7 +1000,8 @@ var require_BaseProducer = __commonJS({
|
|
|
796
1000
|
async stop() {
|
|
797
1001
|
if (this.queue) {
|
|
798
1002
|
await this.queue.close();
|
|
799
|
-
|
|
1003
|
+
await this.queue.disconnect();
|
|
1004
|
+
console.log(`\u{1F6D1} ${this.constructor.name} queue closed & disconnected`);
|
|
800
1005
|
}
|
|
801
1006
|
}
|
|
802
1007
|
};
|
|
@@ -856,7 +1061,8 @@ var require_BaseWorker = __commonJS({
|
|
|
856
1061
|
async stop() {
|
|
857
1062
|
if (this.worker) {
|
|
858
1063
|
await this.worker.close();
|
|
859
|
-
|
|
1064
|
+
await this.worker.disconnect();
|
|
1065
|
+
console.log(`\u{1F6D1} ${this.constructor.name} stopped & disconnected`);
|
|
860
1066
|
}
|
|
861
1067
|
}
|
|
862
1068
|
};
|
|
@@ -891,7 +1097,7 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
891
1097
|
concurrency: 1,
|
|
892
1098
|
// Process jobs one at a time to avoid race conditions
|
|
893
1099
|
limiter: {
|
|
894
|
-
max:
|
|
1100
|
+
max: 5,
|
|
895
1101
|
// Max 10 jobs per...
|
|
896
1102
|
duration: 6e4
|
|
897
1103
|
// ...60 seconds (rate limiting)
|
|
@@ -962,9 +1168,8 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
962
1168
|
},
|
|
963
1169
|
workerConfig: {
|
|
964
1170
|
concurrency: 1,
|
|
965
|
-
// Process 10 jobs at once for chunk processing
|
|
966
1171
|
limiter: {
|
|
967
|
-
max:
|
|
1172
|
+
max: 15,
|
|
968
1173
|
// Max 50 jobs per...
|
|
969
1174
|
duration: 6e4
|
|
970
1175
|
// ...60 seconds (higher throughput for chunking)
|
|
@@ -1008,7 +1213,36 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
1008
1213
|
}
|
|
1009
1214
|
},
|
|
1010
1215
|
workerConfig: {
|
|
1011
|
-
concurrency: 1
|
|
1216
|
+
concurrency: 1,
|
|
1217
|
+
limiter: {
|
|
1218
|
+
max: 15,
|
|
1219
|
+
// (lets always keep this same as content enhance & embed since it comes immediately after)
|
|
1220
|
+
duration: 6e4
|
|
1221
|
+
// ...60 seconds (higher throughput for chunking)
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
},
|
|
1225
|
+
ANNOS_ELASTIC_SYNC_QUEUE: {
|
|
1226
|
+
id: "annos-elastic-sync-queue",
|
|
1227
|
+
queueConfig: {
|
|
1228
|
+
defaultJobOptions: {
|
|
1229
|
+
attempts: 3,
|
|
1230
|
+
backoff: {
|
|
1231
|
+
type: "exponential",
|
|
1232
|
+
delay: 2e3
|
|
1233
|
+
},
|
|
1234
|
+
removeOnComplete: 50,
|
|
1235
|
+
removeOnFail: 100
|
|
1236
|
+
}
|
|
1237
|
+
},
|
|
1238
|
+
workerConfig: {
|
|
1239
|
+
concurrency: 5,
|
|
1240
|
+
limiter: {
|
|
1241
|
+
max: 15,
|
|
1242
|
+
// (lets always keep this same as content enhance & embed since it comes immediately after)
|
|
1243
|
+
duration: 6e4
|
|
1244
|
+
// ...60 seconds (higher throughput for chunking)
|
|
1245
|
+
}
|
|
1012
1246
|
}
|
|
1013
1247
|
}
|
|
1014
1248
|
};
|
|
@@ -1056,9 +1290,11 @@ __export(node_exports, {
|
|
|
1056
1290
|
AnnotationSchema: () => Annotations_default,
|
|
1057
1291
|
BaseProducer: () => import_BaseProducer.BaseProducer,
|
|
1058
1292
|
BaseWorker: () => import_BaseWorker.BaseWorker,
|
|
1293
|
+
ElasticSearchConnector: () => import_ElasticSearchConnector.ElasticSearchConnector,
|
|
1059
1294
|
GET_GLOBAL_BULLMQ_CONFIG: () => import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG,
|
|
1060
1295
|
MongoConnector: () => import_MongoConnector2.MongoConnector,
|
|
1061
1296
|
PlatformConfigsSchema: () => PlatformConfigs_default,
|
|
1297
|
+
ProducerManager: () => import_ProducerManager.ProducerManager,
|
|
1062
1298
|
TplSchema: () => Tpl_default,
|
|
1063
1299
|
WorkerManager: () => import_WorkerManager.WorkerManager,
|
|
1064
1300
|
connectToRedis: () => connectToRedis,
|
|
@@ -1360,6 +1596,7 @@ var _extractBlocksFromSomeBuilders = ({
|
|
|
1360
1596
|
|
|
1361
1597
|
// src/node.ts
|
|
1362
1598
|
var import_MongoConnector2 = __toESM(require_MongoConnector());
|
|
1599
|
+
var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
|
|
1363
1600
|
init_getDbByTenant();
|
|
1364
1601
|
|
|
1365
1602
|
// src/db/getGlobalConfig.ts
|
|
@@ -1499,6 +1736,7 @@ var getAIConfigs = async ({
|
|
|
1499
1736
|
// src/node.ts
|
|
1500
1737
|
init_models();
|
|
1501
1738
|
var import_WorkerManager = __toESM(require_WorkerManager());
|
|
1739
|
+
var import_ProducerManager = __toESM(require_ProducerManager());
|
|
1502
1740
|
var import_BaseProducer = __toESM(require_BaseProducer());
|
|
1503
1741
|
var import_BaseWorker = __toESM(require_BaseWorker());
|
|
1504
1742
|
var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
|
|
@@ -1508,9 +1746,11 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
1508
1746
|
AnnotationSchema,
|
|
1509
1747
|
BaseProducer,
|
|
1510
1748
|
BaseWorker,
|
|
1749
|
+
ElasticSearchConnector,
|
|
1511
1750
|
GET_GLOBAL_BULLMQ_CONFIG,
|
|
1512
1751
|
MongoConnector,
|
|
1513
1752
|
PlatformConfigsSchema,
|
|
1753
|
+
ProducerManager,
|
|
1514
1754
|
TplSchema,
|
|
1515
1755
|
WorkerManager,
|
|
1516
1756
|
connectToRedis,
|
package/dist/node.mjs
CHANGED
|
@@ -523,6 +523,71 @@ var require_MongoConnector = __commonJS({
|
|
|
523
523
|
}
|
|
524
524
|
});
|
|
525
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
|
+
|
|
526
591
|
// src/db/getDbByTenant.js
|
|
527
592
|
var getDbByTenant_exports = {};
|
|
528
593
|
__export(getDbByTenant_exports, {
|
|
@@ -719,6 +784,145 @@ var require_WorkerManager = __commonJS({
|
|
|
719
784
|
}
|
|
720
785
|
});
|
|
721
786
|
|
|
787
|
+
// src/bullmq/ProducerManager.js
|
|
788
|
+
var require_ProducerManager = __commonJS({
|
|
789
|
+
"src/bullmq/ProducerManager.js"(exports, module) {
|
|
790
|
+
"use strict";
|
|
791
|
+
var _ProducerManager = class _ProducerManager {
|
|
792
|
+
constructor(producerClasses = []) {
|
|
793
|
+
if (_ProducerManager.instance) {
|
|
794
|
+
return _ProducerManager.instance;
|
|
795
|
+
}
|
|
796
|
+
this.producerClasses = producerClasses;
|
|
797
|
+
this.activeProducers = /* @__PURE__ */ new Map();
|
|
798
|
+
_ProducerManager.instance = this;
|
|
799
|
+
}
|
|
800
|
+
// Static methods that delegate to singleton instance
|
|
801
|
+
static initialize(producerClasses = []) {
|
|
802
|
+
if (!this.instance) {
|
|
803
|
+
this.instance = new _ProducerManager(producerClasses);
|
|
804
|
+
}
|
|
805
|
+
return this.instance.initializeAllProducers();
|
|
806
|
+
}
|
|
807
|
+
static async addJob(producerClassName, jobName, jobData, opts = {}) {
|
|
808
|
+
if (!this.instance) {
|
|
809
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
810
|
+
}
|
|
811
|
+
return await this.instance.addJob(producerClassName, jobName, jobData, opts);
|
|
812
|
+
}
|
|
813
|
+
static async addBulkJobs(producerClassName, jobs) {
|
|
814
|
+
if (!this.instance) {
|
|
815
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
816
|
+
}
|
|
817
|
+
return await this.instance.addBulkJobs(producerClassName, jobs);
|
|
818
|
+
}
|
|
819
|
+
static async getStatus() {
|
|
820
|
+
if (!this.instance) {
|
|
821
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
822
|
+
}
|
|
823
|
+
return await this.instance.getStatus();
|
|
824
|
+
}
|
|
825
|
+
static async shutdown() {
|
|
826
|
+
if (this.instance) {
|
|
827
|
+
await this.instance.shutdown();
|
|
828
|
+
this.instance = null;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Initialize all producers as singletons
|
|
833
|
+
*/
|
|
834
|
+
initializeAllProducers() {
|
|
835
|
+
if (this.producerClasses.length === 0) {
|
|
836
|
+
console.log("No producers provided to initialize");
|
|
837
|
+
return [];
|
|
838
|
+
}
|
|
839
|
+
console.log("\u{1F680} Initializing all producers...");
|
|
840
|
+
this.producerClasses.forEach((ProducerClass) => {
|
|
841
|
+
try {
|
|
842
|
+
const producerInstance = new ProducerClass();
|
|
843
|
+
this.activeProducers.set(ProducerClass.name, {
|
|
844
|
+
class: ProducerClass,
|
|
845
|
+
instance: producerInstance
|
|
846
|
+
});
|
|
847
|
+
console.log(`\u2705 Initialized ${ProducerClass.name}`);
|
|
848
|
+
} catch (error) {
|
|
849
|
+
console.error(`\u274C Failed to initialize ${ProducerClass.name}:`, error);
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
console.log(`\u{1F389} Successfully initialized ${this.activeProducers.size} producers`);
|
|
853
|
+
return Array.from(this.activeProducers.values());
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Get a specific producer instance
|
|
857
|
+
*/
|
|
858
|
+
getProducer(producerClassName) {
|
|
859
|
+
const producer = this.activeProducers.get(producerClassName);
|
|
860
|
+
if (!producer) {
|
|
861
|
+
throw new Error(`Producer ${producerClassName} not found. Make sure it's initialized.`);
|
|
862
|
+
}
|
|
863
|
+
return producer.instance;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Add a job using a specific producer
|
|
867
|
+
*/
|
|
868
|
+
async addJob(producerClassName, jobData, opts = {}) {
|
|
869
|
+
const producer = this.getProducer(producerClassName);
|
|
870
|
+
return await producer.addJobWithName(jobData, opts);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Add bulk jobs using a specific producer
|
|
874
|
+
*/
|
|
875
|
+
async addBulkJobs(producerClassName, jobs) {
|
|
876
|
+
const producer = this.getProducer(producerClassName);
|
|
877
|
+
return await producer.addBulkJobs(jobs);
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Get status of all producers
|
|
881
|
+
*/
|
|
882
|
+
async getStatus() {
|
|
883
|
+
const statusPromises = Array.from(this.activeProducers.entries()).map(
|
|
884
|
+
async ([name, { instance }]) => {
|
|
885
|
+
try {
|
|
886
|
+
const status = await instance.getStatus();
|
|
887
|
+
return {
|
|
888
|
+
name,
|
|
889
|
+
queueId: instance.config?.id || "unknown",
|
|
890
|
+
isActive: !!instance.queue,
|
|
891
|
+
...status
|
|
892
|
+
};
|
|
893
|
+
} catch (error) {
|
|
894
|
+
return {
|
|
895
|
+
name,
|
|
896
|
+
queueId: instance.config?.id || "unknown",
|
|
897
|
+
isActive: false,
|
|
898
|
+
error: error.message
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
);
|
|
903
|
+
return await Promise.all(statusPromises);
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Gracefully shutdown all producers
|
|
907
|
+
*/
|
|
908
|
+
async shutdown() {
|
|
909
|
+
console.log("\u{1F6D1} Stopping all producers...");
|
|
910
|
+
const stopPromises = Array.from(this.activeProducers.entries()).map(
|
|
911
|
+
([name, { instance }]) => instance.stop().catch(
|
|
912
|
+
(err) => console.error(`\u274C Error stopping ${name}:`, err)
|
|
913
|
+
)
|
|
914
|
+
);
|
|
915
|
+
await Promise.all(stopPromises);
|
|
916
|
+
this.activeProducers.clear();
|
|
917
|
+
console.log("\u2705 All producers stopped");
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
__publicField(_ProducerManager, "instance", null);
|
|
921
|
+
var ProducerManager2 = _ProducerManager;
|
|
922
|
+
module.exports = { ProducerManager: ProducerManager2 };
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
|
|
722
926
|
// src/bullmq/BaseProducer.js
|
|
723
927
|
var require_BaseProducer = __commonJS({
|
|
724
928
|
"src/bullmq/BaseProducer.js"(exports, module) {
|
|
@@ -801,7 +1005,8 @@ var require_BaseProducer = __commonJS({
|
|
|
801
1005
|
async stop() {
|
|
802
1006
|
if (this.queue) {
|
|
803
1007
|
await this.queue.close();
|
|
804
|
-
|
|
1008
|
+
await this.queue.disconnect();
|
|
1009
|
+
console.log(`\u{1F6D1} ${this.constructor.name} queue closed & disconnected`);
|
|
805
1010
|
}
|
|
806
1011
|
}
|
|
807
1012
|
};
|
|
@@ -861,7 +1066,8 @@ var require_BaseWorker = __commonJS({
|
|
|
861
1066
|
async stop() {
|
|
862
1067
|
if (this.worker) {
|
|
863
1068
|
await this.worker.close();
|
|
864
|
-
|
|
1069
|
+
await this.worker.disconnect();
|
|
1070
|
+
console.log(`\u{1F6D1} ${this.constructor.name} stopped & disconnected`);
|
|
865
1071
|
}
|
|
866
1072
|
}
|
|
867
1073
|
};
|
|
@@ -896,7 +1102,7 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
896
1102
|
concurrency: 1,
|
|
897
1103
|
// Process jobs one at a time to avoid race conditions
|
|
898
1104
|
limiter: {
|
|
899
|
-
max:
|
|
1105
|
+
max: 5,
|
|
900
1106
|
// Max 10 jobs per...
|
|
901
1107
|
duration: 6e4
|
|
902
1108
|
// ...60 seconds (rate limiting)
|
|
@@ -967,9 +1173,8 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
967
1173
|
},
|
|
968
1174
|
workerConfig: {
|
|
969
1175
|
concurrency: 1,
|
|
970
|
-
// Process 10 jobs at once for chunk processing
|
|
971
1176
|
limiter: {
|
|
972
|
-
max:
|
|
1177
|
+
max: 15,
|
|
973
1178
|
// Max 50 jobs per...
|
|
974
1179
|
duration: 6e4
|
|
975
1180
|
// ...60 seconds (higher throughput for chunking)
|
|
@@ -1013,7 +1218,36 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
1013
1218
|
}
|
|
1014
1219
|
},
|
|
1015
1220
|
workerConfig: {
|
|
1016
|
-
concurrency: 1
|
|
1221
|
+
concurrency: 1,
|
|
1222
|
+
limiter: {
|
|
1223
|
+
max: 15,
|
|
1224
|
+
// (lets always keep this same as content enhance & embed since it comes immediately after)
|
|
1225
|
+
duration: 6e4
|
|
1226
|
+
// ...60 seconds (higher throughput for chunking)
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
},
|
|
1230
|
+
ANNOS_ELASTIC_SYNC_QUEUE: {
|
|
1231
|
+
id: "annos-elastic-sync-queue",
|
|
1232
|
+
queueConfig: {
|
|
1233
|
+
defaultJobOptions: {
|
|
1234
|
+
attempts: 3,
|
|
1235
|
+
backoff: {
|
|
1236
|
+
type: "exponential",
|
|
1237
|
+
delay: 2e3
|
|
1238
|
+
},
|
|
1239
|
+
removeOnComplete: 50,
|
|
1240
|
+
removeOnFail: 100
|
|
1241
|
+
}
|
|
1242
|
+
},
|
|
1243
|
+
workerConfig: {
|
|
1244
|
+
concurrency: 5,
|
|
1245
|
+
limiter: {
|
|
1246
|
+
max: 15,
|
|
1247
|
+
// (lets always keep this same as content enhance & embed since it comes immediately after)
|
|
1248
|
+
duration: 6e4
|
|
1249
|
+
// ...60 seconds (higher throughput for chunking)
|
|
1250
|
+
}
|
|
1017
1251
|
}
|
|
1018
1252
|
}
|
|
1019
1253
|
};
|
|
@@ -1331,6 +1565,7 @@ var _extractBlocksFromSomeBuilders = ({
|
|
|
1331
1565
|
|
|
1332
1566
|
// src/node.ts
|
|
1333
1567
|
var import_MongoConnector2 = __toESM(require_MongoConnector());
|
|
1568
|
+
var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
|
|
1334
1569
|
init_getDbByTenant();
|
|
1335
1570
|
|
|
1336
1571
|
// src/db/getGlobalConfig.ts
|
|
@@ -1470,13 +1705,16 @@ var getAIConfigs = async ({
|
|
|
1470
1705
|
// src/node.ts
|
|
1471
1706
|
init_models();
|
|
1472
1707
|
var import_WorkerManager = __toESM(require_WorkerManager());
|
|
1708
|
+
var import_ProducerManager = __toESM(require_ProducerManager());
|
|
1473
1709
|
var import_BaseProducer = __toESM(require_BaseProducer());
|
|
1474
1710
|
var import_BaseWorker = __toESM(require_BaseWorker());
|
|
1475
1711
|
var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
|
|
1476
1712
|
var export_BaseProducer = import_BaseProducer.BaseProducer;
|
|
1477
1713
|
var export_BaseWorker = import_BaseWorker.BaseWorker;
|
|
1714
|
+
var export_ElasticSearchConnector = import_ElasticSearchConnector.ElasticSearchConnector;
|
|
1478
1715
|
var export_GET_GLOBAL_BULLMQ_CONFIG = import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG;
|
|
1479
1716
|
var export_MongoConnector = import_MongoConnector2.MongoConnector;
|
|
1717
|
+
var export_ProducerManager = import_ProducerManager.ProducerManager;
|
|
1480
1718
|
var export_WorkerManager = import_WorkerManager.WorkerManager;
|
|
1481
1719
|
var export_getAIChatModelByTenant = import_getModelByTenant.getAIChatModelByTenant;
|
|
1482
1720
|
var export_getAnnotationsModelByTenant = import_getModelByTenant.getAnnotationsModelByTenant;
|
|
@@ -1488,9 +1726,11 @@ export {
|
|
|
1488
1726
|
Annotations_default as AnnotationSchema,
|
|
1489
1727
|
export_BaseProducer as BaseProducer,
|
|
1490
1728
|
export_BaseWorker as BaseWorker,
|
|
1729
|
+
export_ElasticSearchConnector as ElasticSearchConnector,
|
|
1491
1730
|
export_GET_GLOBAL_BULLMQ_CONFIG as GET_GLOBAL_BULLMQ_CONFIG,
|
|
1492
1731
|
export_MongoConnector as MongoConnector,
|
|
1493
1732
|
PlatformConfigs_default as PlatformConfigsSchema,
|
|
1733
|
+
export_ProducerManager as ProducerManager,
|
|
1494
1734
|
Tpl_default as TplSchema,
|
|
1495
1735
|
export_WorkerManager as WorkerManager,
|
|
1496
1736
|
connectToRedis,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.5.
|
|
6
|
+
"version": "1.5.6",
|
|
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",
|