@axiom-lattice/gateway 2.1.11 → 2.1.12
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 +6 -0
- package/dist/index.js +431 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +417 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/controllers/assistant.ts +274 -3
- package/src/controllers/threads.ts +189 -0
- package/src/routes/index.ts +54 -1
- package/src/stores/assistant_store.ts +82 -0
- package/src/stores/thread_store.ts +115 -0
- package/src/types/index.ts +14 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @axiom-lattice/gateway@2.1.
|
|
2
|
+
> @axiom-lattice/gateway@2.1.12 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
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
12
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m46.92 KB[39m
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m100.58 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 131ms
|
|
15
|
+
[32mCJS[39m [1mdist/index.js [22m[32m49.24 KB[39m
|
|
16
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m100.67 KB[39m
|
|
17
|
+
[32mCJS[39m ⚡️ Build success in 131ms
|
|
18
18
|
[34mDTS[39m Build start
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 7072ms
|
|
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
package/dist/index.js
CHANGED
|
@@ -248,6 +248,226 @@ async function resume_stream({
|
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
+
// src/stores/assistant_store.ts
|
|
252
|
+
var AssistantStore = class {
|
|
253
|
+
constructor() {
|
|
254
|
+
this.assistants = /* @__PURE__ */ new Map();
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get all assistants
|
|
258
|
+
*/
|
|
259
|
+
getAllAssistants() {
|
|
260
|
+
return Array.from(this.assistants.values());
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Get assistant by ID
|
|
264
|
+
*/
|
|
265
|
+
getAssistantById(id) {
|
|
266
|
+
return this.assistants.get(id);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Create a new assistant
|
|
270
|
+
*/
|
|
271
|
+
createAssistant(id, data) {
|
|
272
|
+
const now = /* @__PURE__ */ new Date();
|
|
273
|
+
const assistant = {
|
|
274
|
+
id,
|
|
275
|
+
name: data.name,
|
|
276
|
+
description: data.description,
|
|
277
|
+
graphDefinition: data.graphDefinition,
|
|
278
|
+
createdAt: now,
|
|
279
|
+
updatedAt: now
|
|
280
|
+
};
|
|
281
|
+
this.assistants.set(id, assistant);
|
|
282
|
+
return assistant;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Update an existing assistant
|
|
286
|
+
*/
|
|
287
|
+
updateAssistant(id, updates) {
|
|
288
|
+
const existing = this.assistants.get(id);
|
|
289
|
+
if (!existing) {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
const updated = {
|
|
293
|
+
...existing,
|
|
294
|
+
...updates,
|
|
295
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
296
|
+
};
|
|
297
|
+
this.assistants.set(id, updated);
|
|
298
|
+
return updated;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Delete an assistant by ID
|
|
302
|
+
*/
|
|
303
|
+
deleteAssistant(id) {
|
|
304
|
+
return this.assistants.delete(id);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Check if assistant exists
|
|
308
|
+
*/
|
|
309
|
+
hasAssistant(id) {
|
|
310
|
+
return this.assistants.has(id);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
var assistantStore = new AssistantStore();
|
|
314
|
+
|
|
315
|
+
// src/controllers/assistant.ts
|
|
316
|
+
var import_crypto = require("crypto");
|
|
317
|
+
var import_core2 = require("@axiom-lattice/core");
|
|
318
|
+
function convertAgentConfigToAssistant(config) {
|
|
319
|
+
return {
|
|
320
|
+
id: config.key,
|
|
321
|
+
name: config.name,
|
|
322
|
+
description: config.description,
|
|
323
|
+
graphDefinition: config,
|
|
324
|
+
// Store the full config as graphDefinition
|
|
325
|
+
createdAt: /* @__PURE__ */ new Date(0),
|
|
326
|
+
// Code-configured agents have no creation date
|
|
327
|
+
updatedAt: /* @__PURE__ */ new Date(0)
|
|
328
|
+
// Code-configured agents have no update date
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
async function getAssistantList(request, reply) {
|
|
332
|
+
const agentConfigs = await (0, import_core2.getAllAgentConfigs)();
|
|
333
|
+
const codeConfiguredAssistants = agentConfigs.map(
|
|
334
|
+
convertAgentConfigToAssistant
|
|
335
|
+
);
|
|
336
|
+
const storedAssistants = assistantStore.getAllAssistants();
|
|
337
|
+
const assistantMap = /* @__PURE__ */ new Map();
|
|
338
|
+
codeConfiguredAssistants.forEach((assistant) => {
|
|
339
|
+
assistantMap.set(assistant.id, assistant);
|
|
340
|
+
});
|
|
341
|
+
storedAssistants.forEach((assistant) => {
|
|
342
|
+
assistantMap.set(assistant.id, assistant);
|
|
343
|
+
});
|
|
344
|
+
const allAssistants = Array.from(assistantMap.values());
|
|
345
|
+
return {
|
|
346
|
+
success: true,
|
|
347
|
+
message: "Successfully retrieved assistant list",
|
|
348
|
+
data: {
|
|
349
|
+
records: allAssistants,
|
|
350
|
+
total: allAssistants.length
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
async function getAssistant(request, reply) {
|
|
355
|
+
const { id } = request.params;
|
|
356
|
+
let assistant = assistantStore.getAssistantById(id);
|
|
357
|
+
if (!assistant) {
|
|
358
|
+
const agentConfigs = await (0, import_core2.getAllAgentConfigs)();
|
|
359
|
+
const agentConfig = agentConfigs.find((config) => config.key === id);
|
|
360
|
+
if (agentConfig) {
|
|
361
|
+
assistant = convertAgentConfigToAssistant(agentConfig);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (!assistant) {
|
|
365
|
+
return reply.status(404).send({
|
|
366
|
+
success: false,
|
|
367
|
+
message: "Assistant not found"
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
success: true,
|
|
372
|
+
message: "Successfully retrieved assistant",
|
|
373
|
+
data: assistant
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
async function createAssistant(request, reply) {
|
|
377
|
+
const data = request.body;
|
|
378
|
+
if (!data.name) {
|
|
379
|
+
return reply.status(400).send({
|
|
380
|
+
success: false,
|
|
381
|
+
message: "name is required"
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
if (!data.graphDefinition) {
|
|
385
|
+
return reply.status(400).send({
|
|
386
|
+
success: false,
|
|
387
|
+
message: "graphDefinition is required"
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
const id = (0, import_crypto.randomUUID)();
|
|
391
|
+
const newAssistant = assistantStore.createAssistant(id, data);
|
|
392
|
+
return reply.status(201).send({
|
|
393
|
+
success: true,
|
|
394
|
+
message: "Successfully created assistant",
|
|
395
|
+
data: newAssistant
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
async function updateAssistant(request, reply) {
|
|
399
|
+
const { id } = request.params;
|
|
400
|
+
const updates = request.body;
|
|
401
|
+
const agentConfigs = await (0, import_core2.getAllAgentConfigs)();
|
|
402
|
+
const isCodeConfigured = agentConfigs.some((config) => config.key === id);
|
|
403
|
+
if (isCodeConfigured) {
|
|
404
|
+
return reply.status(403).send({
|
|
405
|
+
success: false,
|
|
406
|
+
message: "Cannot update code-configured assistant. Only stored assistants can be updated."
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
if (!assistantStore.hasAssistant(id)) {
|
|
410
|
+
return reply.status(404).send({
|
|
411
|
+
success: false,
|
|
412
|
+
message: "Assistant not found"
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
const updatedAssistant = assistantStore.updateAssistant(id, updates);
|
|
416
|
+
if (!updatedAssistant) {
|
|
417
|
+
return reply.status(500).send({
|
|
418
|
+
success: false,
|
|
419
|
+
message: "Failed to update assistant"
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
return {
|
|
423
|
+
success: true,
|
|
424
|
+
message: "Successfully updated assistant",
|
|
425
|
+
data: updatedAssistant
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
async function deleteAssistant(request, reply) {
|
|
429
|
+
const { id } = request.params;
|
|
430
|
+
const agentConfigs = await (0, import_core2.getAllAgentConfigs)();
|
|
431
|
+
const isCodeConfigured = agentConfigs.some((config) => config.key === id);
|
|
432
|
+
if (isCodeConfigured) {
|
|
433
|
+
return reply.status(403).send({
|
|
434
|
+
success: false,
|
|
435
|
+
message: "Cannot delete code-configured assistant. Only stored assistants can be deleted."
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
if (!assistantStore.hasAssistant(id)) {
|
|
439
|
+
return reply.status(404).send({
|
|
440
|
+
success: false,
|
|
441
|
+
message: "Assistant not found"
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
const deleted = assistantStore.deleteAssistant(id);
|
|
445
|
+
if (!deleted) {
|
|
446
|
+
return reply.status(500).send({
|
|
447
|
+
success: false,
|
|
448
|
+
message: "Failed to delete assistant"
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
success: true,
|
|
453
|
+
message: "Successfully deleted assistant"
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
var getAgentGraph = async (request, reply) => {
|
|
457
|
+
try {
|
|
458
|
+
const { assistantId } = request.params;
|
|
459
|
+
const imageData = await draw_graph(assistantId);
|
|
460
|
+
reply.header("Content-Type", "application/json").send({
|
|
461
|
+
image: imageData
|
|
462
|
+
});
|
|
463
|
+
} catch (error) {
|
|
464
|
+
reply.status(500).send({
|
|
465
|
+
success: false,
|
|
466
|
+
error: error.message || "Failed to get agent graph"
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
251
471
|
// src/controllers/run.ts
|
|
252
472
|
var import_uuid2 = require("uuid");
|
|
253
473
|
var createRun = async (request, reply) => {
|
|
@@ -515,24 +735,8 @@ var clearMemory = async (request, reply) => {
|
|
|
515
735
|
}
|
|
516
736
|
};
|
|
517
737
|
|
|
518
|
-
// src/controllers/assistant.ts
|
|
519
|
-
var getAgentGraph = async (request, reply) => {
|
|
520
|
-
try {
|
|
521
|
-
const { assistantId } = request.params;
|
|
522
|
-
const imageData = await draw_graph(assistantId);
|
|
523
|
-
reply.header("Content-Type", "application/json").send({
|
|
524
|
-
image: imageData
|
|
525
|
-
});
|
|
526
|
-
} catch (error) {
|
|
527
|
-
reply.status(500).send({
|
|
528
|
-
success: false,
|
|
529
|
-
error: error.message || "\u83B7\u53D6\u4EE3\u7406\u56FE\u8868\u5931\u8D25"
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
|
|
534
738
|
// src/controllers/agent_task.ts
|
|
535
|
-
var
|
|
739
|
+
var import_core3 = require("@axiom-lattice/core");
|
|
536
740
|
var triggerAgentTask = async (request, reply) => {
|
|
537
741
|
try {
|
|
538
742
|
const { assistant_id, thread_id, input, command } = request.body;
|
|
@@ -551,7 +755,7 @@ var triggerAgentTask = async (request, reply) => {
|
|
|
551
755
|
});
|
|
552
756
|
return;
|
|
553
757
|
}
|
|
554
|
-
const agentManager =
|
|
758
|
+
const agentManager = import_core3.AgentManager.getInstance();
|
|
555
759
|
const result = await agentManager.callAgentInQueue({
|
|
556
760
|
assistant_id,
|
|
557
761
|
thread_id,
|
|
@@ -570,6 +774,184 @@ var triggerAgentTask = async (request, reply) => {
|
|
|
570
774
|
}
|
|
571
775
|
};
|
|
572
776
|
|
|
777
|
+
// src/stores/thread_store.ts
|
|
778
|
+
var ThreadStore = class {
|
|
779
|
+
constructor() {
|
|
780
|
+
// Map<assistantId, Map<threadId, Thread>>
|
|
781
|
+
this.threads = /* @__PURE__ */ new Map();
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Get all threads for a specific assistant
|
|
785
|
+
*/
|
|
786
|
+
getThreadsByAssistantId(assistantId) {
|
|
787
|
+
const assistantThreads = this.threads.get(assistantId);
|
|
788
|
+
if (!assistantThreads) {
|
|
789
|
+
return [];
|
|
790
|
+
}
|
|
791
|
+
return Array.from(assistantThreads.values());
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Get a thread by ID for a specific assistant
|
|
795
|
+
*/
|
|
796
|
+
getThreadById(assistantId, threadId) {
|
|
797
|
+
const assistantThreads = this.threads.get(assistantId);
|
|
798
|
+
if (!assistantThreads) {
|
|
799
|
+
return void 0;
|
|
800
|
+
}
|
|
801
|
+
return assistantThreads.get(threadId);
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Create a new thread for an assistant
|
|
805
|
+
*/
|
|
806
|
+
createThread(assistantId, threadId, data) {
|
|
807
|
+
const now = /* @__PURE__ */ new Date();
|
|
808
|
+
const thread = {
|
|
809
|
+
id: threadId,
|
|
810
|
+
assistantId,
|
|
811
|
+
metadata: data.metadata || {},
|
|
812
|
+
createdAt: now,
|
|
813
|
+
updatedAt: now
|
|
814
|
+
};
|
|
815
|
+
if (!this.threads.has(assistantId)) {
|
|
816
|
+
this.threads.set(assistantId, /* @__PURE__ */ new Map());
|
|
817
|
+
}
|
|
818
|
+
const assistantThreads = this.threads.get(assistantId);
|
|
819
|
+
assistantThreads.set(threadId, thread);
|
|
820
|
+
return thread;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Update an existing thread
|
|
824
|
+
*/
|
|
825
|
+
updateThread(assistantId, threadId, updates) {
|
|
826
|
+
const assistantThreads = this.threads.get(assistantId);
|
|
827
|
+
if (!assistantThreads) {
|
|
828
|
+
return null;
|
|
829
|
+
}
|
|
830
|
+
const existing = assistantThreads.get(threadId);
|
|
831
|
+
if (!existing) {
|
|
832
|
+
return null;
|
|
833
|
+
}
|
|
834
|
+
const updated = {
|
|
835
|
+
...existing,
|
|
836
|
+
metadata: {
|
|
837
|
+
...existing.metadata,
|
|
838
|
+
...updates.metadata || {}
|
|
839
|
+
},
|
|
840
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
841
|
+
};
|
|
842
|
+
assistantThreads.set(threadId, updated);
|
|
843
|
+
return updated;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Delete a thread by ID
|
|
847
|
+
*/
|
|
848
|
+
deleteThread(assistantId, threadId) {
|
|
849
|
+
const assistantThreads = this.threads.get(assistantId);
|
|
850
|
+
if (!assistantThreads) {
|
|
851
|
+
return false;
|
|
852
|
+
}
|
|
853
|
+
return assistantThreads.delete(threadId);
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Check if thread exists
|
|
857
|
+
*/
|
|
858
|
+
hasThread(assistantId, threadId) {
|
|
859
|
+
const assistantThreads = this.threads.get(assistantId);
|
|
860
|
+
if (!assistantThreads) {
|
|
861
|
+
return false;
|
|
862
|
+
}
|
|
863
|
+
return assistantThreads.has(threadId);
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
var threadStore = new ThreadStore();
|
|
867
|
+
|
|
868
|
+
// src/controllers/threads.ts
|
|
869
|
+
var import_crypto2 = require("crypto");
|
|
870
|
+
async function getThreadList(request, reply) {
|
|
871
|
+
const { assistantId } = request.params;
|
|
872
|
+
const threads = threadStore.getThreadsByAssistantId(assistantId);
|
|
873
|
+
return {
|
|
874
|
+
success: true,
|
|
875
|
+
message: "Successfully retrieved thread list",
|
|
876
|
+
data: {
|
|
877
|
+
records: threads,
|
|
878
|
+
total: threads.length
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
async function getThread(request, reply) {
|
|
883
|
+
const { assistantId, threadId } = request.params;
|
|
884
|
+
const thread = threadStore.getThreadById(assistantId, threadId);
|
|
885
|
+
if (!thread) {
|
|
886
|
+
return reply.status(404).send({
|
|
887
|
+
success: false,
|
|
888
|
+
message: "Thread not found"
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
return {
|
|
892
|
+
success: true,
|
|
893
|
+
message: "Successfully retrieved thread",
|
|
894
|
+
data: thread
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
async function createThread(request, reply) {
|
|
898
|
+
const { assistantId } = request.params;
|
|
899
|
+
const data = request.body;
|
|
900
|
+
const threadId = (0, import_crypto2.randomUUID)();
|
|
901
|
+
const newThread = threadStore.createThread(assistantId, threadId, data);
|
|
902
|
+
return reply.status(201).send({
|
|
903
|
+
success: true,
|
|
904
|
+
message: "Successfully created thread",
|
|
905
|
+
data: newThread
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
async function updateThread(request, reply) {
|
|
909
|
+
const { assistantId, threadId } = request.params;
|
|
910
|
+
const updates = request.body;
|
|
911
|
+
if (!threadStore.hasThread(assistantId, threadId)) {
|
|
912
|
+
return reply.status(404).send({
|
|
913
|
+
success: false,
|
|
914
|
+
message: "Thread not found"
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
const updatedThread = threadStore.updateThread(
|
|
918
|
+
assistantId,
|
|
919
|
+
threadId,
|
|
920
|
+
updates
|
|
921
|
+
);
|
|
922
|
+
if (!updatedThread) {
|
|
923
|
+
return reply.status(500).send({
|
|
924
|
+
success: false,
|
|
925
|
+
message: "Failed to update thread"
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
return {
|
|
929
|
+
success: true,
|
|
930
|
+
message: "Successfully updated thread",
|
|
931
|
+
data: updatedThread
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
async function deleteThread(request, reply) {
|
|
935
|
+
const { assistantId, threadId } = request.params;
|
|
936
|
+
if (!threadStore.hasThread(assistantId, threadId)) {
|
|
937
|
+
return reply.status(404).send({
|
|
938
|
+
success: false,
|
|
939
|
+
message: "Thread not found"
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
const deleted = threadStore.deleteThread(assistantId, threadId);
|
|
943
|
+
if (!deleted) {
|
|
944
|
+
return reply.status(500).send({
|
|
945
|
+
success: false,
|
|
946
|
+
message: "Failed to delete thread"
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
return {
|
|
950
|
+
success: true,
|
|
951
|
+
message: "Successfully deleted thread"
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
|
|
573
955
|
// src/schemas/index.ts
|
|
574
956
|
var getAllMemoryItemsSchema = {
|
|
575
957
|
description: "Get all memory items for an assistant thread",
|
|
@@ -773,6 +1155,11 @@ var registerLatticeRoutes = (app2) => {
|
|
|
773
1155
|
{ schema: clearMemorySchema },
|
|
774
1156
|
clearMemory
|
|
775
1157
|
);
|
|
1158
|
+
app2.get("/api/assistants", getAssistantList);
|
|
1159
|
+
app2.get("/api/assistants/:id", getAssistant);
|
|
1160
|
+
app2.post("/api/assistants", createAssistant);
|
|
1161
|
+
app2.put("/api/assistants/:id", updateAssistant);
|
|
1162
|
+
app2.delete("/api/assistants/:id", deleteAssistant);
|
|
776
1163
|
app2.get(
|
|
777
1164
|
"/api/assistants/:assistantId/graph",
|
|
778
1165
|
{ schema: getAgentGraphSchema },
|
|
@@ -783,6 +1170,20 @@ var registerLatticeRoutes = (app2) => {
|
|
|
783
1170
|
{ schema: triggerAgentTaskSchema },
|
|
784
1171
|
triggerAgentTask
|
|
785
1172
|
);
|
|
1173
|
+
app2.get("/api/assistants/:assistantId/threads", getThreadList);
|
|
1174
|
+
app2.get(
|
|
1175
|
+
"/api/assistants/:assistantId/threads/:threadId",
|
|
1176
|
+
getThread
|
|
1177
|
+
);
|
|
1178
|
+
app2.post("/api/assistants/:assistantId/threads", createThread);
|
|
1179
|
+
app2.put(
|
|
1180
|
+
"/api/assistants/:assistantId/threads/:threadId",
|
|
1181
|
+
updateThread
|
|
1182
|
+
);
|
|
1183
|
+
app2.delete(
|
|
1184
|
+
"/api/assistants/:assistantId/threads/:threadId",
|
|
1185
|
+
deleteThread
|
|
1186
|
+
);
|
|
786
1187
|
};
|
|
787
1188
|
|
|
788
1189
|
// src/logger/Logger.ts
|
|
@@ -986,7 +1387,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
|
|
|
986
1387
|
};
|
|
987
1388
|
|
|
988
1389
|
// src/services/queue_service.ts
|
|
989
|
-
var
|
|
1390
|
+
var import_core4 = require("@axiom-lattice/core");
|
|
990
1391
|
var import_protocols = require("@axiom-lattice/protocols");
|
|
991
1392
|
var import_queue_redis = require("@axiom-lattice/queue-redis");
|
|
992
1393
|
var DEFAULT_QUEUE_KEY = "default";
|
|
@@ -1005,8 +1406,8 @@ var setQueueServiceType = (type) => {
|
|
|
1005
1406
|
redisPassword: process.env.REDIS_PASSWORD
|
|
1006
1407
|
} : void 0
|
|
1007
1408
|
};
|
|
1008
|
-
if (
|
|
1009
|
-
|
|
1409
|
+
if (import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
1410
|
+
import_core4.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
|
|
1010
1411
|
}
|
|
1011
1412
|
let client;
|
|
1012
1413
|
if (type === "redis") {
|
|
@@ -1015,13 +1416,13 @@ var setQueueServiceType = (type) => {
|
|
|
1015
1416
|
redisPassword: process.env.REDIS_PASSWORD
|
|
1016
1417
|
});
|
|
1017
1418
|
}
|
|
1018
|
-
(0,
|
|
1419
|
+
(0, import_core4.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
|
|
1019
1420
|
};
|
|
1020
1421
|
var getQueueService = () => {
|
|
1021
|
-
if (!
|
|
1422
|
+
if (!import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
1022
1423
|
setQueueServiceType(queueServiceType);
|
|
1023
1424
|
}
|
|
1024
|
-
return (0,
|
|
1425
|
+
return (0, import_core4.getQueueLattice)(DEFAULT_QUEUE_KEY);
|
|
1025
1426
|
};
|
|
1026
1427
|
var popAgentTaskFromQueue = async () => {
|
|
1027
1428
|
const queue = getQueueService();
|
|
@@ -1030,7 +1431,7 @@ var popAgentTaskFromQueue = async () => {
|
|
|
1030
1431
|
};
|
|
1031
1432
|
|
|
1032
1433
|
// src/services/agent_task_consumer.ts
|
|
1033
|
-
var
|
|
1434
|
+
var import_core5 = require("@axiom-lattice/core");
|
|
1034
1435
|
var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
1035
1436
|
const {
|
|
1036
1437
|
assistant_id,
|
|
@@ -1094,7 +1495,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
1094
1495
|
}
|
|
1095
1496
|
if (callback_event) {
|
|
1096
1497
|
const state = await agent_state({ assistant_id, thread_id });
|
|
1097
|
-
|
|
1498
|
+
import_core5.eventBus.publish(callback_event, {
|
|
1098
1499
|
success: true,
|
|
1099
1500
|
state,
|
|
1100
1501
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -1108,7 +1509,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
1108
1509
|
await response.text();
|
|
1109
1510
|
if (callback_event) {
|
|
1110
1511
|
const state = await agent_state({ assistant_id, thread_id });
|
|
1111
|
-
|
|
1512
|
+
import_core5.eventBus.publish(callback_event, {
|
|
1112
1513
|
success: true,
|
|
1113
1514
|
state,
|
|
1114
1515
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -1135,7 +1536,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
1135
1536
|
return handleAgentTask(taskRequest, nextRetryCount);
|
|
1136
1537
|
}
|
|
1137
1538
|
if (callback_event) {
|
|
1138
|
-
|
|
1539
|
+
import_core5.eventBus.publish(callback_event, {
|
|
1139
1540
|
success: false,
|
|
1140
1541
|
error: error instanceof Error ? error.message : String(error),
|
|
1141
1542
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -1173,7 +1574,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
1173
1574
|
* 初始化事件监听和队列轮询
|
|
1174
1575
|
*/
|
|
1175
1576
|
initialize() {
|
|
1176
|
-
|
|
1577
|
+
import_core5.eventBus.subscribe(import_core5.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
|
|
1177
1578
|
this.startPollingQueue();
|
|
1178
1579
|
console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
|
|
1179
1580
|
}
|
|
@@ -1292,7 +1693,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
1292
1693
|
handleAgentTask(taskRequest).catch((error) => {
|
|
1293
1694
|
console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
|
|
1294
1695
|
if (taskRequest.callback_event) {
|
|
1295
|
-
|
|
1696
|
+
import_core5.eventBus.publish(taskRequest.callback_event, {
|
|
1296
1697
|
success: false,
|
|
1297
1698
|
error: error instanceof Error ? error.message : String(error),
|
|
1298
1699
|
config: {
|