@axiom-lattice/gateway 2.1.5 → 2.1.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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +10 -0
- package/dist/index.js +103 -275
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -280
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
- package/src/controllers/agent_task.ts +1 -1
- package/src/services/agent_task_consumer.ts +86 -12
- package/src/services/queue_service.ts +70 -10
- package/src/services/AgentManager.ts +0 -46
- package/src/services/agent_task_types.ts +0 -2
- package/src/services/event_bus.ts +0 -62
- package/src/services/queue_service_memory.ts +0 -85
- package/src/services/queue_service_redis.ts +0 -116
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @axiom-lattice/gateway@2.1.
|
|
2
|
+
> @axiom-lattice/gateway@2.1.6 build /home/runner/work/agentic/agentic/packages/gateway
|
|
3
3
|
> tsup src/index.ts --format cjs,esm --dts --clean --sourcemap
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
[34mCLI[39m Cleaning output folder
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
13
|
-
[32mCJS[39m [1mdist/index.js.map [22m[
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
15
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
16
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[
|
|
17
|
-
[32mESM[39m ⚡️ Build success in
|
|
12
|
+
[32mCJS[39m [1mdist/index.js [22m[32m38.84 KB[39m
|
|
13
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m76.54 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 142ms
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m36.61 KB[39m
|
|
16
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m76.45 KB[39m
|
|
17
|
+
[32mESM[39m ⚡️ Build success in 149ms
|
|
18
18
|
[34mDTS[39m Build start
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 5936ms
|
|
20
20
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.32 KB[39m
|
|
21
21
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.32 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @axiom-lattice/gateway
|
|
2
2
|
|
|
3
|
+
## 2.1.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ee11051: run subagent in another thread
|
|
8
|
+
- Updated dependencies [ee11051]
|
|
9
|
+
- @axiom-lattice/protocols@2.1.2
|
|
10
|
+
- @axiom-lattice/core@2.1.4
|
|
11
|
+
- @axiom-lattice/queue-redis@1.0.1
|
|
12
|
+
|
|
3
13
|
## 2.1.5
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -534,268 +534,8 @@ var getAgentGraph = async (request, reply) => {
|
|
|
534
534
|
}
|
|
535
535
|
};
|
|
536
536
|
|
|
537
|
-
// src/services/agent_task_types.ts
|
|
538
|
-
var AGENT_TASK_EVENT = "agent:execute";
|
|
539
|
-
|
|
540
|
-
// src/services/event_bus.ts
|
|
541
|
-
var import_events = require("events");
|
|
542
|
-
|
|
543
|
-
// src/services/queue_service_memory.ts
|
|
544
|
-
var queue_service_memory_exports = {};
|
|
545
|
-
__export(queue_service_memory_exports, {
|
|
546
|
-
popAgentTaskFromQueue: () => popAgentTaskFromQueue,
|
|
547
|
-
pushAgentTaskToQueue: () => pushAgentTaskToQueue
|
|
548
|
-
});
|
|
549
|
-
var queue_name = process.env.QUEUE_NAME || "tasks";
|
|
550
|
-
var queues = /* @__PURE__ */ new Map();
|
|
551
|
-
var ensureQueue = (queueName) => {
|
|
552
|
-
if (!queues.has(queueName)) {
|
|
553
|
-
queues.set(queueName, []);
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
var sendToQueue = async (queueName, message) => {
|
|
557
|
-
try {
|
|
558
|
-
ensureQueue(queueName);
|
|
559
|
-
const queue = queues.get(queueName);
|
|
560
|
-
queue.unshift(message);
|
|
561
|
-
const result = queue.length;
|
|
562
|
-
console.log("lPush (memory)", result);
|
|
563
|
-
return { data: result, error: null };
|
|
564
|
-
} catch (error) {
|
|
565
|
-
console.error(error);
|
|
566
|
-
return { data: null, error };
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
var popFromQueue = async (queueName) => {
|
|
570
|
-
try {
|
|
571
|
-
ensureQueue(queueName);
|
|
572
|
-
const queue = queues.get(queueName);
|
|
573
|
-
const message = queue.pop();
|
|
574
|
-
if (message) {
|
|
575
|
-
return { data: message, error: null };
|
|
576
|
-
}
|
|
577
|
-
return { data: null, error: null };
|
|
578
|
-
} catch (error) {
|
|
579
|
-
console.error(error);
|
|
580
|
-
return { data: null, error };
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
var createTenantQueue = async () => {
|
|
584
|
-
try {
|
|
585
|
-
ensureQueue(queue_name);
|
|
586
|
-
const queue = queues.get(queue_name);
|
|
587
|
-
const exists = queue !== void 0;
|
|
588
|
-
return { success: true, queue_name };
|
|
589
|
-
} catch (error) {
|
|
590
|
-
console.error(error);
|
|
591
|
-
return { success: false, error };
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
var pushAgentTaskToQueue = async (agentTask) => {
|
|
595
|
-
const tenantId = agentTask["x-tenant-id"];
|
|
596
|
-
try {
|
|
597
|
-
await createTenantQueue();
|
|
598
|
-
const result = await sendToQueue(`${queue_name}`, agentTask);
|
|
599
|
-
return result;
|
|
600
|
-
} catch (error) {
|
|
601
|
-
console.error(error);
|
|
602
|
-
return null;
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
var popAgentTaskFromQueue = async () => {
|
|
606
|
-
const result = await popFromQueue(`${queue_name}`);
|
|
607
|
-
return result;
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
// src/services/queue_service_redis.ts
|
|
611
|
-
var queue_service_redis_exports = {};
|
|
612
|
-
__export(queue_service_redis_exports, {
|
|
613
|
-
popAgentTaskFromQueue: () => popAgentTaskFromQueue2,
|
|
614
|
-
pushAgentTaskToQueue: () => pushAgentTaskToQueue2
|
|
615
|
-
});
|
|
616
|
-
var import_redis = require("redis");
|
|
617
|
-
var queue_name2 = process.env.QUEUE_NAME || "tasks";
|
|
618
|
-
var redisClient = null;
|
|
619
|
-
var isConnecting = false;
|
|
620
|
-
var connectionPromise = null;
|
|
621
|
-
var getRedisClient = async () => {
|
|
622
|
-
if (redisClient?.isOpen) {
|
|
623
|
-
return redisClient;
|
|
624
|
-
}
|
|
625
|
-
if (isConnecting && connectionPromise) {
|
|
626
|
-
await connectionPromise;
|
|
627
|
-
if (redisClient?.isOpen) {
|
|
628
|
-
return redisClient;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
isConnecting = true;
|
|
632
|
-
connectionPromise = (async () => {
|
|
633
|
-
try {
|
|
634
|
-
const redisOptions = {
|
|
635
|
-
url: process.env.REDIS_URL || "redis://localhost:6379",
|
|
636
|
-
password: process.env.REDIS_PASSWORD
|
|
637
|
-
};
|
|
638
|
-
redisClient = (0, import_redis.createClient)(redisOptions);
|
|
639
|
-
redisClient.on(
|
|
640
|
-
"error",
|
|
641
|
-
(err) => console.error("Redis Client Error", err)
|
|
642
|
-
);
|
|
643
|
-
await redisClient.connect();
|
|
644
|
-
console.log("Redis connection successful");
|
|
645
|
-
isConnecting = false;
|
|
646
|
-
} catch (error) {
|
|
647
|
-
console.error("Redis connection failed:", error);
|
|
648
|
-
isConnecting = false;
|
|
649
|
-
throw error;
|
|
650
|
-
}
|
|
651
|
-
})();
|
|
652
|
-
await connectionPromise;
|
|
653
|
-
return redisClient;
|
|
654
|
-
};
|
|
655
|
-
var sendToQueue2 = async (queueName, message) => {
|
|
656
|
-
try {
|
|
657
|
-
const client = await getRedisClient();
|
|
658
|
-
const result = await client.lPush(queueName, JSON.stringify(message));
|
|
659
|
-
console.log("lPush", result);
|
|
660
|
-
return { data: result, error: null };
|
|
661
|
-
} catch (error) {
|
|
662
|
-
console.error(error);
|
|
663
|
-
return { data: null, error };
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
var popFromQueue2 = async (queueName) => {
|
|
667
|
-
try {
|
|
668
|
-
const client = await getRedisClient();
|
|
669
|
-
const message = await client.rPop(queueName);
|
|
670
|
-
if (message) {
|
|
671
|
-
return { data: JSON.parse(message), error: null };
|
|
672
|
-
}
|
|
673
|
-
return { data: null, error: null };
|
|
674
|
-
} catch (error) {
|
|
675
|
-
console.error(error);
|
|
676
|
-
return { data: null, error };
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
var createTenantQueue2 = async () => {
|
|
680
|
-
try {
|
|
681
|
-
const client = await getRedisClient();
|
|
682
|
-
const exists = await client.exists(queue_name2);
|
|
683
|
-
return { success: true, queue_name: queue_name2 };
|
|
684
|
-
} catch (error) {
|
|
685
|
-
console.error(error);
|
|
686
|
-
return { success: false, error };
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
var pushAgentTaskToQueue2 = async (agentTask) => {
|
|
690
|
-
const tenantId = agentTask["x-tenant-id"];
|
|
691
|
-
try {
|
|
692
|
-
await createTenantQueue2();
|
|
693
|
-
const result = await sendToQueue2(`${queue_name2}`, agentTask);
|
|
694
|
-
return result;
|
|
695
|
-
} catch (error) {
|
|
696
|
-
console.error(error);
|
|
697
|
-
return null;
|
|
698
|
-
}
|
|
699
|
-
};
|
|
700
|
-
var popAgentTaskFromQueue2 = async () => {
|
|
701
|
-
const result = await popFromQueue2(`${queue_name2}`);
|
|
702
|
-
return result;
|
|
703
|
-
};
|
|
704
|
-
|
|
705
|
-
// src/services/queue_service.ts
|
|
706
|
-
var queueServiceType = process.env.QUEUE_SERVICE_TYPE || "memory";
|
|
707
|
-
var setQueueServiceType = (type) => {
|
|
708
|
-
queueServiceType = type;
|
|
709
|
-
console.log(`Queue service type set to: ${type}`);
|
|
710
|
-
};
|
|
711
|
-
var getQueueService = () => {
|
|
712
|
-
return queueServiceType === "redis" ? queue_service_redis_exports : queue_service_memory_exports;
|
|
713
|
-
};
|
|
714
|
-
var pushAgentTaskToQueue3 = async (agentTask) => {
|
|
715
|
-
const service = getQueueService();
|
|
716
|
-
return service.pushAgentTaskToQueue(agentTask);
|
|
717
|
-
};
|
|
718
|
-
var popAgentTaskFromQueue3 = async () => {
|
|
719
|
-
const service = getQueueService();
|
|
720
|
-
return service.popAgentTaskFromQueue();
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
// src/services/event_bus.ts
|
|
724
|
-
var EventBus = class {
|
|
725
|
-
constructor() {
|
|
726
|
-
this.emitter = new import_events.EventEmitter();
|
|
727
|
-
this.emitter.setMaxListeners(100);
|
|
728
|
-
}
|
|
729
|
-
/**
|
|
730
|
-
* 发布事件
|
|
731
|
-
* @param eventName 事件名称
|
|
732
|
-
* @param data 事件数据
|
|
733
|
-
*/
|
|
734
|
-
publish(eventName, data, useQueue = false) {
|
|
735
|
-
if (useQueue) {
|
|
736
|
-
pushAgentTaskToQueue3(data);
|
|
737
|
-
} else {
|
|
738
|
-
this.emitter.emit(eventName, data);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* 订阅事件
|
|
743
|
-
* @param eventName 事件名称
|
|
744
|
-
* @param callback 回调函数
|
|
745
|
-
*/
|
|
746
|
-
subscribe(eventName, callback) {
|
|
747
|
-
this.emitter.on(eventName, callback);
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* 取消订阅事件
|
|
751
|
-
* @param eventName 事件名称
|
|
752
|
-
* @param callback 回调函数
|
|
753
|
-
*/
|
|
754
|
-
unsubscribe(eventName, callback) {
|
|
755
|
-
this.emitter.off(eventName, callback);
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* 只订阅一次事件
|
|
759
|
-
* @param eventName 事件名称
|
|
760
|
-
* @param callback 回调函数
|
|
761
|
-
*/
|
|
762
|
-
subscribeOnce(eventName, callback) {
|
|
763
|
-
this.emitter.once(eventName, callback);
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
var eventBus = new EventBus();
|
|
767
|
-
var event_bus_default = eventBus;
|
|
768
|
-
|
|
769
|
-
// src/services/AgentManager.ts
|
|
770
|
-
var AgentManager = class _AgentManager {
|
|
771
|
-
constructor() {
|
|
772
|
-
this.agents = [];
|
|
773
|
-
}
|
|
774
|
-
static getInstance() {
|
|
775
|
-
if (!_AgentManager.instance) {
|
|
776
|
-
_AgentManager.instance = new _AgentManager();
|
|
777
|
-
}
|
|
778
|
-
return _AgentManager.instance;
|
|
779
|
-
}
|
|
780
|
-
callAgentInQueue(queue) {
|
|
781
|
-
return new Promise((resolve, reject) => {
|
|
782
|
-
try {
|
|
783
|
-
event_bus_default.publish(
|
|
784
|
-
AGENT_TASK_EVENT,
|
|
785
|
-
{
|
|
786
|
-
...queue
|
|
787
|
-
},
|
|
788
|
-
true
|
|
789
|
-
);
|
|
790
|
-
resolve(true);
|
|
791
|
-
} catch (error) {
|
|
792
|
-
reject(error);
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
|
|
798
537
|
// src/controllers/agent_task.ts
|
|
538
|
+
var import_core2 = require("@axiom-lattice/core");
|
|
799
539
|
var triggerAgentTask = async (request, reply) => {
|
|
800
540
|
try {
|
|
801
541
|
const { assistant_id, thread_id, input, command } = request.body;
|
|
@@ -814,7 +554,7 @@ var triggerAgentTask = async (request, reply) => {
|
|
|
814
554
|
});
|
|
815
555
|
return;
|
|
816
556
|
}
|
|
817
|
-
const agentManager = AgentManager.getInstance();
|
|
557
|
+
const agentManager = import_core2.AgentManager.getInstance();
|
|
818
558
|
const result = await agentManager.callAgentInQueue({
|
|
819
559
|
assistant_id,
|
|
820
560
|
thread_id,
|
|
@@ -1248,7 +988,52 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
|
|
|
1248
988
|
await app2.register(import_swagger_ui.default, swaggerUiConfig);
|
|
1249
989
|
};
|
|
1250
990
|
|
|
991
|
+
// src/services/queue_service.ts
|
|
992
|
+
var import_core3 = require("@axiom-lattice/core");
|
|
993
|
+
var import_protocols = require("@axiom-lattice/protocols");
|
|
994
|
+
var import_queue_redis = require("@axiom-lattice/queue-redis");
|
|
995
|
+
var DEFAULT_QUEUE_KEY = "default";
|
|
996
|
+
var queueServiceType = process.env.QUEUE_SERVICE_TYPE || "memory";
|
|
997
|
+
var setQueueServiceType = (type) => {
|
|
998
|
+
queueServiceType = type;
|
|
999
|
+
console.log(`Queue service type set to: ${type}`);
|
|
1000
|
+
const queueName = process.env.QUEUE_NAME || "tasks";
|
|
1001
|
+
const config = {
|
|
1002
|
+
name: "Default Queue Service",
|
|
1003
|
+
description: `Default ${type} queue service`,
|
|
1004
|
+
type: type === "redis" ? import_protocols.QueueType.REDIS : import_protocols.QueueType.MEMORY,
|
|
1005
|
+
queueName,
|
|
1006
|
+
options: type === "redis" ? {
|
|
1007
|
+
redisUrl: process.env.REDIS_URL,
|
|
1008
|
+
redisPassword: process.env.REDIS_PASSWORD
|
|
1009
|
+
} : void 0
|
|
1010
|
+
};
|
|
1011
|
+
if (import_core3.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
1012
|
+
import_core3.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
|
|
1013
|
+
}
|
|
1014
|
+
let client;
|
|
1015
|
+
if (type === "redis") {
|
|
1016
|
+
client = new import_queue_redis.RedisQueueClient(queueName, {
|
|
1017
|
+
redisUrl: process.env.REDIS_URL,
|
|
1018
|
+
redisPassword: process.env.REDIS_PASSWORD
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
(0, import_core3.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
|
|
1022
|
+
};
|
|
1023
|
+
var getQueueService = () => {
|
|
1024
|
+
if (!import_core3.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
1025
|
+
setQueueServiceType(queueServiceType);
|
|
1026
|
+
}
|
|
1027
|
+
return (0, import_core3.getQueueLattice)(DEFAULT_QUEUE_KEY);
|
|
1028
|
+
};
|
|
1029
|
+
var popAgentTaskFromQueue = async () => {
|
|
1030
|
+
const queue = getQueueService();
|
|
1031
|
+
const result = await queue.pop();
|
|
1032
|
+
return result;
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1251
1035
|
// src/services/agent_task_consumer.ts
|
|
1036
|
+
var import_core4 = require("@axiom-lattice/core");
|
|
1252
1037
|
var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
1253
1038
|
const {
|
|
1254
1039
|
assistant_id,
|
|
@@ -1284,16 +1069,59 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
1284
1069
|
if (!response.ok) {
|
|
1285
1070
|
throw new Error(`API\u8BF7\u6C42\u5931\u8D25: ${response.status} ${response.statusText}`);
|
|
1286
1071
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1072
|
+
const contentType = response.headers.get("content-type");
|
|
1073
|
+
if (contentType?.includes("text/event-stream")) {
|
|
1074
|
+
const reader = response.body?.getReader();
|
|
1075
|
+
const decoder = new TextDecoder();
|
|
1076
|
+
if (!reader) {
|
|
1077
|
+
throw new Error("Response body is not readable");
|
|
1078
|
+
}
|
|
1079
|
+
let buffer = "";
|
|
1080
|
+
let streamEnded = false;
|
|
1081
|
+
try {
|
|
1082
|
+
while (true) {
|
|
1083
|
+
const { done, value } = await reader.read();
|
|
1084
|
+
if (done) {
|
|
1085
|
+
streamEnded = true;
|
|
1086
|
+
console.log(
|
|
1087
|
+
`SSE\u6D41\u5DF2\u7ED3\u675F [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
1088
|
+
);
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
} catch (streamError) {
|
|
1093
|
+
console.error("Error reading SSE stream:", streamError);
|
|
1094
|
+
throw streamError;
|
|
1095
|
+
} finally {
|
|
1096
|
+
reader.releaseLock();
|
|
1097
|
+
}
|
|
1098
|
+
if (callback_event) {
|
|
1099
|
+
const state = await agent_state({ assistant_id, thread_id });
|
|
1100
|
+
import_core4.eventBus.publish(callback_event, {
|
|
1101
|
+
success: true,
|
|
1102
|
+
state,
|
|
1103
|
+
config: { assistant_id, thread_id, tenant_id }
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
console.log(
|
|
1107
|
+
`\u4EFB\u52A1\u5904\u7406\u6210\u529F [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
1108
|
+
);
|
|
1109
|
+
return true;
|
|
1110
|
+
} else {
|
|
1111
|
+
await response.text();
|
|
1112
|
+
if (callback_event) {
|
|
1113
|
+
const state = await agent_state({ assistant_id, thread_id });
|
|
1114
|
+
import_core4.eventBus.publish(callback_event, {
|
|
1115
|
+
success: true,
|
|
1116
|
+
state,
|
|
1117
|
+
config: { assistant_id, thread_id, tenant_id }
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
console.log(
|
|
1121
|
+
`\u4EFB\u52A1\u5904\u7406\u6210\u529F [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
1122
|
+
);
|
|
1123
|
+
return true;
|
|
1292
1124
|
}
|
|
1293
|
-
console.log(
|
|
1294
|
-
`\u4EFB\u52A1\u5904\u7406\u6210\u529F [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
1295
|
-
);
|
|
1296
|
-
return true;
|
|
1297
1125
|
} catch (error) {
|
|
1298
1126
|
console.error(
|
|
1299
1127
|
`Agent\u4EFB\u52A1\u6267\u884C\u5931\u8D25: ${assistant_id}, \u7EBF\u7A0B: ${thread_id}`,
|
|
@@ -1310,7 +1138,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
1310
1138
|
return handleAgentTask(taskRequest, nextRetryCount);
|
|
1311
1139
|
}
|
|
1312
1140
|
if (callback_event) {
|
|
1313
|
-
|
|
1141
|
+
import_core4.eventBus.publish(callback_event, {
|
|
1314
1142
|
success: false,
|
|
1315
1143
|
error: error instanceof Error ? error.message : String(error),
|
|
1316
1144
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -1348,7 +1176,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
1348
1176
|
* 初始化事件监听和队列轮询
|
|
1349
1177
|
*/
|
|
1350
1178
|
initialize() {
|
|
1351
|
-
|
|
1179
|
+
import_core4.eventBus.subscribe(import_core4.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
|
|
1352
1180
|
this.startPollingQueue();
|
|
1353
1181
|
console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
|
|
1354
1182
|
}
|
|
@@ -1391,7 +1219,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
1391
1219
|
*/
|
|
1392
1220
|
async processNextTask() {
|
|
1393
1221
|
try {
|
|
1394
|
-
const queueResult = await
|
|
1222
|
+
const queueResult = await popAgentTaskFromQueue();
|
|
1395
1223
|
if (queueResult && queueResult.data) {
|
|
1396
1224
|
const taskItem = queueResult.data;
|
|
1397
1225
|
if (taskItem && typeof taskItem === "object") {
|
|
@@ -1467,7 +1295,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
1467
1295
|
handleAgentTask(taskRequest).catch((error) => {
|
|
1468
1296
|
console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
|
|
1469
1297
|
if (taskRequest.callback_event) {
|
|
1470
|
-
|
|
1298
|
+
import_core4.eventBus.publish(taskRequest.callback_event, {
|
|
1471
1299
|
success: false,
|
|
1472
1300
|
error: error instanceof Error ? error.message : String(error),
|
|
1473
1301
|
config: {
|