@axiom-lattice/gateway 2.1.35 → 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 {
@@ -3697,8 +3622,8 @@ async function getMcpServerConfig(request, reply) {
3697
3622
  try {
3698
3623
  const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3699
3624
  const store = storeLattice.store;
3700
- const config2 = await store.getConfigByKey(tenantId, key);
3701
- if (!config2) {
3625
+ const config = await store.getConfigByKey(tenantId, key);
3626
+ if (!config) {
3702
3627
  return {
3703
3628
  success: false,
3704
3629
  message: "MCP server configuration not found"
@@ -3707,7 +3632,7 @@ async function getMcpServerConfig(request, reply) {
3707
3632
  return {
3708
3633
  success: true,
3709
3634
  message: "MCP server configuration retrieved successfully",
3710
- data: config2
3635
+ data: config
3711
3636
  };
3712
3637
  } catch (error) {
3713
3638
  console.error("Failed to get MCP server config:", error);
@@ -3732,21 +3657,21 @@ async function createMcpServerConfig(request, reply) {
3732
3657
  };
3733
3658
  }
3734
3659
  const id = body.id || (0, import_crypto5.randomUUID)();
3735
- const config2 = await store.createConfig(tenantId, id, body);
3660
+ const config = await store.createConfig(tenantId, id, body);
3736
3661
  try {
3737
- await connectAndRegisterTools(config2);
3662
+ await connectAndRegisterTools(config);
3738
3663
  await store.updateConfig(tenantId, id, { status: "connected" });
3739
- config2.status = "connected";
3664
+ config.status = "connected";
3740
3665
  } catch (error) {
3741
3666
  console.warn("Failed to auto-connect MCP server:", error);
3742
3667
  await store.updateConfig(tenantId, id, { status: "error" });
3743
- config2.status = "error";
3668
+ config.status = "error";
3744
3669
  }
3745
3670
  reply.code(201);
3746
3671
  return {
3747
3672
  success: true,
3748
3673
  message: "MCP server configuration created successfully",
3749
- data: config2
3674
+ data: config
3750
3675
  };
3751
3676
  } catch (error) {
3752
3677
  console.error("Failed to create MCP server config:", error);
@@ -3812,15 +3737,15 @@ async function deleteMcpServerConfig(request, reply) {
3812
3737
  try {
3813
3738
  const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3814
3739
  const store = storeLattice.store;
3815
- let config2 = await store.getConfigByKey(tenantId, keyOrId);
3740
+ let config = await store.getConfigByKey(tenantId, keyOrId);
3816
3741
  let configKey = keyOrId;
3817
- if (!config2) {
3818
- config2 = await store.getConfigById(tenantId, keyOrId);
3819
- if (config2) {
3820
- configKey = config2.key;
3742
+ if (!config) {
3743
+ config = await store.getConfigById(tenantId, keyOrId);
3744
+ if (config) {
3745
+ configKey = config.key;
3821
3746
  }
3822
3747
  }
3823
- if (!config2) {
3748
+ if (!config) {
3824
3749
  reply.code(404);
3825
3750
  return {
3826
3751
  success: false,
@@ -3834,7 +3759,7 @@ async function deleteMcpServerConfig(request, reply) {
3834
3759
  } catch (error) {
3835
3760
  console.warn("Failed to remove from MCP manager:", error);
3836
3761
  }
3837
- const deleted = await store.deleteConfig(tenantId, config2.id);
3762
+ const deleted = await store.deleteConfig(tenantId, config.id);
3838
3763
  if (!deleted) {
3839
3764
  return {
3840
3765
  success: false,
@@ -3859,8 +3784,8 @@ async function testMcpServerConnection(request, reply) {
3859
3784
  try {
3860
3785
  const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3861
3786
  const store = storeLattice.store;
3862
- const config2 = await store.getConfigByKey(tenantId, key);
3863
- if (!config2) {
3787
+ const config = await store.getConfigByKey(tenantId, key);
3788
+ if (!config) {
3864
3789
  reply.code(404);
3865
3790
  return {
3866
3791
  success: false,
@@ -3870,7 +3795,7 @@ async function testMcpServerConnection(request, reply) {
3870
3795
  const startTime = Date.now();
3871
3796
  try {
3872
3797
  const testKey = `__test_${key}_${Date.now()}`;
3873
- const connection = convertToConnection(config2.config);
3798
+ const connection = convertToConnection(config.config);
3874
3799
  import_core19.mcpManager.addServer(testKey, connection);
3875
3800
  await import_core19.mcpManager.connect();
3876
3801
  const tools = await import_core19.mcpManager.getAllTools();
@@ -3912,8 +3837,8 @@ async function listMcpServerTools(request, reply) {
3912
3837
  try {
3913
3838
  const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3914
3839
  const store = storeLattice.store;
3915
- const config2 = await store.getConfigByKey(tenantId, key);
3916
- if (!config2) {
3840
+ const config = await store.getConfigByKey(tenantId, key);
3841
+ if (!config) {
3917
3842
  reply.code(404);
3918
3843
  return {
3919
3844
  success: false,
@@ -3921,7 +3846,7 @@ async function listMcpServerTools(request, reply) {
3921
3846
  };
3922
3847
  }
3923
3848
  if (!import_core19.mcpManager.hasServer(key)) {
3924
- await connectAndRegisterTools(config2);
3849
+ await connectAndRegisterTools(config);
3925
3850
  }
3926
3851
  const tools = await import_core19.mcpManager.getAllTools();
3927
3852
  return {
@@ -3945,30 +3870,30 @@ async function connectMcpServer(request, reply) {
3945
3870
  try {
3946
3871
  const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3947
3872
  const store = storeLattice.store;
3948
- const config2 = await store.getConfigByKey(tenantId, key);
3949
- if (!config2) {
3873
+ const config = await store.getConfigByKey(tenantId, key);
3874
+ if (!config) {
3950
3875
  reply.code(404);
3951
3876
  return {
3952
3877
  success: false,
3953
3878
  message: "MCP server configuration not found"
3954
3879
  };
3955
3880
  }
3956
- await connectAndRegisterTools(config2);
3957
- const updated = await store.updateConfig(tenantId, config2.id, {
3881
+ await connectAndRegisterTools(config);
3882
+ const updated = await store.updateConfig(tenantId, config.id, {
3958
3883
  status: "connected"
3959
3884
  });
3960
3885
  return {
3961
3886
  success: true,
3962
3887
  message: "MCP server connected successfully",
3963
- data: updated || config2
3888
+ data: updated || config
3964
3889
  };
3965
3890
  } catch (error) {
3966
3891
  console.error("Failed to connect MCP server:", error);
3967
3892
  const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3968
3893
  const store = storeLattice.store;
3969
- const config2 = await store.getConfigByKey(tenantId, key);
3970
- if (config2) {
3971
- await store.updateConfig(tenantId, config2.id, { status: "error" });
3894
+ const config = await store.getConfigByKey(tenantId, key);
3895
+ if (config) {
3896
+ await store.updateConfig(tenantId, config.id, { status: "error" });
3972
3897
  }
3973
3898
  return {
3974
3899
  success: false,
@@ -3982,8 +3907,8 @@ async function disconnectMcpServer(request, reply) {
3982
3907
  try {
3983
3908
  const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
3984
3909
  const store = storeLattice.store;
3985
- const config2 = await store.getConfigByKey(tenantId, key);
3986
- if (!config2) {
3910
+ const config = await store.getConfigByKey(tenantId, key);
3911
+ if (!config) {
3987
3912
  reply.code(404);
3988
3913
  return {
3989
3914
  success: false,
@@ -3993,13 +3918,13 @@ async function disconnectMcpServer(request, reply) {
3993
3918
  if (import_core19.mcpManager.hasServer(key)) {
3994
3919
  await import_core19.mcpManager.removeServer(key);
3995
3920
  }
3996
- const updated = await store.updateConfig(tenantId, config2.id, {
3921
+ const updated = await store.updateConfig(tenantId, config.id, {
3997
3922
  status: "disconnected"
3998
3923
  });
3999
3924
  return {
4000
3925
  success: true,
4001
3926
  message: "MCP server disconnected successfully",
4002
- data: updated || config2
3927
+ data: updated || config
4003
3928
  };
4004
3929
  } catch (error) {
4005
3930
  console.error("Failed to disconnect MCP server:", error);
@@ -4040,32 +3965,32 @@ async function testMcpServerTools(request, reply) {
4040
3965
  };
4041
3966
  }
4042
3967
  }
4043
- function convertToConnection(config2) {
3968
+ function convertToConnection(config) {
4044
3969
  const baseConfig = {
4045
- env: config2.env
3970
+ env: config.env
4046
3971
  };
4047
- if (config2.transport === "stdio") {
3972
+ if (config.transport === "stdio") {
4048
3973
  return {
4049
3974
  ...baseConfig,
4050
3975
  transport: "stdio",
4051
- command: config2.command,
4052
- args: config2.args || []
3976
+ command: config.command,
3977
+ args: config.args || []
4053
3978
  };
4054
3979
  } else {
4055
3980
  return {
4056
3981
  ...baseConfig,
4057
- transport: config2.transport === "streamable_http" ? "http" : config2.transport,
4058
- url: config2.url
3982
+ transport: config.transport === "streamable_http" ? "http" : config.transport,
3983
+ url: config.url
4059
3984
  };
4060
3985
  }
4061
3986
  }
4062
- async function connectAndRegisterTools(config2) {
4063
- const connection = convertToConnection(config2.config);
4064
- import_core19.mcpManager.addServer(config2.key, connection);
3987
+ async function connectAndRegisterTools(config) {
3988
+ const connection = convertToConnection(config.config);
3989
+ import_core19.mcpManager.addServer(config.key, connection);
4065
3990
  await import_core19.mcpManager.connect();
4066
3991
  const allTools = await import_core19.mcpManager.getAllTools();
4067
3992
  const selectedTools = allTools.filter(
4068
- (tool) => config2.selectedTools.includes(tool.name)
3993
+ (tool) => config.selectedTools.includes(tool.name)
4069
3994
  );
4070
3995
  for (const tool of selectedTools) {
4071
3996
  import_core19.toolLatticeManager.registerExistingTool(tool.name, tool);
@@ -4243,11 +4168,11 @@ var defaultAuthConfig = {
4243
4168
  tokenExpiration: 86400
4244
4169
  };
4245
4170
  var AuthController = class {
4246
- constructor(config2 = {}) {
4171
+ constructor(config = {}) {
4247
4172
  this.userStore = (0, import_core22.getStoreLattice)("default", "user").store;
4248
4173
  this.tenantStore = (0, import_core22.getStoreLattice)("default", "tenant").store;
4249
4174
  this.userTenantLinkStore = (0, import_core22.getStoreLattice)("default", "userTenantLink").store;
4250
- this.config = { ...defaultAuthConfig, ...config2 };
4175
+ this.config = { ...defaultAuthConfig, ...config };
4251
4176
  }
4252
4177
  async register(request, reply) {
4253
4178
  const { email, password, name } = request.body;
@@ -4522,8 +4447,8 @@ var AuthController = class {
4522
4447
  return btoa(JSON.stringify(payload));
4523
4448
  }
4524
4449
  };
4525
- function registerAuthRoutes(app2, config2) {
4526
- const controller = new AuthController(config2);
4450
+ function registerAuthRoutes(app2, config) {
4451
+ const controller = new AuthController(config);
4527
4452
  const authHook = async (request, reply) => {
4528
4453
  const authHeader = request.headers.authorization;
4529
4454
  if (!authHeader || !authHeader.startsWith("Bearer ")) {
@@ -5053,11 +4978,11 @@ var DEFAULT_LOGGER_CONFIG = {
5053
4978
  };
5054
4979
  var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
5055
4980
  var logger = loggerLattice.client;
5056
- function initializeLogger(config2) {
4981
+ function initializeLogger(config) {
5057
4982
  if (import_core24.loggerLatticeManager.hasLattice("default")) {
5058
4983
  import_core24.loggerLatticeManager.removeLattice("default");
5059
4984
  }
5060
- (0, import_core24.registerLoggerLattice)("default", config2);
4985
+ (0, import_core24.registerLoggerLattice)("default", config);
5061
4986
  return (0, import_core24.getLoggerLattice)("default");
5062
4987
  }
5063
4988
  var app = (0, import_fastify.default)({
@@ -5135,23 +5060,23 @@ app.setErrorHandler((error, request, reply) => {
5135
5060
  error: error.message || "\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEF"
5136
5061
  });
5137
5062
  });
5138
- var start = async (config2) => {
5063
+ var start = async (config) => {
5139
5064
  try {
5140
- if (config2?.loggerConfig) {
5065
+ if (config?.loggerConfig) {
5141
5066
  const loggerConfig = {
5142
5067
  ...DEFAULT_LOGGER_CONFIG,
5143
- ...config2.loggerConfig,
5068
+ ...config.loggerConfig,
5144
5069
  // Merge file config if provided
5145
- file: config2.loggerConfig.file || DEFAULT_LOGGER_CONFIG.file
5070
+ file: config.loggerConfig.file || DEFAULT_LOGGER_CONFIG.file
5146
5071
  };
5147
5072
  loggerLattice = initializeLogger(loggerConfig);
5148
5073
  logger = loggerLattice.client;
5149
5074
  }
5150
5075
  app.decorate("loggerLattice", loggerLattice);
5151
- const target_port = config2?.port || Number(process.env.PORT) || 4001;
5076
+ const target_port = config?.port || Number(process.env.PORT) || 4001;
5152
5077
  await app.listen({ port: target_port, host: "0.0.0.0" });
5153
5078
  logger.info(`Lattice Gateway is running on port: ${target_port}`);
5154
- const queueServiceConfig = config2?.queueServiceConfig;
5079
+ const queueServiceConfig = config?.queueServiceConfig;
5155
5080
  if (queueServiceConfig) {
5156
5081
  setQueueServiceType(queueServiceConfig.type);
5157
5082
  if (queueServiceConfig.defaultStartPollingQueue) {