@axiom-lattice/gateway 2.1.14 → 2.1.16

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @axiom-lattice/gateway@2.1.14 build /home/runner/work/agentic/agentic/packages/gateway
2
+ > @axiom-lattice/gateway@2.1.16 build /home/runner/work/agentic/agentic/packages/gateway
3
3
  > tsup src/index.ts --format cjs,esm --dts --clean --sourcemap
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,13 +9,13 @@
9
9
  CLI Cleaning output folder
10
10
  CJS Build start
11
11
  ESM Build start
12
- ESM dist/index.mjs 56.17 KB
13
- ESM dist/index.mjs.map 121.06 KB
14
- ESM ⚡️ Build success in 149ms
15
- CJS dist/index.js 58.53 KB
16
- CJS dist/index.js.map 121.16 KB
17
- CJS ⚡️ Build success in 153ms
12
+ ESM dist/index.mjs 53.97 KB
13
+ ESM dist/index.mjs.map 116.16 KB
14
+ ESM ⚡️ Build success in 146ms
15
+ CJS dist/index.js 56.47 KB
16
+ CJS dist/index.js.map 116.26 KB
17
+ CJS ⚡️ Build success in 148ms
18
18
  DTS Build start
19
- DTS ⚡️ Build success in 7922ms
19
+ DTS ⚡️ Build success in 7937ms
20
20
  DTS dist/index.d.ts 3.32 KB
21
21
  DTS dist/index.d.mts 3.32 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @axiom-lattice/gateway
2
2
 
3
+ ## 2.1.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 7d8f3f5: enhance lattice
8
+ - Updated dependencies [7d8f3f5]
9
+ - @axiom-lattice/protocols@2.1.6
10
+ - @axiom-lattice/core@2.1.12
11
+ - @axiom-lattice/queue-redis@1.0.5
12
+
13
+ ## 2.1.15
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [af6d59b]
18
+ - @axiom-lattice/core@2.1.11
19
+
3
20
  ## 2.1.14
4
21
 
5
22
  ### Patch Changes
package/dist/index.js CHANGED
@@ -248,73 +248,10 @@ 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
251
  // src/controllers/assistant.ts
316
- var import_crypto = require("crypto");
317
252
  var import_core2 = require("@axiom-lattice/core");
253
+ var import_crypto = require("crypto");
254
+ var import_core3 = require("@axiom-lattice/core");
318
255
  function convertAgentConfigToAssistant(config) {
319
256
  return {
320
257
  id: config.key,
@@ -329,11 +266,13 @@ function convertAgentConfigToAssistant(config) {
329
266
  };
330
267
  }
331
268
  async function getAssistantList(request, reply) {
332
- const agentConfigs = await (0, import_core2.getAllAgentConfigs)();
269
+ const agentConfigs = await (0, import_core3.getAllAgentConfigs)();
333
270
  const codeConfiguredAssistants = agentConfigs.map(
334
271
  convertAgentConfigToAssistant
335
272
  );
336
- const storedAssistants = assistantStore.getAllAssistants();
273
+ const storeLattice = (0, import_core2.getStoreLattice)("default", "assistant");
274
+ const assistantStore = storeLattice.store;
275
+ const storedAssistants = await assistantStore.getAllAssistants();
337
276
  const assistantMap = /* @__PURE__ */ new Map();
338
277
  codeConfiguredAssistants.forEach((assistant) => {
339
278
  assistantMap.set(assistant.id, assistant);
@@ -353,9 +292,11 @@ async function getAssistantList(request, reply) {
353
292
  }
354
293
  async function getAssistant(request, reply) {
355
294
  const { id } = request.params;
356
- let assistant = assistantStore.getAssistantById(id);
295
+ const storeLattice = (0, import_core2.getStoreLattice)("default", "assistant");
296
+ const assistantStore = storeLattice.store;
297
+ let assistant = await assistantStore.getAssistantById(id);
357
298
  if (!assistant) {
358
- const agentConfigs = await (0, import_core2.getAllAgentConfigs)();
299
+ const agentConfigs = await (0, import_core3.getAllAgentConfigs)();
359
300
  const agentConfig = agentConfigs.find((config) => config.key === id);
360
301
  if (agentConfig) {
361
302
  assistant = convertAgentConfigToAssistant(agentConfig);
@@ -388,7 +329,9 @@ async function createAssistant(request, reply) {
388
329
  });
389
330
  }
390
331
  const id = (0, import_crypto.randomUUID)();
391
- const newAssistant = assistantStore.createAssistant(id, data);
332
+ const storeLattice = (0, import_core2.getStoreLattice)("default", "assistant");
333
+ const assistantStore = storeLattice.store;
334
+ const newAssistant = await assistantStore.createAssistant(id, data);
392
335
  return reply.status(201).send({
393
336
  success: true,
394
337
  message: "Successfully created assistant",
@@ -398,7 +341,7 @@ async function createAssistant(request, reply) {
398
341
  async function updateAssistant(request, reply) {
399
342
  const { id } = request.params;
400
343
  const updates = request.body;
401
- const agentConfigs = await (0, import_core2.getAllAgentConfigs)();
344
+ const agentConfigs = await (0, import_core3.getAllAgentConfigs)();
402
345
  const isCodeConfigured = agentConfigs.some((config) => config.key === id);
403
346
  if (isCodeConfigured) {
404
347
  return reply.status(403).send({
@@ -406,13 +349,16 @@ async function updateAssistant(request, reply) {
406
349
  message: "Cannot update code-configured assistant. Only stored assistants can be updated."
407
350
  });
408
351
  }
409
- if (!assistantStore.hasAssistant(id)) {
352
+ const storeLattice = (0, import_core2.getStoreLattice)("default", "assistant");
353
+ const assistantStore = storeLattice.store;
354
+ const exists = await assistantStore.hasAssistant(id);
355
+ if (!exists) {
410
356
  return reply.status(404).send({
411
357
  success: false,
412
358
  message: "Assistant not found"
413
359
  });
414
360
  }
415
- const updatedAssistant = assistantStore.updateAssistant(id, updates);
361
+ const updatedAssistant = await assistantStore.updateAssistant(id, updates);
416
362
  if (!updatedAssistant) {
417
363
  return reply.status(500).send({
418
364
  success: false,
@@ -427,7 +373,7 @@ async function updateAssistant(request, reply) {
427
373
  }
428
374
  async function deleteAssistant(request, reply) {
429
375
  const { id } = request.params;
430
- const agentConfigs = await (0, import_core2.getAllAgentConfigs)();
376
+ const agentConfigs = await (0, import_core3.getAllAgentConfigs)();
431
377
  const isCodeConfigured = agentConfigs.some((config) => config.key === id);
432
378
  if (isCodeConfigured) {
433
379
  return reply.status(403).send({
@@ -435,13 +381,16 @@ async function deleteAssistant(request, reply) {
435
381
  message: "Cannot delete code-configured assistant. Only stored assistants can be deleted."
436
382
  });
437
383
  }
438
- if (!assistantStore.hasAssistant(id)) {
384
+ const storeLattice = (0, import_core2.getStoreLattice)("default", "assistant");
385
+ const assistantStore = storeLattice.store;
386
+ const exists = await assistantStore.hasAssistant(id);
387
+ if (!exists) {
439
388
  return reply.status(404).send({
440
389
  success: false,
441
390
  message: "Assistant not found"
442
391
  });
443
392
  }
444
- const deleted = assistantStore.deleteAssistant(id);
393
+ const deleted = await assistantStore.deleteAssistant(id);
445
394
  if (!deleted) {
446
395
  return reply.status(500).send({
447
396
  success: false,
@@ -736,7 +685,7 @@ var clearMemory = async (request, reply) => {
736
685
  };
737
686
 
738
687
  // src/controllers/agent_task.ts
739
- var import_core3 = require("@axiom-lattice/core");
688
+ var import_core4 = require("@axiom-lattice/core");
740
689
  var triggerAgentTask = async (request, reply) => {
741
690
  try {
742
691
  const { assistant_id, thread_id, input, command } = request.body;
@@ -755,7 +704,7 @@ var triggerAgentTask = async (request, reply) => {
755
704
  });
756
705
  return;
757
706
  }
758
- const agentManager = import_core3.AgentManager.getInstance();
707
+ const agentManager = import_core4.AgentManager.getInstance();
759
708
  const result = await agentManager.callAgentInQueue({
760
709
  assistant_id,
761
710
  thread_id,
@@ -774,102 +723,14 @@ var triggerAgentTask = async (request, reply) => {
774
723
  }
775
724
  };
776
725
 
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
726
  // src/controllers/threads.ts
727
+ var import_core5 = require("@axiom-lattice/core");
869
728
  var import_crypto2 = require("crypto");
870
729
  async function getThreadList(request, reply) {
871
730
  const { assistantId } = request.params;
872
- const threads = threadStore.getThreadsByAssistantId(assistantId);
731
+ const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
732
+ const threadStore = storeLattice.store;
733
+ const threads = await threadStore.getThreadsByAssistantId(assistantId);
873
734
  return {
874
735
  success: true,
875
736
  message: "Successfully retrieved thread list",
@@ -881,7 +742,9 @@ async function getThreadList(request, reply) {
881
742
  }
882
743
  async function getThread(request, reply) {
883
744
  const { assistantId, threadId } = request.params;
884
- const thread = threadStore.getThreadById(assistantId, threadId);
745
+ const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
746
+ const threadStore = storeLattice.store;
747
+ const thread = await threadStore.getThreadById(assistantId, threadId);
885
748
  if (!thread) {
886
749
  return reply.status(404).send({
887
750
  success: false,
@@ -898,7 +761,9 @@ async function createThread(request, reply) {
898
761
  const { assistantId } = request.params;
899
762
  const data = request.body;
900
763
  const threadId = (0, import_crypto2.randomUUID)();
901
- const newThread = threadStore.createThread(assistantId, threadId, data);
764
+ const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
765
+ const threadStore = storeLattice.store;
766
+ const newThread = await threadStore.createThread(assistantId, threadId, data);
902
767
  return reply.status(201).send({
903
768
  success: true,
904
769
  message: "Successfully created thread",
@@ -908,13 +773,16 @@ async function createThread(request, reply) {
908
773
  async function updateThread(request, reply) {
909
774
  const { assistantId, threadId } = request.params;
910
775
  const updates = request.body;
911
- if (!threadStore.hasThread(assistantId, threadId)) {
776
+ const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
777
+ const threadStore = storeLattice.store;
778
+ const exists = await threadStore.hasThread(assistantId, threadId);
779
+ if (!exists) {
912
780
  return reply.status(404).send({
913
781
  success: false,
914
782
  message: "Thread not found"
915
783
  });
916
784
  }
917
- const updatedThread = threadStore.updateThread(
785
+ const updatedThread = await threadStore.updateThread(
918
786
  assistantId,
919
787
  threadId,
920
788
  updates
@@ -933,13 +801,16 @@ async function updateThread(request, reply) {
933
801
  }
934
802
  async function deleteThread(request, reply) {
935
803
  const { assistantId, threadId } = request.params;
936
- if (!threadStore.hasThread(assistantId, threadId)) {
804
+ const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
805
+ const threadStore = storeLattice.store;
806
+ const exists = await threadStore.hasThread(assistantId, threadId);
807
+ if (!exists) {
937
808
  return reply.status(404).send({
938
809
  success: false,
939
810
  message: "Thread not found"
940
811
  });
941
812
  }
942
- const deleted = threadStore.deleteThread(assistantId, threadId);
813
+ const deleted = await threadStore.deleteThread(assistantId, threadId);
943
814
  if (!deleted) {
944
815
  return reply.status(500).send({
945
816
  success: false,
@@ -1025,7 +896,7 @@ var ConfigService = class {
1025
896
  var configService = new ConfigService();
1026
897
 
1027
898
  // src/services/queue_service.ts
1028
- var import_core4 = require("@axiom-lattice/core");
899
+ var import_core6 = require("@axiom-lattice/core");
1029
900
  var import_protocols = require("@axiom-lattice/protocols");
1030
901
  var import_queue_redis = require("@axiom-lattice/queue-redis");
1031
902
  var DEFAULT_QUEUE_KEY = "default";
@@ -1044,8 +915,8 @@ var setQueueServiceType = (type) => {
1044
915
  redisPassword: process.env.REDIS_PASSWORD
1045
916
  } : void 0
1046
917
  };
1047
- if (import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
1048
- import_core4.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
918
+ if (import_core6.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
919
+ import_core6.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
1049
920
  }
1050
921
  let client;
1051
922
  if (type === "redis") {
@@ -1054,13 +925,13 @@ var setQueueServiceType = (type) => {
1054
925
  redisPassword: process.env.REDIS_PASSWORD
1055
926
  });
1056
927
  }
1057
- (0, import_core4.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
928
+ (0, import_core6.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
1058
929
  };
1059
930
  var getQueueService = () => {
1060
- if (!import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
931
+ if (!import_core6.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
1061
932
  setQueueServiceType(queueServiceType);
1062
933
  }
1063
- return (0, import_core4.getQueueLattice)(DEFAULT_QUEUE_KEY);
934
+ return (0, import_core6.getQueueLattice)(DEFAULT_QUEUE_KEY);
1064
935
  };
1065
936
  var popAgentTaskFromQueue = async () => {
1066
937
  const queue = getQueueService();
@@ -1141,10 +1012,10 @@ async function getConfig(request, reply) {
1141
1012
  }
1142
1013
 
1143
1014
  // src/controllers/models.ts
1144
- var import_core5 = require("@axiom-lattice/core");
1015
+ var import_core7 = require("@axiom-lattice/core");
1145
1016
  async function getModels(request, reply) {
1146
1017
  try {
1147
- const allLattices = import_core5.modelLatticeManager.getAllLattices();
1018
+ const allLattices = import_core7.modelLatticeManager.getAllLattices();
1148
1019
  const models = allLattices.map((lattice) => {
1149
1020
  const config = lattice.client.config || {};
1150
1021
  return {
@@ -1194,8 +1065,8 @@ async function updateModels(request, reply) {
1194
1065
  continue;
1195
1066
  }
1196
1067
  try {
1197
- if (import_core5.modelLatticeManager.hasLattice(modelConfig.key)) {
1198
- import_core5.modelLatticeManager.removeLattice(modelConfig.key);
1068
+ if (import_core7.modelLatticeManager.hasLattice(modelConfig.key)) {
1069
+ import_core7.modelLatticeManager.removeLattice(modelConfig.key);
1199
1070
  }
1200
1071
  const llmConfig = {
1201
1072
  provider: modelConfig.provider,
@@ -1208,7 +1079,7 @@ async function updateModels(request, reply) {
1208
1079
  timeout: modelConfig.timeout,
1209
1080
  maxRetries: modelConfig.maxRetries
1210
1081
  };
1211
- (0, import_core5.registerModelLattice)(modelConfig.key, llmConfig);
1082
+ (0, import_core7.registerModelLattice)(modelConfig.key, llmConfig);
1212
1083
  registeredModels.push(modelConfig.key);
1213
1084
  } catch (error) {
1214
1085
  errors.push(
@@ -1760,7 +1631,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
1760
1631
  };
1761
1632
 
1762
1633
  // src/services/agent_task_consumer.ts
1763
- var import_core6 = require("@axiom-lattice/core");
1634
+ var import_core8 = require("@axiom-lattice/core");
1764
1635
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
1765
1636
  const {
1766
1637
  assistant_id,
@@ -1824,7 +1695,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
1824
1695
  }
1825
1696
  if (callback_event) {
1826
1697
  const state = await agent_state({ assistant_id, thread_id });
1827
- import_core6.eventBus.publish(callback_event, {
1698
+ import_core8.eventBus.publish(callback_event, {
1828
1699
  success: true,
1829
1700
  state,
1830
1701
  config: { assistant_id, thread_id, tenant_id }
@@ -1838,7 +1709,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
1838
1709
  await response.text();
1839
1710
  if (callback_event) {
1840
1711
  const state = await agent_state({ assistant_id, thread_id });
1841
- import_core6.eventBus.publish(callback_event, {
1712
+ import_core8.eventBus.publish(callback_event, {
1842
1713
  success: true,
1843
1714
  state,
1844
1715
  config: { assistant_id, thread_id, tenant_id }
@@ -1865,7 +1736,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
1865
1736
  return handleAgentTask(taskRequest, nextRetryCount);
1866
1737
  }
1867
1738
  if (callback_event) {
1868
- import_core6.eventBus.publish(callback_event, {
1739
+ import_core8.eventBus.publish(callback_event, {
1869
1740
  success: false,
1870
1741
  error: error instanceof Error ? error.message : String(error),
1871
1742
  config: { assistant_id, thread_id, tenant_id }
@@ -1903,7 +1774,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
1903
1774
  * 初始化事件监听和队列轮询
1904
1775
  */
1905
1776
  initialize() {
1906
- import_core6.eventBus.subscribe(import_core6.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
1777
+ import_core8.eventBus.subscribe(import_core8.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
1907
1778
  this.startPollingQueue();
1908
1779
  console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
1909
1780
  }
@@ -2022,7 +1893,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
2022
1893
  handleAgentTask(taskRequest).catch((error) => {
2023
1894
  console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
2024
1895
  if (taskRequest.callback_event) {
2025
- import_core6.eventBus.publish(taskRequest.callback_event, {
1896
+ import_core8.eventBus.publish(taskRequest.callback_event, {
2026
1897
  success: false,
2027
1898
  error: error instanceof Error ? error.message : String(error),
2028
1899
  config: {