@axiom-lattice/gateway 2.1.11 → 2.1.13

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/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 import_core2 = require("@axiom-lattice/core");
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 = import_core2.AgentManager.getInstance();
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,474 @@ 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
+
955
+ // src/config.ts
956
+ var ConfigService = class {
957
+ constructor() {
958
+ this.config = this.loadFromEnv();
959
+ }
960
+ /**
961
+ * Load configuration from environment variables
962
+ */
963
+ loadFromEnv() {
964
+ return {
965
+ port: process.env.PORT ? Number(process.env.PORT) : void 0,
966
+ queueServiceType: process.env.QUEUE_SERVICE_TYPE,
967
+ redisUrl: process.env.REDIS_URL,
968
+ redisPassword: process.env.REDIS_PASSWORD,
969
+ queueName: process.env.QUEUE_NAME
970
+ };
971
+ }
972
+ /**
973
+ * Update configuration from JSON object
974
+ * This will update both the internal config and process.env
975
+ */
976
+ updateConfig(jsonConfig) {
977
+ for (const [key, value] of Object.entries(jsonConfig)) {
978
+ if (value !== null && value !== void 0) {
979
+ if (typeof value === "object" && !Array.isArray(value)) {
980
+ for (const [nestedKey, nestedValue] of Object.entries(value)) {
981
+ const envKey = `${key.toUpperCase()}_${nestedKey.toUpperCase()}`;
982
+ process.env[envKey] = String(nestedValue);
983
+ }
984
+ } else {
985
+ process.env[key.toUpperCase()] = String(value);
986
+ }
987
+ }
988
+ }
989
+ this.config = this.loadFromEnv();
990
+ this.config = this.deepMerge(this.config, jsonConfig);
991
+ }
992
+ /**
993
+ * Deep merge two objects
994
+ */
995
+ deepMerge(target, source) {
996
+ const output = { ...target };
997
+ if (this.isObject(target) && this.isObject(source)) {
998
+ Object.keys(source).forEach((key) => {
999
+ if (this.isObject(source[key])) {
1000
+ if (!(key in target)) {
1001
+ Object.assign(output, { [key]: source[key] });
1002
+ } else {
1003
+ output[key] = this.deepMerge(target[key], source[key]);
1004
+ }
1005
+ } else {
1006
+ Object.assign(output, { [key]: source[key] });
1007
+ }
1008
+ });
1009
+ }
1010
+ return output;
1011
+ }
1012
+ /**
1013
+ * Check if value is a plain object
1014
+ */
1015
+ isObject(item) {
1016
+ return item && typeof item === "object" && !Array.isArray(item);
1017
+ }
1018
+ /**
1019
+ * Get current configuration
1020
+ */
1021
+ getConfig() {
1022
+ return { ...this.config };
1023
+ }
1024
+ };
1025
+ var configService = new ConfigService();
1026
+
1027
+ // src/services/queue_service.ts
1028
+ var import_core4 = require("@axiom-lattice/core");
1029
+ var import_protocols = require("@axiom-lattice/protocols");
1030
+ var import_queue_redis = require("@axiom-lattice/queue-redis");
1031
+ var DEFAULT_QUEUE_KEY = "default";
1032
+ var queueServiceType = process.env.QUEUE_SERVICE_TYPE || "memory";
1033
+ var setQueueServiceType = (type) => {
1034
+ queueServiceType = type;
1035
+ console.log(`Queue service type set to: ${type}`);
1036
+ const queueName = process.env.QUEUE_NAME || "tasks";
1037
+ const config = {
1038
+ name: "Default Queue Service",
1039
+ description: `Default ${type} queue service`,
1040
+ type: type === "redis" ? import_protocols.QueueType.REDIS : import_protocols.QueueType.MEMORY,
1041
+ queueName,
1042
+ options: type === "redis" ? {
1043
+ redisUrl: process.env.REDIS_URL,
1044
+ redisPassword: process.env.REDIS_PASSWORD
1045
+ } : void 0
1046
+ };
1047
+ if (import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
1048
+ import_core4.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
1049
+ }
1050
+ let client;
1051
+ if (type === "redis") {
1052
+ client = new import_queue_redis.RedisQueueClient(queueName, {
1053
+ redisUrl: process.env.REDIS_URL,
1054
+ redisPassword: process.env.REDIS_PASSWORD
1055
+ });
1056
+ }
1057
+ (0, import_core4.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
1058
+ };
1059
+ var getQueueService = () => {
1060
+ if (!import_core4.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
1061
+ setQueueServiceType(queueServiceType);
1062
+ }
1063
+ return (0, import_core4.getQueueLattice)(DEFAULT_QUEUE_KEY);
1064
+ };
1065
+ var popAgentTaskFromQueue = async () => {
1066
+ const queue = getQueueService();
1067
+ const result = await queue.pop();
1068
+ return result;
1069
+ };
1070
+
1071
+ // src/controllers/config.ts
1072
+ async function updateConfig(request, reply) {
1073
+ try {
1074
+ const { config: jsonConfig } = request.body;
1075
+ if (!jsonConfig || typeof jsonConfig !== "object") {
1076
+ return reply.status(400).send({
1077
+ success: false,
1078
+ error: "Invalid configuration: config must be an object"
1079
+ });
1080
+ }
1081
+ configService.updateConfig(jsonConfig);
1082
+ const warnings = [];
1083
+ const requiresRestart = [];
1084
+ if (jsonConfig.port !== void 0) {
1085
+ requiresRestart.push("PORT");
1086
+ warnings.push("Port change requires server restart to take effect");
1087
+ }
1088
+ if (jsonConfig.queueServiceType) {
1089
+ setQueueServiceType(jsonConfig.queueServiceType);
1090
+ }
1091
+ if ((jsonConfig.redisUrl || jsonConfig.redisPassword) && (process.env.QUEUE_SERVICE_TYPE === "redis" || jsonConfig.queueServiceType === "redis")) {
1092
+ const currentType = jsonConfig.queueServiceType || process.env.QUEUE_SERVICE_TYPE || "memory";
1093
+ if (currentType === "redis") {
1094
+ setQueueServiceType("redis");
1095
+ }
1096
+ }
1097
+ const updatedConfig = configService.getConfig();
1098
+ const safeConfig = {
1099
+ ...updatedConfig,
1100
+ redisPassword: updatedConfig.redisPassword ? "***" : updatedConfig.redisPassword
1101
+ };
1102
+ return reply.send({
1103
+ success: true,
1104
+ message: "Configuration updated successfully",
1105
+ data: safeConfig,
1106
+ warnings: warnings.length > 0 ? warnings : void 0,
1107
+ requiresRestart: requiresRestart.length > 0 ? requiresRestart : void 0
1108
+ });
1109
+ } catch (error) {
1110
+ console.error("Failed to update configuration", {
1111
+ error: error.message,
1112
+ stack: error.stack
1113
+ });
1114
+ return reply.status(500).send({
1115
+ success: false,
1116
+ error: error.message || "Failed to update configuration"
1117
+ });
1118
+ }
1119
+ }
1120
+ async function getConfig(request, reply) {
1121
+ try {
1122
+ const currentConfig = configService.getConfig();
1123
+ const safeConfig = {
1124
+ ...currentConfig,
1125
+ redisPassword: currentConfig.redisPassword ? "***" : currentConfig.redisPassword
1126
+ };
1127
+ return reply.send({
1128
+ success: true,
1129
+ data: safeConfig
1130
+ });
1131
+ } catch (error) {
1132
+ console.error("Failed to get configuration", {
1133
+ error: error.message,
1134
+ stack: error.stack
1135
+ });
1136
+ return reply.status(500).send({
1137
+ success: false,
1138
+ error: error.message || "Failed to get configuration"
1139
+ });
1140
+ }
1141
+ }
1142
+
1143
+ // src/controllers/models.ts
1144
+ var import_core5 = require("@axiom-lattice/core");
1145
+ async function getModels(request, reply) {
1146
+ try {
1147
+ const allLattices = import_core5.modelLatticeManager.getAllLattices();
1148
+ const models = allLattices.map((lattice) => {
1149
+ const config = lattice.client.config || {};
1150
+ return {
1151
+ key: lattice.key,
1152
+ model: config.model || "",
1153
+ provider: config.provider || "openai",
1154
+ streaming: config.streaming || false,
1155
+ apiKey: config.apiKey || "",
1156
+ baseURL: config.baseURL || "",
1157
+ maxTokens: config.maxTokens,
1158
+ temperature: config.temperature,
1159
+ timeout: config.timeout,
1160
+ maxRetries: config.maxRetries
1161
+ };
1162
+ });
1163
+ return reply.send({
1164
+ success: true,
1165
+ data: models
1166
+ });
1167
+ } catch (error) {
1168
+ console.error("Failed to get models", {
1169
+ error: error.message,
1170
+ stack: error.stack
1171
+ });
1172
+ return reply.status(500).send({
1173
+ success: false,
1174
+ error: error.message || "Failed to get models"
1175
+ });
1176
+ }
1177
+ }
1178
+ async function updateModels(request, reply) {
1179
+ try {
1180
+ const { models } = request.body;
1181
+ if (!models || !Array.isArray(models)) {
1182
+ return reply.status(400).send({
1183
+ success: false,
1184
+ error: "Invalid request: models must be an array"
1185
+ });
1186
+ }
1187
+ const registeredModels = [];
1188
+ const errors = [];
1189
+ for (const modelConfig of models) {
1190
+ if (!modelConfig.key || !modelConfig.model || !modelConfig.provider) {
1191
+ errors.push(
1192
+ `Model configuration is incomplete: key, model, and provider are required`
1193
+ );
1194
+ continue;
1195
+ }
1196
+ try {
1197
+ if (import_core5.modelLatticeManager.hasLattice(modelConfig.key)) {
1198
+ import_core5.modelLatticeManager.removeLattice(modelConfig.key);
1199
+ }
1200
+ const llmConfig = {
1201
+ provider: modelConfig.provider,
1202
+ model: modelConfig.model,
1203
+ streaming: modelConfig.streaming ?? false,
1204
+ apiKey: modelConfig.apiKey,
1205
+ baseURL: modelConfig.baseURL,
1206
+ maxTokens: modelConfig.maxTokens,
1207
+ temperature: modelConfig.temperature,
1208
+ timeout: modelConfig.timeout,
1209
+ maxRetries: modelConfig.maxRetries
1210
+ };
1211
+ (0, import_core5.registerModelLattice)(modelConfig.key, llmConfig);
1212
+ registeredModels.push(modelConfig.key);
1213
+ } catch (error) {
1214
+ errors.push(
1215
+ `Failed to register model ${modelConfig.key}: ${error.message}`
1216
+ );
1217
+ }
1218
+ }
1219
+ if (errors.length > 0 && registeredModels.length === 0) {
1220
+ return reply.status(400).send({
1221
+ success: false,
1222
+ error: errors.join("; ")
1223
+ });
1224
+ }
1225
+ return reply.send({
1226
+ success: true,
1227
+ message: `Successfully registered ${registeredModels.length} model(s)`,
1228
+ data: {
1229
+ registered: registeredModels,
1230
+ errors: errors.length > 0 ? errors : void 0
1231
+ }
1232
+ });
1233
+ } catch (error) {
1234
+ console.error("Failed to update models", {
1235
+ error: error.message,
1236
+ stack: error.stack
1237
+ });
1238
+ return reply.status(500).send({
1239
+ success: false,
1240
+ error: error.message || "Failed to update models"
1241
+ });
1242
+ }
1243
+ }
1244
+
573
1245
  // src/schemas/index.ts
574
1246
  var getAllMemoryItemsSchema = {
575
1247
  description: "Get all memory items for an assistant thread",
@@ -738,6 +1410,77 @@ var triggerAgentTaskSchema = {
738
1410
  }
739
1411
  }
740
1412
  };
1413
+ var updateConfigSchema = {
1414
+ description: "Update gateway configuration",
1415
+ tags: ["Configuration"],
1416
+ summary: "Update Configuration",
1417
+ body: {
1418
+ type: "object",
1419
+ properties: {
1420
+ config: {
1421
+ type: "object",
1422
+ description: "Configuration object to update",
1423
+ properties: {
1424
+ port: { type: "number", description: "Server port" },
1425
+ queueServiceType: {
1426
+ type: "string",
1427
+ enum: ["memory", "redis"],
1428
+ description: "Queue service type"
1429
+ },
1430
+ redisUrl: { type: "string", description: "Redis URL" },
1431
+ redisPassword: { type: "string", description: "Redis password" },
1432
+ queueName: { type: "string", description: "Queue name" }
1433
+ }
1434
+ }
1435
+ },
1436
+ required: ["config"]
1437
+ },
1438
+ response: {
1439
+ 200: {
1440
+ type: "object",
1441
+ properties: {
1442
+ success: { type: "boolean" },
1443
+ message: { type: "string" },
1444
+ data: { type: "object" }
1445
+ }
1446
+ },
1447
+ 400: {
1448
+ type: "object",
1449
+ properties: {
1450
+ success: { type: "boolean" },
1451
+ error: { type: "string" }
1452
+ }
1453
+ },
1454
+ 500: {
1455
+ type: "object",
1456
+ properties: {
1457
+ success: { type: "boolean" },
1458
+ error: { type: "string" }
1459
+ }
1460
+ }
1461
+ }
1462
+ };
1463
+ var getConfigSchema = {
1464
+ description: "Get current gateway configuration",
1465
+ tags: ["Configuration"],
1466
+ summary: "Get Configuration",
1467
+ response: {
1468
+ 200: {
1469
+ type: "object",
1470
+ properties: {
1471
+ success: { type: "boolean" },
1472
+ data: { type: "object" }
1473
+ }
1474
+ },
1475
+ 500: {
1476
+ type: "object",
1477
+ properties: {
1478
+ success: { type: "boolean" },
1479
+ error: { type: "string" }
1480
+ }
1481
+ }
1482
+ }
1483
+ };
741
1484
 
742
1485
  // src/routes/index.ts
743
1486
  var registerLatticeRoutes = (app2) => {
@@ -773,6 +1516,11 @@ var registerLatticeRoutes = (app2) => {
773
1516
  { schema: clearMemorySchema },
774
1517
  clearMemory
775
1518
  );
1519
+ app2.get("/api/assistants", getAssistantList);
1520
+ app2.get("/api/assistants/:id", getAssistant);
1521
+ app2.post("/api/assistants", createAssistant);
1522
+ app2.put("/api/assistants/:id", updateAssistant);
1523
+ app2.delete("/api/assistants/:id", deleteAssistant);
776
1524
  app2.get(
777
1525
  "/api/assistants/:assistantId/graph",
778
1526
  { schema: getAgentGraphSchema },
@@ -783,6 +1531,32 @@ var registerLatticeRoutes = (app2) => {
783
1531
  { schema: triggerAgentTaskSchema },
784
1532
  triggerAgentTask
785
1533
  );
1534
+ app2.get("/api/assistants/:assistantId/threads", getThreadList);
1535
+ app2.get(
1536
+ "/api/assistants/:assistantId/threads/:threadId",
1537
+ getThread
1538
+ );
1539
+ app2.post("/api/assistants/:assistantId/threads", createThread);
1540
+ app2.put(
1541
+ "/api/assistants/:assistantId/threads/:threadId",
1542
+ updateThread
1543
+ );
1544
+ app2.delete(
1545
+ "/api/assistants/:assistantId/threads/:threadId",
1546
+ deleteThread
1547
+ );
1548
+ app2.get(
1549
+ "/api/config",
1550
+ { schema: getConfigSchema },
1551
+ getConfig
1552
+ );
1553
+ app2.put(
1554
+ "/api/config",
1555
+ { schema: updateConfigSchema },
1556
+ updateConfig
1557
+ );
1558
+ app2.get("/api/models", getModels);
1559
+ app2.put("/api/models", updateModels);
786
1560
  };
787
1561
 
788
1562
  // src/logger/Logger.ts
@@ -985,52 +1759,8 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
985
1759
  await app2.register(import_swagger_ui.default, swaggerUiConfig);
986
1760
  };
987
1761
 
988
- // src/services/queue_service.ts
989
- var import_core3 = require("@axiom-lattice/core");
990
- var import_protocols = require("@axiom-lattice/protocols");
991
- var import_queue_redis = require("@axiom-lattice/queue-redis");
992
- var DEFAULT_QUEUE_KEY = "default";
993
- var queueServiceType = process.env.QUEUE_SERVICE_TYPE || "memory";
994
- var setQueueServiceType = (type) => {
995
- queueServiceType = type;
996
- console.log(`Queue service type set to: ${type}`);
997
- const queueName = process.env.QUEUE_NAME || "tasks";
998
- const config = {
999
- name: "Default Queue Service",
1000
- description: `Default ${type} queue service`,
1001
- type: type === "redis" ? import_protocols.QueueType.REDIS : import_protocols.QueueType.MEMORY,
1002
- queueName,
1003
- options: type === "redis" ? {
1004
- redisUrl: process.env.REDIS_URL,
1005
- redisPassword: process.env.REDIS_PASSWORD
1006
- } : void 0
1007
- };
1008
- if (import_core3.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
1009
- import_core3.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
1010
- }
1011
- let client;
1012
- if (type === "redis") {
1013
- client = new import_queue_redis.RedisQueueClient(queueName, {
1014
- redisUrl: process.env.REDIS_URL,
1015
- redisPassword: process.env.REDIS_PASSWORD
1016
- });
1017
- }
1018
- (0, import_core3.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
1019
- };
1020
- var getQueueService = () => {
1021
- if (!import_core3.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
1022
- setQueueServiceType(queueServiceType);
1023
- }
1024
- return (0, import_core3.getQueueLattice)(DEFAULT_QUEUE_KEY);
1025
- };
1026
- var popAgentTaskFromQueue = async () => {
1027
- const queue = getQueueService();
1028
- const result = await queue.pop();
1029
- return result;
1030
- };
1031
-
1032
1762
  // src/services/agent_task_consumer.ts
1033
- var import_core4 = require("@axiom-lattice/core");
1763
+ var import_core6 = require("@axiom-lattice/core");
1034
1764
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
1035
1765
  const {
1036
1766
  assistant_id,
@@ -1094,7 +1824,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
1094
1824
  }
1095
1825
  if (callback_event) {
1096
1826
  const state = await agent_state({ assistant_id, thread_id });
1097
- import_core4.eventBus.publish(callback_event, {
1827
+ import_core6.eventBus.publish(callback_event, {
1098
1828
  success: true,
1099
1829
  state,
1100
1830
  config: { assistant_id, thread_id, tenant_id }
@@ -1108,7 +1838,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
1108
1838
  await response.text();
1109
1839
  if (callback_event) {
1110
1840
  const state = await agent_state({ assistant_id, thread_id });
1111
- import_core4.eventBus.publish(callback_event, {
1841
+ import_core6.eventBus.publish(callback_event, {
1112
1842
  success: true,
1113
1843
  state,
1114
1844
  config: { assistant_id, thread_id, tenant_id }
@@ -1135,7 +1865,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
1135
1865
  return handleAgentTask(taskRequest, nextRetryCount);
1136
1866
  }
1137
1867
  if (callback_event) {
1138
- import_core4.eventBus.publish(callback_event, {
1868
+ import_core6.eventBus.publish(callback_event, {
1139
1869
  success: false,
1140
1870
  error: error instanceof Error ? error.message : String(error),
1141
1871
  config: { assistant_id, thread_id, tenant_id }
@@ -1173,7 +1903,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
1173
1903
  * 初始化事件监听和队列轮询
1174
1904
  */
1175
1905
  initialize() {
1176
- import_core4.eventBus.subscribe(import_core4.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
1906
+ import_core6.eventBus.subscribe(import_core6.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
1177
1907
  this.startPollingQueue();
1178
1908
  console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
1179
1909
  }
@@ -1292,7 +2022,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
1292
2022
  handleAgentTask(taskRequest).catch((error) => {
1293
2023
  console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
1294
2024
  if (taskRequest.callback_event) {
1295
- import_core4.eventBus.publish(taskRequest.callback_event, {
2025
+ import_core6.eventBus.publish(taskRequest.callback_event, {
1296
2026
  success: false,
1297
2027
  error: error instanceof Error ? error.message : String(error),
1298
2028
  config: {