@axiom-lattice/gateway 2.1.34 → 2.1.36

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
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
8
  var __export = (target, all) => {
12
9
  for (var name in all)
13
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -30,106 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
27
  ));
31
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
29
 
33
- // src/config.ts
34
- var config_exports = {};
35
- __export(config_exports, {
36
- config: () => config,
37
- configService: () => configService
38
- });
39
- var ConfigService, configService, config;
40
- var init_config = __esm({
41
- "src/config.ts"() {
42
- "use strict";
43
- ConfigService = class {
44
- constructor() {
45
- this.config = this.loadFromEnv();
46
- }
47
- /**
48
- * Load configuration from environment variables
49
- */
50
- loadFromEnv() {
51
- return {
52
- port: process.env.PORT ? Number(process.env.PORT) : void 0,
53
- queueServiceType: process.env.QUEUE_SERVICE_TYPE,
54
- redisUrl: process.env.REDIS_URL,
55
- redisPassword: process.env.REDIS_PASSWORD,
56
- queueName: process.env.QUEUE_NAME
57
- };
58
- }
59
- /**
60
- * Update configuration from JSON object
61
- * This will update both the internal config and process.env
62
- */
63
- updateConfig(jsonConfig) {
64
- for (const [key, value] of Object.entries(jsonConfig)) {
65
- if (value !== null && value !== void 0) {
66
- if (typeof value === "object" && !Array.isArray(value)) {
67
- for (const [nestedKey, nestedValue] of Object.entries(value)) {
68
- const envKey = `${key.toUpperCase()}_${nestedKey.toUpperCase()}`;
69
- process.env[envKey] = String(nestedValue);
70
- }
71
- } else {
72
- process.env[key.toUpperCase()] = String(value);
73
- }
74
- }
75
- }
76
- this.config = this.loadFromEnv();
77
- this.config = this.deepMerge(this.config, jsonConfig);
78
- }
79
- /**
80
- * Deep merge two objects
81
- */
82
- deepMerge(target, source) {
83
- const output = { ...target };
84
- if (this.isObject(target) && this.isObject(source)) {
85
- Object.keys(source).forEach((key) => {
86
- if (this.isObject(source[key])) {
87
- if (!(key in target)) {
88
- Object.assign(output, { [key]: source[key] });
89
- } else {
90
- output[key] = this.deepMerge(target[key], source[key]);
91
- }
92
- } else {
93
- Object.assign(output, { [key]: source[key] });
94
- }
95
- });
96
- }
97
- return output;
98
- }
99
- /**
100
- * Check if value is a plain object
101
- */
102
- isObject(item) {
103
- return item && typeof item === "object" && !Array.isArray(item);
104
- }
105
- /**
106
- * Get current configuration
107
- */
108
- getConfig() {
109
- return { ...this.config };
110
- }
111
- };
112
- configService = new ConfigService();
113
- config = {
114
- get port() {
115
- return configService.getConfig().port;
116
- },
117
- get queueServiceType() {
118
- return configService.getConfig().queueServiceType;
119
- },
120
- get redisUrl() {
121
- return configService.getConfig().redisUrl;
122
- },
123
- get redisPassword() {
124
- return configService.getConfig().redisPassword;
125
- },
126
- get queueName() {
127
- return configService.getConfig().queueName;
128
- }
129
- };
130
- }
131
- });
132
-
133
30
  // src/index.ts
134
31
  var index_exports = {};
135
32
  __export(index_exports, {
@@ -147,31 +44,6 @@ var import_messages = require("@langchain/core/messages");
147
44
  var import_langgraph = require("@langchain/langgraph");
148
45
  var import_uuid = require("uuid");
149
46
  var import_core = require("@axiom-lattice/core");
150
- async function fetchDatabaseConfigs(baseURL, apiKey, tenantId) {
151
- try {
152
- const headers = {};
153
- if (apiKey) {
154
- headers["Authorization"] = `Bearer ${apiKey}`;
155
- }
156
- if (tenantId) {
157
- headers["x-tenant-id"] = tenantId;
158
- }
159
- const response = await fetch(`${baseURL}/api/database-configs`, { headers });
160
- if (response.ok) {
161
- const data = await response.json();
162
- if (data.success && data.data && Array.isArray(data.data.records)) {
163
- return data.data.records.map((record) => ({
164
- key: record.key,
165
- name: record.name,
166
- description: record.description
167
- }));
168
- }
169
- }
170
- } catch (error) {
171
- console.error("Failed to fetch database configs:", error);
172
- }
173
- return [];
174
- }
175
47
  function getOrCreateChunkBuffer() {
176
48
  if (!(0, import_core.hasChunkBuffer)("default")) {
177
49
  const buffer = new import_core.InMemoryChunkBuffer({
@@ -203,14 +75,6 @@ async function agent_invoke({
203
75
  if (!runnable_agent) {
204
76
  throw new Error(`Agent ${assistant_id} not found`);
205
77
  }
206
- const { configService: configService2 } = await Promise.resolve().then(() => (init_config(), config_exports));
207
- const gatewayConfig = configService2.getConfig();
208
- const databaseConfigs = await fetchDatabaseConfigs(
209
- gatewayConfig.baseURL || "http://localhost:4001",
210
- void 0,
211
- tenant_id
212
- );
213
- global.__DATABASE_CONFIGS__ = databaseConfigs;
214
78
  const runConfig = {
215
79
  ...agentLattice?.config?.runConfig || {},
216
80
  workspaceId: workspace_id,
@@ -264,14 +128,6 @@ async function agent_stream({
264
128
  messages = [humanMessage];
265
129
  }
266
130
  const chunkBuffer = getOrCreateChunkBuffer();
267
- const { configService: configService2 } = await Promise.resolve().then(() => (init_config(), config_exports));
268
- const gatewayConfig = configService2.getConfig();
269
- const databaseConfigs = await fetchDatabaseConfigs(
270
- gatewayConfig.baseURL || "http://localhost:4001",
271
- void 0,
272
- tenant_id
273
- );
274
- global.__DATABASE_CONFIGS__ = databaseConfigs;
275
131
  const runConfig = {
276
132
  ...agentLattice?.config?.runConfig || {},
277
133
  workspaceId: workspace_id,
@@ -429,12 +285,12 @@ async function resume_stream({
429
285
  var import_core2 = require("@axiom-lattice/core");
430
286
  var import_crypto = require("crypto");
431
287
  var import_core3 = require("@axiom-lattice/core");
432
- function convertAgentConfigToAssistant(config2) {
288
+ function convertAgentConfigToAssistant(config) {
433
289
  return {
434
- id: config2.key,
435
- name: config2.name,
436
- description: config2.description,
437
- graphDefinition: config2,
290
+ id: config.key,
291
+ name: config.name,
292
+ description: config.description,
293
+ graphDefinition: config,
438
294
  // Store the full config as graphDefinition
439
295
  createdAt: /* @__PURE__ */ new Date(0),
440
296
  // Code-configured agents have no creation date
@@ -474,7 +330,7 @@ async function getAssistant(request, reply) {
474
330
  let assistant = await assistantStore.getAssistantById(id);
475
331
  if (!assistant) {
476
332
  const agentConfigs = await (0, import_core3.getAllAgentConfigs)();
477
- const agentConfig = agentConfigs.find((config2) => config2.key === id);
333
+ const agentConfig = agentConfigs.find((config) => config.key === id);
478
334
  if (agentConfig) {
479
335
  assistant = convertAgentConfigToAssistant(agentConfig);
480
336
  }
@@ -549,7 +405,7 @@ async function deleteAssistant(request, reply) {
549
405
  const storeLattice = (0, import_core2.getStoreLattice)("default", "assistant");
550
406
  const assistantStore = storeLattice.store;
551
407
  const agentConfigs = await (0, import_core3.getAllAgentConfigs)();
552
- const isCodeConfigured = agentConfigs.some((config2) => config2.key === id);
408
+ const isCodeConfigured = agentConfigs.some((config) => config.key === id);
553
409
  if (isCodeConfigured) {
554
410
  const exists2 = await assistantStore.hasAssistant(id);
555
411
  if (!exists2) {
@@ -1210,8 +1066,77 @@ async function resumeScheduledTask(request, reply) {
1210
1066
  }
1211
1067
  }
1212
1068
 
1213
- // src/controllers/config.ts
1214
- init_config();
1069
+ // src/config.ts
1070
+ var ConfigService = class {
1071
+ constructor() {
1072
+ this.config = this.loadFromEnv();
1073
+ }
1074
+ /**
1075
+ * Load configuration from environment variables
1076
+ */
1077
+ loadFromEnv() {
1078
+ return {
1079
+ port: process.env.PORT ? Number(process.env.PORT) : void 0,
1080
+ queueServiceType: process.env.QUEUE_SERVICE_TYPE,
1081
+ redisUrl: process.env.REDIS_URL,
1082
+ redisPassword: process.env.REDIS_PASSWORD,
1083
+ queueName: process.env.QUEUE_NAME
1084
+ };
1085
+ }
1086
+ /**
1087
+ * Update configuration from JSON object
1088
+ * This will update both the internal config and process.env
1089
+ */
1090
+ updateConfig(jsonConfig) {
1091
+ for (const [key, value] of Object.entries(jsonConfig)) {
1092
+ if (value !== null && value !== void 0) {
1093
+ if (typeof value === "object" && !Array.isArray(value)) {
1094
+ for (const [nestedKey, nestedValue] of Object.entries(value)) {
1095
+ const envKey = `${key.toUpperCase()}_${nestedKey.toUpperCase()}`;
1096
+ process.env[envKey] = String(nestedValue);
1097
+ }
1098
+ } else {
1099
+ process.env[key.toUpperCase()] = String(value);
1100
+ }
1101
+ }
1102
+ }
1103
+ this.config = this.loadFromEnv();
1104
+ this.config = this.deepMerge(this.config, jsonConfig);
1105
+ }
1106
+ /**
1107
+ * Deep merge two objects
1108
+ */
1109
+ deepMerge(target, source) {
1110
+ const output = { ...target };
1111
+ if (this.isObject(target) && this.isObject(source)) {
1112
+ Object.keys(source).forEach((key) => {
1113
+ if (this.isObject(source[key])) {
1114
+ if (!(key in target)) {
1115
+ Object.assign(output, { [key]: source[key] });
1116
+ } else {
1117
+ output[key] = this.deepMerge(target[key], source[key]);
1118
+ }
1119
+ } else {
1120
+ Object.assign(output, { [key]: source[key] });
1121
+ }
1122
+ });
1123
+ }
1124
+ return output;
1125
+ }
1126
+ /**
1127
+ * Check if value is a plain object
1128
+ */
1129
+ isObject(item) {
1130
+ return item && typeof item === "object" && !Array.isArray(item);
1131
+ }
1132
+ /**
1133
+ * Get current configuration
1134
+ */
1135
+ getConfig() {
1136
+ return { ...this.config };
1137
+ }
1138
+ };
1139
+ var configService = new ConfigService();
1215
1140
 
1216
1141
  // src/services/queue_service.ts
1217
1142
  var import_core7 = require("@axiom-lattice/core");
@@ -1223,7 +1148,7 @@ var setQueueServiceType = (type) => {
1223
1148
  queueServiceType = type;
1224
1149
  console.log(`Queue service type set to: ${type}`);
1225
1150
  const queueName = process.env.QUEUE_NAME || "tasks";
1226
- const config2 = {
1151
+ const config = {
1227
1152
  name: "Default Queue Service",
1228
1153
  description: `Default ${type} queue service`,
1229
1154
  type: type === "redis" ? import_protocols.QueueType.REDIS : import_protocols.QueueType.MEMORY,
@@ -1243,7 +1168,7 @@ var setQueueServiceType = (type) => {
1243
1168
  redisPassword: process.env.REDIS_PASSWORD
1244
1169
  });
1245
1170
  }
1246
- (0, import_core7.registerQueueLattice)(DEFAULT_QUEUE_KEY, config2, client);
1171
+ (0, import_core7.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
1247
1172
  };
1248
1173
  var getQueueService = () => {
1249
1174
  if (!import_core7.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
@@ -1335,18 +1260,18 @@ async function getModels(request, reply) {
1335
1260
  try {
1336
1261
  const allLattices = import_core8.modelLatticeManager.getAllLattices();
1337
1262
  const models = allLattices.map((lattice) => {
1338
- const config2 = lattice.client.config || {};
1263
+ const config = lattice.client.config || {};
1339
1264
  return {
1340
1265
  key: lattice.key,
1341
- model: config2.model || "",
1342
- provider: config2.provider || "openai",
1343
- streaming: config2.streaming || false,
1344
- apiKey: config2.apiKey || "",
1345
- baseURL: config2.baseURL || "",
1346
- maxTokens: config2.maxTokens,
1347
- temperature: config2.temperature,
1348
- timeout: config2.timeout,
1349
- maxRetries: config2.maxRetries
1266
+ model: config.model || "",
1267
+ provider: config.provider || "openai",
1268
+ streaming: config.streaming || false,
1269
+ apiKey: config.apiKey || "",
1270
+ baseURL: config.baseURL || "",
1271
+ maxTokens: config.maxTokens,
1272
+ temperature: config.temperature,
1273
+ timeout: config.timeout,
1274
+ maxRetries: config.maxRetries
1350
1275
  };
1351
1276
  });
1352
1277
  return reply.send({
@@ -1806,15 +1731,15 @@ async function getToolConfigs(request, reply) {
1806
1731
  try {
1807
1732
  const allLattices = import_core11.toolLatticeManager.getAllLattices();
1808
1733
  const toolConfigs = allLattices.map((lattice) => {
1809
- const config2 = { ...lattice.config };
1810
- const serializedSchema = config2.schema ? serializeSchema(config2.schema) : void 0;
1734
+ const config = { ...lattice.config };
1735
+ const serializedSchema = config.schema ? serializeSchema(config.schema) : void 0;
1811
1736
  return {
1812
1737
  id: lattice.key,
1813
- name: config2.name,
1814
- description: config2.description,
1738
+ name: config.name,
1739
+ description: config.description,
1815
1740
  schema: serializedSchema,
1816
- returnDirect: config2.returnDirect,
1817
- needUserApprove: config2.needUserApprove
1741
+ returnDirect: config.returnDirect,
1742
+ needUserApprove: config.needUserApprove
1818
1743
  };
1819
1744
  });
1820
1745
  return reply.send({
@@ -2871,8 +2796,8 @@ async function getDatabaseConfig(request, reply) {
2871
2796
  try {
2872
2797
  const storeLattice = (0, import_core17.getStoreLattice)("default", "database");
2873
2798
  const store = storeLattice.store;
2874
- const config2 = await store.getConfigByKey(tenantId, key);
2875
- if (!config2) {
2799
+ const config = await store.getConfigByKey(tenantId, key);
2800
+ if (!config) {
2876
2801
  return {
2877
2802
  success: false,
2878
2803
  message: "Database configuration not found"
@@ -2881,7 +2806,7 @@ async function getDatabaseConfig(request, reply) {
2881
2806
  return {
2882
2807
  success: true,
2883
2808
  message: "Database configuration retrieved successfully",
2884
- data: config2
2809
+ data: config
2885
2810
  };
2886
2811
  } catch (error) {
2887
2812
  console.error("Failed to get database config:", error);
@@ -2906,9 +2831,9 @@ async function createDatabaseConfig(request, reply) {
2906
2831
  };
2907
2832
  }
2908
2833
  const id = body.id || (0, import_crypto3.randomUUID)();
2909
- const config2 = await store.createConfig(tenantId, id, body);
2834
+ const config = await store.createConfig(tenantId, id, body);
2910
2835
  try {
2911
- import_core17.sqlDatabaseManager.registerDatabase(config2.key, config2.config);
2836
+ import_core17.sqlDatabaseManager.registerDatabase(config.key, config.config);
2912
2837
  } catch (error) {
2913
2838
  console.warn("Failed to auto-register database:", error);
2914
2839
  }
@@ -2916,7 +2841,7 @@ async function createDatabaseConfig(request, reply) {
2916
2841
  return {
2917
2842
  success: true,
2918
2843
  message: "Database configuration created successfully",
2919
- data: config2
2844
+ data: config
2920
2845
  };
2921
2846
  } catch (error) {
2922
2847
  console.error("Failed to create database config:", error);
@@ -2975,23 +2900,23 @@ async function deleteDatabaseConfig(request, reply) {
2975
2900
  const storeLattice = (0, import_core17.getStoreLattice)("default", "database");
2976
2901
  const store = storeLattice.store;
2977
2902
  console.log("Delete request - keyOrId:", keyOrId);
2978
- let config2 = await store.getConfigByKey(tenantId, keyOrId);
2903
+ let config = await store.getConfigByKey(tenantId, keyOrId);
2979
2904
  let configKey = keyOrId;
2980
- if (!config2) {
2981
- config2 = await store.getConfigById(tenantId, keyOrId);
2982
- if (config2) {
2983
- configKey = config2.key;
2905
+ if (!config) {
2906
+ config = await store.getConfigById(tenantId, keyOrId);
2907
+ if (config) {
2908
+ configKey = config.key;
2984
2909
  }
2985
2910
  }
2986
- if (!config2) {
2911
+ if (!config) {
2987
2912
  reply.code(404);
2988
2913
  return {
2989
2914
  success: false,
2990
2915
  message: "Database configuration not found"
2991
2916
  };
2992
2917
  }
2993
- console.log("Found config to delete:", { id: config2.id, key: config2.key });
2994
- const deleted = await store.deleteConfig(tenantId, config2.id);
2918
+ console.log("Found config to delete:", { id: config.id, key: config.key });
2919
+ const deleted = await store.deleteConfig(tenantId, config.id);
2995
2920
  if (!deleted) {
2996
2921
  return {
2997
2922
  success: false,
@@ -3023,8 +2948,8 @@ async function testDatabaseConnection(request, reply) {
3023
2948
  try {
3024
2949
  const storeLattice = (0, import_core17.getStoreLattice)("default", "database");
3025
2950
  const store = storeLattice.store;
3026
- const config2 = await store.getConfigByKey(tenantId, key);
3027
- if (!config2) {
2951
+ const config = await store.getConfigByKey(tenantId, key);
2952
+ if (!config) {
3028
2953
  reply.code(404);
3029
2954
  return {
3030
2955
  success: false,
@@ -3032,7 +2957,7 @@ async function testDatabaseConnection(request, reply) {
3032
2957
  };
3033
2958
  }
3034
2959
  const testKey = `__test_${key}_${Date.now()}`;
3035
- import_core17.sqlDatabaseManager.registerDatabase(testKey, config2.config);
2960
+ import_core17.sqlDatabaseManager.registerDatabase(testKey, config.config);
3036
2961
  const startTime = Date.now();
3037
2962
  const db = import_core17.sqlDatabaseManager.getDatabase(testKey);
3038
2963
  try {
@@ -3142,8 +3067,8 @@ async function getMetricsServerConfig(request, reply) {
3142
3067
  try {
3143
3068
  const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
3144
3069
  const store = storeLattice.store;
3145
- const config2 = await store.getConfigByKey(tenantId, key);
3146
- if (!config2) {
3070
+ const config = await store.getConfigByKey(tenantId, key);
3071
+ if (!config) {
3147
3072
  return {
3148
3073
  success: false,
3149
3074
  message: "Metrics server configuration not found"
@@ -3152,7 +3077,7 @@ async function getMetricsServerConfig(request, reply) {
3152
3077
  return {
3153
3078
  success: true,
3154
3079
  message: "Metrics server configuration retrieved successfully",
3155
- data: config2
3080
+ data: config
3156
3081
  };
3157
3082
  } catch (error) {
3158
3083
  console.error("Failed to get metrics server config:", error);
@@ -3193,9 +3118,9 @@ async function createMetricsServerConfig(request, reply) {
3193
3118
  selectedDataSources: body.selectedDataSources || []
3194
3119
  } : body.config
3195
3120
  };
3196
- const config2 = await store.createConfig(tenantId, id, configData);
3121
+ const config = await store.createConfig(tenantId, id, configData);
3197
3122
  try {
3198
- import_core18.metricsServerManager.registerServer(config2.key, config2.config);
3123
+ import_core18.metricsServerManager.registerServer(config.key, config.config);
3199
3124
  } catch (error) {
3200
3125
  console.warn("Failed to auto-register metrics server:", error);
3201
3126
  }
@@ -3203,7 +3128,7 @@ async function createMetricsServerConfig(request, reply) {
3203
3128
  return {
3204
3129
  success: true,
3205
3130
  message: "Metrics server configuration created successfully",
3206
- data: config2
3131
+ data: config
3207
3132
  };
3208
3133
  } catch (error) {
3209
3134
  console.error("Failed to create metrics server config:", error);
@@ -3270,22 +3195,22 @@ async function deleteMetricsServerConfig(request, reply) {
3270
3195
  try {
3271
3196
  const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
3272
3197
  const store = storeLattice.store;
3273
- let config2 = await store.getConfigByKey(tenantId, keyOrId);
3198
+ let config = await store.getConfigByKey(tenantId, keyOrId);
3274
3199
  let configKey = keyOrId;
3275
- if (!config2) {
3276
- config2 = await store.getConfigById(tenantId, keyOrId);
3277
- if (config2) {
3278
- configKey = config2.key;
3200
+ if (!config) {
3201
+ config = await store.getConfigById(tenantId, keyOrId);
3202
+ if (config) {
3203
+ configKey = config.key;
3279
3204
  }
3280
3205
  }
3281
- if (!config2) {
3206
+ if (!config) {
3282
3207
  reply.code(404);
3283
3208
  return {
3284
3209
  success: false,
3285
3210
  message: "Metrics server configuration not found"
3286
3211
  };
3287
3212
  }
3288
- const deleted = await store.deleteConfig(tenantId, config2.id);
3213
+ const deleted = await store.deleteConfig(tenantId, config.id);
3289
3214
  if (!deleted) {
3290
3215
  return {
3291
3216
  success: false,
@@ -3317,8 +3242,8 @@ async function testMetricsServerConnection(request, reply) {
3317
3242
  try {
3318
3243
  const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
3319
3244
  const store = storeLattice.store;
3320
- const config2 = await store.getConfigByKey(tenantId, key);
3321
- if (!config2) {
3245
+ const config = await store.getConfigByKey(tenantId, key);
3246
+ if (!config) {
3322
3247
  reply.code(404);
3323
3248
  return {
3324
3249
  success: false,
@@ -3326,7 +3251,7 @@ async function testMetricsServerConnection(request, reply) {
3326
3251
  };
3327
3252
  }
3328
3253
  const testKey = `__test_${key}_${Date.now()}`;
3329
- import_core18.metricsServerManager.registerServer(testKey, config2.config);
3254
+ import_core18.metricsServerManager.registerServer(testKey, config.config);
3330
3255
  try {
3331
3256
  const client = import_core18.metricsServerManager.getClient(testKey);
3332
3257
  const result = await client.testConnection();
@@ -3368,8 +3293,8 @@ async function listAvailableMetrics(request, reply) {
3368
3293
  try {
3369
3294
  const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
3370
3295
  const store = storeLattice.store;
3371
- const config2 = await store.getConfigByKey(tenantId, key);
3372
- if (!config2) {
3296
+ const config = await store.getConfigByKey(tenantId, key);
3297
+ if (!config) {
3373
3298
  reply.code(404);
3374
3299
  return {
3375
3300
  success: false,
@@ -3377,7 +3302,7 @@ async function listAvailableMetrics(request, reply) {
3377
3302
  };
3378
3303
  }
3379
3304
  if (!import_core18.metricsServerManager.hasServer(key)) {
3380
- import_core18.metricsServerManager.registerServer(key, config2.config);
3305
+ import_core18.metricsServerManager.registerServer(key, config.config);
3381
3306
  }
3382
3307
  const client = import_core18.metricsServerManager.getClient(key);
3383
3308
  const metrics = await client.listMetrics();
@@ -3407,8 +3332,8 @@ async function queryMetricsData(request, reply) {
3407
3332
  try {
3408
3333
  const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
3409
3334
  const store = storeLattice.store;
3410
- const config2 = await store.getConfigByKey(tenantId, key);
3411
- if (!config2) {
3335
+ const config = await store.getConfigByKey(tenantId, key);
3336
+ if (!config) {
3412
3337
  reply.code(404);
3413
3338
  return {
3414
3339
  success: false,
@@ -3423,7 +3348,7 @@ async function queryMetricsData(request, reply) {
3423
3348
  };
3424
3349
  }
3425
3350
  if (!import_core18.metricsServerManager.hasServer(key)) {
3426
- import_core18.metricsServerManager.registerServer(key, config2.config);
3351
+ import_core18.metricsServerManager.registerServer(key, config.config);
3427
3352
  }
3428
3353
  const client = import_core18.metricsServerManager.getClient(key);
3429
3354
  const result = await client.queryMetricData(metricName, {
@@ -3454,22 +3379,22 @@ async function getDataSources(request, reply) {
3454
3379
  try {
3455
3380
  const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
3456
3381
  const store = storeLattice.store;
3457
- const config2 = await store.getConfigByKey(tenantId, key);
3458
- if (!config2) {
3382
+ const config = await store.getConfigByKey(tenantId, key);
3383
+ if (!config) {
3459
3384
  reply.code(404);
3460
3385
  return {
3461
3386
  success: false,
3462
3387
  message: "Metrics server configuration not found"
3463
3388
  };
3464
3389
  }
3465
- if (config2.config.type !== "semantic") {
3390
+ if (config.config.type !== "semantic") {
3466
3391
  reply.code(400);
3467
3392
  return {
3468
3393
  success: false,
3469
3394
  message: "This endpoint is only available for semantic metrics servers"
3470
3395
  };
3471
3396
  }
3472
- const semanticConfig = config2.config;
3397
+ const semanticConfig = config.config;
3473
3398
  const client = new import_core18.SemanticMetricsClient(semanticConfig);
3474
3399
  const datasources = await client.getDataSources();
3475
3400
  return {
@@ -3493,22 +3418,22 @@ async function getDatasourceMetrics(request, reply) {
3493
3418
  try {
3494
3419
  const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
3495
3420
  const store = storeLattice.store;
3496
- const config2 = await store.getConfigByKey(tenantId, key);
3497
- if (!config2) {
3421
+ const config = await store.getConfigByKey(tenantId, key);
3422
+ if (!config) {
3498
3423
  reply.code(404);
3499
3424
  return {
3500
3425
  success: false,
3501
3426
  message: "Metrics server configuration not found"
3502
3427
  };
3503
3428
  }
3504
- if (config2.config.type !== "semantic") {
3429
+ if (config.config.type !== "semantic") {
3505
3430
  reply.code(400);
3506
3431
  return {
3507
3432
  success: false,
3508
3433
  message: "This endpoint is only available for semantic metrics servers"
3509
3434
  };
3510
3435
  }
3511
- const semanticConfig = config2.config;
3436
+ const semanticConfig = config.config;
3512
3437
  const client = new import_core18.SemanticMetricsClient(semanticConfig);
3513
3438
  const metrics = await client.getDatasourceMetrics(datasourceId);
3514
3439
  return {
@@ -3531,15 +3456,15 @@ async function querySemanticMetrics(request, reply) {
3531
3456
  try {
3532
3457
  const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
3533
3458
  const store = storeLattice.store;
3534
- const config2 = await store.getConfigByKey(tenantId, key);
3535
- if (!config2) {
3459
+ const config = await store.getConfigByKey(tenantId, key);
3460
+ if (!config) {
3536
3461
  reply.code(404);
3537
3462
  return {
3538
3463
  success: false,
3539
3464
  message: "Metrics server configuration not found"
3540
3465
  };
3541
3466
  }
3542
- if (config2.config.type !== "semantic") {
3467
+ if (config.config.type !== "semantic") {
3543
3468
  reply.code(400);
3544
3469
  return {
3545
3470
  success: false,
@@ -3553,7 +3478,7 @@ async function querySemanticMetrics(request, reply) {
3553
3478
  message: "datasourceId and metrics array are required"
3554
3479
  };
3555
3480
  }
3556
- const semanticConfig = config2.config;
3481
+ const semanticConfig = config.config;
3557
3482
  const client = new import_core18.SemanticMetricsClient(semanticConfig);
3558
3483
  const result = await client.semanticQuery(body);
3559
3484
  return {
@@ -3659,12 +3584,437 @@ function registerMetricsServerConfigRoutes(app2) {
3659
3584
  app2.post("/api/metrics-configs/test-datasources/:datasourceId/meta", testDatasourceMetrics);
3660
3585
  }
3661
3586
 
3662
- // src/controllers/users.ts
3587
+ // src/controllers/mcp-configs.ts
3663
3588
  var import_core19 = require("@axiom-lattice/core");
3589
+ var import_crypto5 = require("crypto");
3590
+ function getTenantId3(request) {
3591
+ return request.headers["x-tenant-id"] || "default";
3592
+ }
3593
+ async function getMcpServerConfigList(request, reply) {
3594
+ const tenantId = getTenantId3(request);
3595
+ try {
3596
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3597
+ const store = storeLattice.store;
3598
+ const configs = await store.getAllConfigs(tenantId);
3599
+ return {
3600
+ success: true,
3601
+ message: "MCP server configurations retrieved successfully",
3602
+ data: {
3603
+ records: configs,
3604
+ total: configs.length
3605
+ }
3606
+ };
3607
+ } catch (error) {
3608
+ console.error("Failed to get MCP server configs:", error);
3609
+ return {
3610
+ success: false,
3611
+ message: "Failed to retrieve MCP server configurations",
3612
+ data: {
3613
+ records: [],
3614
+ total: 0
3615
+ }
3616
+ };
3617
+ }
3618
+ }
3619
+ async function getMcpServerConfig(request, reply) {
3620
+ const tenantId = getTenantId3(request);
3621
+ const { key } = request.params;
3622
+ try {
3623
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3624
+ const store = storeLattice.store;
3625
+ const config = await store.getConfigByKey(tenantId, key);
3626
+ if (!config) {
3627
+ return {
3628
+ success: false,
3629
+ message: "MCP server configuration not found"
3630
+ };
3631
+ }
3632
+ return {
3633
+ success: true,
3634
+ message: "MCP server configuration retrieved successfully",
3635
+ data: config
3636
+ };
3637
+ } catch (error) {
3638
+ console.error("Failed to get MCP server config:", error);
3639
+ return {
3640
+ success: false,
3641
+ message: "Failed to retrieve MCP server configuration"
3642
+ };
3643
+ }
3644
+ }
3645
+ async function createMcpServerConfig(request, reply) {
3646
+ const tenantId = getTenantId3(request);
3647
+ const body = request.body;
3648
+ try {
3649
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3650
+ const store = storeLattice.store;
3651
+ const existing = await store.getConfigByKey(tenantId, body.key);
3652
+ if (existing) {
3653
+ reply.code(409);
3654
+ return {
3655
+ success: false,
3656
+ message: "MCP server configuration with this key already exists"
3657
+ };
3658
+ }
3659
+ const id = body.id || (0, import_crypto5.randomUUID)();
3660
+ const config = await store.createConfig(tenantId, id, body);
3661
+ try {
3662
+ await connectAndRegisterTools(config);
3663
+ await store.updateConfig(tenantId, id, { status: "connected" });
3664
+ config.status = "connected";
3665
+ } catch (error) {
3666
+ console.warn("Failed to auto-connect MCP server:", error);
3667
+ await store.updateConfig(tenantId, id, { status: "error" });
3668
+ config.status = "error";
3669
+ }
3670
+ reply.code(201);
3671
+ return {
3672
+ success: true,
3673
+ message: "MCP server configuration created successfully",
3674
+ data: config
3675
+ };
3676
+ } catch (error) {
3677
+ console.error("Failed to create MCP server config:", error);
3678
+ return {
3679
+ success: false,
3680
+ message: "Failed to create MCP server configuration"
3681
+ };
3682
+ }
3683
+ }
3684
+ async function updateMcpServerConfig(request, reply) {
3685
+ const tenantId = getTenantId3(request);
3686
+ const { key } = request.params;
3687
+ const updates = request.body;
3688
+ try {
3689
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3690
+ const store = storeLattice.store;
3691
+ const existing = await store.getConfigByKey(tenantId, key);
3692
+ if (!existing) {
3693
+ reply.code(404);
3694
+ return {
3695
+ success: false,
3696
+ message: "MCP server configuration not found"
3697
+ };
3698
+ }
3699
+ const shouldReconnect = updates.config !== void 0;
3700
+ const updated = await store.updateConfig(tenantId, existing.id, updates);
3701
+ if (!updated) {
3702
+ return {
3703
+ success: false,
3704
+ message: "Failed to update MCP server configuration"
3705
+ };
3706
+ }
3707
+ if (shouldReconnect) {
3708
+ try {
3709
+ if (import_core19.mcpManager.hasServer(key)) {
3710
+ await import_core19.mcpManager.removeServer(key);
3711
+ }
3712
+ await connectAndRegisterTools(updated);
3713
+ await store.updateConfig(tenantId, existing.id, { status: "connected" });
3714
+ updated.status = "connected";
3715
+ } catch (error) {
3716
+ console.warn("Failed to reconnect MCP server:", error);
3717
+ await store.updateConfig(tenantId, existing.id, { status: "error" });
3718
+ updated.status = "error";
3719
+ }
3720
+ }
3721
+ return {
3722
+ success: true,
3723
+ message: "MCP server configuration updated successfully",
3724
+ data: updated
3725
+ };
3726
+ } catch (error) {
3727
+ console.error("Failed to update MCP server config:", error);
3728
+ return {
3729
+ success: false,
3730
+ message: "Failed to update MCP server configuration"
3731
+ };
3732
+ }
3733
+ }
3734
+ async function deleteMcpServerConfig(request, reply) {
3735
+ const tenantId = getTenantId3(request);
3736
+ const { keyOrId } = request.params;
3737
+ try {
3738
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3739
+ const store = storeLattice.store;
3740
+ let config = await store.getConfigByKey(tenantId, keyOrId);
3741
+ let configKey = keyOrId;
3742
+ if (!config) {
3743
+ config = await store.getConfigById(tenantId, keyOrId);
3744
+ if (config) {
3745
+ configKey = config.key;
3746
+ }
3747
+ }
3748
+ if (!config) {
3749
+ reply.code(404);
3750
+ return {
3751
+ success: false,
3752
+ message: "MCP server configuration not found"
3753
+ };
3754
+ }
3755
+ try {
3756
+ if (import_core19.mcpManager.hasServer(configKey)) {
3757
+ await import_core19.mcpManager.removeServer(configKey);
3758
+ }
3759
+ } catch (error) {
3760
+ console.warn("Failed to remove from MCP manager:", error);
3761
+ }
3762
+ const deleted = await store.deleteConfig(tenantId, config.id);
3763
+ if (!deleted) {
3764
+ return {
3765
+ success: false,
3766
+ message: "Failed to delete MCP server configuration"
3767
+ };
3768
+ }
3769
+ return {
3770
+ success: true,
3771
+ message: "MCP server configuration deleted successfully"
3772
+ };
3773
+ } catch (error) {
3774
+ console.error("Failed to delete MCP server config:", error);
3775
+ return {
3776
+ success: false,
3777
+ message: "Failed to delete MCP server configuration"
3778
+ };
3779
+ }
3780
+ }
3781
+ async function testMcpServerConnection(request, reply) {
3782
+ const tenantId = getTenantId3(request);
3783
+ const { key } = request.params;
3784
+ try {
3785
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3786
+ const store = storeLattice.store;
3787
+ const config = await store.getConfigByKey(tenantId, key);
3788
+ if (!config) {
3789
+ reply.code(404);
3790
+ return {
3791
+ success: false,
3792
+ message: "MCP server configuration not found"
3793
+ };
3794
+ }
3795
+ const startTime = Date.now();
3796
+ try {
3797
+ const testKey = `__test_${key}_${Date.now()}`;
3798
+ const connection = convertToConnection(config.config);
3799
+ import_core19.mcpManager.addServer(testKey, connection);
3800
+ await import_core19.mcpManager.connect();
3801
+ const tools = await import_core19.mcpManager.getAllTools();
3802
+ const latency = Date.now() - startTime;
3803
+ await import_core19.mcpManager.removeServer(testKey);
3804
+ return {
3805
+ success: true,
3806
+ message: "Connection test successful",
3807
+ data: {
3808
+ connected: true,
3809
+ latency
3810
+ }
3811
+ };
3812
+ } catch (error) {
3813
+ return {
3814
+ success: true,
3815
+ message: "Connection test failed",
3816
+ data: {
3817
+ connected: false,
3818
+ error: error instanceof Error ? error.message : "Unknown error"
3819
+ }
3820
+ };
3821
+ }
3822
+ } catch (error) {
3823
+ console.error("Failed to test MCP server connection:", error);
3824
+ return {
3825
+ success: false,
3826
+ message: "Failed to test MCP server connection",
3827
+ data: {
3828
+ connected: false,
3829
+ error: error instanceof Error ? error.message : "Unknown error"
3830
+ }
3831
+ };
3832
+ }
3833
+ }
3834
+ async function listMcpServerTools(request, reply) {
3835
+ const tenantId = getTenantId3(request);
3836
+ const { key } = request.params;
3837
+ try {
3838
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3839
+ const store = storeLattice.store;
3840
+ const config = await store.getConfigByKey(tenantId, key);
3841
+ if (!config) {
3842
+ reply.code(404);
3843
+ return {
3844
+ success: false,
3845
+ message: "MCP server configuration not found"
3846
+ };
3847
+ }
3848
+ if (!import_core19.mcpManager.hasServer(key)) {
3849
+ await connectAndRegisterTools(config);
3850
+ }
3851
+ const tools = await import_core19.mcpManager.getAllTools();
3852
+ return {
3853
+ success: true,
3854
+ message: "Tools retrieved successfully",
3855
+ data: {
3856
+ tools
3857
+ }
3858
+ };
3859
+ } catch (error) {
3860
+ console.error("Failed to list MCP tools:", error);
3861
+ return {
3862
+ success: false,
3863
+ message: "Failed to retrieve tools"
3864
+ };
3865
+ }
3866
+ }
3867
+ async function connectMcpServer(request, reply) {
3868
+ const tenantId = getTenantId3(request);
3869
+ const { key } = request.params;
3870
+ try {
3871
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3872
+ const store = storeLattice.store;
3873
+ const config = await store.getConfigByKey(tenantId, key);
3874
+ if (!config) {
3875
+ reply.code(404);
3876
+ return {
3877
+ success: false,
3878
+ message: "MCP server configuration not found"
3879
+ };
3880
+ }
3881
+ await connectAndRegisterTools(config);
3882
+ const updated = await store.updateConfig(tenantId, config.id, {
3883
+ status: "connected"
3884
+ });
3885
+ return {
3886
+ success: true,
3887
+ message: "MCP server connected successfully",
3888
+ data: updated || config
3889
+ };
3890
+ } catch (error) {
3891
+ console.error("Failed to connect MCP server:", error);
3892
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3893
+ const store = storeLattice.store;
3894
+ const config = await store.getConfigByKey(tenantId, key);
3895
+ if (config) {
3896
+ await store.updateConfig(tenantId, config.id, { status: "error" });
3897
+ }
3898
+ return {
3899
+ success: false,
3900
+ message: `Failed to connect MCP server: ${error instanceof Error ? error.message : "Unknown error"}`
3901
+ };
3902
+ }
3903
+ }
3904
+ async function disconnectMcpServer(request, reply) {
3905
+ const tenantId = getTenantId3(request);
3906
+ const { key } = request.params;
3907
+ try {
3908
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3909
+ const store = storeLattice.store;
3910
+ const config = await store.getConfigByKey(tenantId, key);
3911
+ if (!config) {
3912
+ reply.code(404);
3913
+ return {
3914
+ success: false,
3915
+ message: "MCP server configuration not found"
3916
+ };
3917
+ }
3918
+ if (import_core19.mcpManager.hasServer(key)) {
3919
+ await import_core19.mcpManager.removeServer(key);
3920
+ }
3921
+ const updated = await store.updateConfig(tenantId, config.id, {
3922
+ status: "disconnected"
3923
+ });
3924
+ return {
3925
+ success: true,
3926
+ message: "MCP server disconnected successfully",
3927
+ data: updated || config
3928
+ };
3929
+ } catch (error) {
3930
+ console.error("Failed to disconnect MCP server:", error);
3931
+ return {
3932
+ success: false,
3933
+ message: "Failed to disconnect MCP server"
3934
+ };
3935
+ }
3936
+ }
3937
+ async function testMcpServerTools(request, reply) {
3938
+ const body = request.body;
3939
+ try {
3940
+ if (!body.config) {
3941
+ reply.code(400);
3942
+ return {
3943
+ success: false,
3944
+ message: "config is required"
3945
+ };
3946
+ }
3947
+ const testKey = `__test_${Date.now()}`;
3948
+ const connection = convertToConnection(body.config);
3949
+ import_core19.mcpManager.addServer(testKey, connection);
3950
+ await import_core19.mcpManager.connect();
3951
+ const tools = await import_core19.mcpManager.getAllTools();
3952
+ await import_core19.mcpManager.removeServer(testKey);
3953
+ return {
3954
+ success: true,
3955
+ message: "Tools retrieved successfully",
3956
+ data: {
3957
+ tools
3958
+ }
3959
+ };
3960
+ } catch (error) {
3961
+ console.error("Failed to test MCP server tools:", error);
3962
+ return {
3963
+ success: false,
3964
+ message: `Failed to retrieve tools: ${error instanceof Error ? error.message : String(error)}`
3965
+ };
3966
+ }
3967
+ }
3968
+ function convertToConnection(config) {
3969
+ const baseConfig = {
3970
+ env: config.env
3971
+ };
3972
+ if (config.transport === "stdio") {
3973
+ return {
3974
+ ...baseConfig,
3975
+ transport: "stdio",
3976
+ command: config.command,
3977
+ args: config.args || []
3978
+ };
3979
+ } else {
3980
+ return {
3981
+ ...baseConfig,
3982
+ transport: config.transport === "streamable_http" ? "http" : config.transport,
3983
+ url: config.url
3984
+ };
3985
+ }
3986
+ }
3987
+ async function connectAndRegisterTools(config) {
3988
+ const connection = convertToConnection(config.config);
3989
+ import_core19.mcpManager.addServer(config.key, connection);
3990
+ await import_core19.mcpManager.connect();
3991
+ const allTools = await import_core19.mcpManager.getAllTools();
3992
+ const selectedTools = allTools.filter(
3993
+ (tool) => config.selectedTools.includes(tool.name)
3994
+ );
3995
+ for (const tool of selectedTools) {
3996
+ import_core19.toolLatticeManager.registerExistingTool(tool.name, tool);
3997
+ }
3998
+ }
3999
+ function registerMcpServerConfigRoutes(app2) {
4000
+ app2.get("/api/mcp-servers", getMcpServerConfigList);
4001
+ app2.get("/api/mcp-servers/:key", getMcpServerConfig);
4002
+ app2.post("/api/mcp-servers", createMcpServerConfig);
4003
+ app2.put("/api/mcp-servers/:key", updateMcpServerConfig);
4004
+ app2.delete("/api/mcp-servers/:keyOrId", deleteMcpServerConfig);
4005
+ app2.post("/api/mcp-servers/:key/test", testMcpServerConnection);
4006
+ app2.get("/api/mcp-servers/:key/tools", listMcpServerTools);
4007
+ app2.post("/api/mcp-servers/:key/connect", connectMcpServer);
4008
+ app2.post("/api/mcp-servers/:key/disconnect", disconnectMcpServer);
4009
+ app2.post("/api/mcp-servers/test-tools", testMcpServerTools);
4010
+ }
4011
+
4012
+ // src/controllers/users.ts
4013
+ var import_core20 = require("@axiom-lattice/core");
3664
4014
  var import_uuid4 = require("uuid");
3665
4015
  var UsersController = class {
3666
4016
  constructor() {
3667
- this.userStore = (0, import_core19.getStoreLattice)("default", "user").store;
4017
+ this.userStore = (0, import_core20.getStoreLattice)("default", "user").store;
3668
4018
  }
3669
4019
  async listUsers(request, reply) {
3670
4020
  const { email } = request.query;
@@ -3742,11 +4092,11 @@ function registerUserRoutes(app2) {
3742
4092
  }
3743
4093
 
3744
4094
  // src/controllers/tenants.ts
3745
- var import_core20 = require("@axiom-lattice/core");
4095
+ var import_core21 = require("@axiom-lattice/core");
3746
4096
  var import_uuid5 = require("uuid");
3747
4097
  var TenantsController = class {
3748
4098
  constructor() {
3749
- this.tenantStore = (0, import_core20.getStoreLattice)("default", "tenant").store;
4099
+ this.tenantStore = (0, import_core21.getStoreLattice)("default", "tenant").store;
3750
4100
  }
3751
4101
  // ==================== Tenant CRUD ====================
3752
4102
  async listTenants(request, reply) {
@@ -3810,7 +4160,7 @@ function registerTenantRoutes(app2) {
3810
4160
  }
3811
4161
 
3812
4162
  // src/controllers/auth.ts
3813
- var import_core21 = require("@axiom-lattice/core");
4163
+ var import_core22 = require("@axiom-lattice/core");
3814
4164
  var import_uuid6 = require("uuid");
3815
4165
  var defaultAuthConfig = {
3816
4166
  autoApproveUsers: true,
@@ -3818,11 +4168,11 @@ var defaultAuthConfig = {
3818
4168
  tokenExpiration: 86400
3819
4169
  };
3820
4170
  var AuthController = class {
3821
- constructor(config2 = {}) {
3822
- this.userStore = (0, import_core21.getStoreLattice)("default", "user").store;
3823
- this.tenantStore = (0, import_core21.getStoreLattice)("default", "tenant").store;
3824
- this.userTenantLinkStore = (0, import_core21.getStoreLattice)("default", "userTenantLink").store;
3825
- this.config = { ...defaultAuthConfig, ...config2 };
4171
+ constructor(config = {}) {
4172
+ this.userStore = (0, import_core22.getStoreLattice)("default", "user").store;
4173
+ this.tenantStore = (0, import_core22.getStoreLattice)("default", "tenant").store;
4174
+ this.userTenantLinkStore = (0, import_core22.getStoreLattice)("default", "userTenantLink").store;
4175
+ this.config = { ...defaultAuthConfig, ...config };
3826
4176
  }
3827
4177
  async register(request, reply) {
3828
4178
  const { email, password, name } = request.body;
@@ -4097,8 +4447,8 @@ var AuthController = class {
4097
4447
  return btoa(JSON.stringify(payload));
4098
4448
  }
4099
4449
  };
4100
- function registerAuthRoutes(app2, config2) {
4101
- const controller = new AuthController(config2);
4450
+ function registerAuthRoutes(app2, config) {
4451
+ const controller = new AuthController(config);
4102
4452
  const authHook = async (request, reply) => {
4103
4453
  const authHeader = request.headers.authorization;
4104
4454
  if (!authHeader || !authHeader.startsWith("Bearer ")) {
@@ -4258,6 +4608,7 @@ var registerLatticeRoutes = (app2) => {
4258
4608
  registerWorkspaceRoutes(app2);
4259
4609
  registerDatabaseConfigRoutes(app2);
4260
4610
  registerMetricsServerConfigRoutes(app2);
4611
+ registerMcpServerConfigRoutes(app2);
4261
4612
  registerUserRoutes(app2);
4262
4613
  registerTenantRoutes(app2);
4263
4614
  registerAuthRoutes(app2, {
@@ -4329,7 +4680,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
4329
4680
  };
4330
4681
 
4331
4682
  // src/services/agent_task_consumer.ts
4332
- var import_core22 = require("@axiom-lattice/core");
4683
+ var import_core23 = require("@axiom-lattice/core");
4333
4684
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
4334
4685
  const {
4335
4686
  assistant_id,
@@ -4395,7 +4746,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4395
4746
  }
4396
4747
  if (callback_event) {
4397
4748
  const state = await agent_state({ assistant_id, thread_id });
4398
- import_core22.eventBus.publish(callback_event, {
4749
+ import_core23.eventBus.publish(callback_event, {
4399
4750
  success: true,
4400
4751
  state,
4401
4752
  config: { assistant_id, thread_id, tenant_id }
@@ -4409,7 +4760,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4409
4760
  await response.text();
4410
4761
  if (callback_event) {
4411
4762
  const state = await agent_state({ assistant_id, thread_id });
4412
- import_core22.eventBus.publish(callback_event, {
4763
+ import_core23.eventBus.publish(callback_event, {
4413
4764
  success: true,
4414
4765
  state,
4415
4766
  config: { assistant_id, thread_id, tenant_id }
@@ -4436,7 +4787,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4436
4787
  return handleAgentTask(taskRequest, nextRetryCount);
4437
4788
  }
4438
4789
  if (callback_event) {
4439
- import_core22.eventBus.publish(callback_event, {
4790
+ import_core23.eventBus.publish(callback_event, {
4440
4791
  success: false,
4441
4792
  error: error instanceof Error ? error.message : String(error),
4442
4793
  config: { assistant_id, thread_id, tenant_id }
@@ -4474,7 +4825,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
4474
4825
  * 初始化事件监听和队列轮询
4475
4826
  */
4476
4827
  initialize() {
4477
- import_core22.eventBus.subscribe(import_core22.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
4828
+ import_core23.eventBus.subscribe(import_core23.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
4478
4829
  this.startPollingQueue();
4479
4830
  console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
4480
4831
  }
@@ -4593,7 +4944,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
4593
4944
  handleAgentTask(taskRequest).catch((error) => {
4594
4945
  console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
4595
4946
  if (taskRequest.callback_event) {
4596
- import_core22.eventBus.publish(taskRequest.callback_event, {
4947
+ import_core23.eventBus.publish(taskRequest.callback_event, {
4597
4948
  success: false,
4598
4949
  error: error instanceof Error ? error.message : String(error),
4599
4950
  config: {
@@ -4613,7 +4964,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
4613
4964
  var AgentTaskConsumer = _AgentTaskConsumer;
4614
4965
 
4615
4966
  // src/index.ts
4616
- var import_core23 = require("@axiom-lattice/core");
4967
+ var import_core24 = require("@axiom-lattice/core");
4617
4968
  var import_protocols2 = require("@axiom-lattice/protocols");
4618
4969
  process.on("unhandledRejection", (reason, promise) => {
4619
4970
  console.error("\u672A\u5904\u7406\u7684Promise\u62D2\u7EDD:", reason);
@@ -4627,12 +4978,12 @@ var DEFAULT_LOGGER_CONFIG = {
4627
4978
  };
4628
4979
  var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
4629
4980
  var logger = loggerLattice.client;
4630
- function initializeLogger(config2) {
4631
- if (import_core23.loggerLatticeManager.hasLattice("default")) {
4632
- import_core23.loggerLatticeManager.removeLattice("default");
4981
+ function initializeLogger(config) {
4982
+ if (import_core24.loggerLatticeManager.hasLattice("default")) {
4983
+ import_core24.loggerLatticeManager.removeLattice("default");
4633
4984
  }
4634
- (0, import_core23.registerLoggerLattice)("default", config2);
4635
- return (0, import_core23.getLoggerLattice)("default");
4985
+ (0, import_core24.registerLoggerLattice)("default", config);
4986
+ return (0, import_core24.getLoggerLattice)("default");
4636
4987
  }
4637
4988
  var app = (0, import_fastify.default)({
4638
4989
  logger: false,
@@ -4709,23 +5060,23 @@ app.setErrorHandler((error, request, reply) => {
4709
5060
  error: error.message || "\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEF"
4710
5061
  });
4711
5062
  });
4712
- var start = async (config2) => {
5063
+ var start = async (config) => {
4713
5064
  try {
4714
- if (config2?.loggerConfig) {
5065
+ if (config?.loggerConfig) {
4715
5066
  const loggerConfig = {
4716
5067
  ...DEFAULT_LOGGER_CONFIG,
4717
- ...config2.loggerConfig,
5068
+ ...config.loggerConfig,
4718
5069
  // Merge file config if provided
4719
- file: config2.loggerConfig.file || DEFAULT_LOGGER_CONFIG.file
5070
+ file: config.loggerConfig.file || DEFAULT_LOGGER_CONFIG.file
4720
5071
  };
4721
5072
  loggerLattice = initializeLogger(loggerConfig);
4722
5073
  logger = loggerLattice.client;
4723
5074
  }
4724
5075
  app.decorate("loggerLattice", loggerLattice);
4725
- const target_port = config2?.port || Number(process.env.PORT) || 4001;
5076
+ const target_port = config?.port || Number(process.env.PORT) || 4001;
4726
5077
  await app.listen({ port: target_port, host: "0.0.0.0" });
4727
5078
  logger.info(`Lattice Gateway is running on port: ${target_port}`);
4728
- const queueServiceConfig = config2?.queueServiceConfig;
5079
+ const queueServiceConfig = config?.queueServiceConfig;
4729
5080
  if (queueServiceConfig) {
4730
5081
  setQueueServiceType(queueServiceConfig.type);
4731
5082
  if (queueServiceConfig.defaultStartPollingQueue) {