@axiom-lattice/gateway 2.1.35 → 2.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +8 -12
- package/CHANGELOG.md +16 -0
- package/dist/index.js +207 -280
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/controllers/metrics-configs.ts +8 -2
- package/src/services/agent_service.ts +0 -53
- package/dist/chunk-FSASG3SB.mjs +0 -94
- package/dist/chunk-FSASG3SB.mjs.map +0 -1
- package/dist/config-F3FCBSPH.mjs +0 -9
- package/dist/config-F3FCBSPH.mjs.map +0 -1
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(
|
|
288
|
+
function convertAgentConfigToAssistant(config) {
|
|
433
289
|
return {
|
|
434
|
-
id:
|
|
435
|
-
name:
|
|
436
|
-
description:
|
|
437
|
-
graphDefinition:
|
|
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((
|
|
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((
|
|
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/
|
|
1214
|
-
|
|
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
|
|
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,
|
|
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
|
|
1263
|
+
const config = lattice.client.config || {};
|
|
1339
1264
|
return {
|
|
1340
1265
|
key: lattice.key,
|
|
1341
|
-
model:
|
|
1342
|
-
provider:
|
|
1343
|
-
streaming:
|
|
1344
|
-
apiKey:
|
|
1345
|
-
baseURL:
|
|
1346
|
-
maxTokens:
|
|
1347
|
-
temperature:
|
|
1348
|
-
timeout:
|
|
1349
|
-
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
|
|
1810
|
-
const serializedSchema =
|
|
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:
|
|
1814
|
-
description:
|
|
1738
|
+
name: config.name,
|
|
1739
|
+
description: config.description,
|
|
1815
1740
|
schema: serializedSchema,
|
|
1816
|
-
returnDirect:
|
|
1817
|
-
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
|
|
2875
|
-
if (!
|
|
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:
|
|
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
|
|
2834
|
+
const config = await store.createConfig(tenantId, id, body);
|
|
2910
2835
|
try {
|
|
2911
|
-
import_core17.sqlDatabaseManager.registerDatabase(
|
|
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:
|
|
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
|
|
2903
|
+
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
2979
2904
|
let configKey = keyOrId;
|
|
2980
|
-
if (!
|
|
2981
|
-
|
|
2982
|
-
if (
|
|
2983
|
-
configKey =
|
|
2905
|
+
if (!config) {
|
|
2906
|
+
config = await store.getConfigById(tenantId, keyOrId);
|
|
2907
|
+
if (config) {
|
|
2908
|
+
configKey = config.key;
|
|
2984
2909
|
}
|
|
2985
2910
|
}
|
|
2986
|
-
if (!
|
|
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:
|
|
2994
|
-
const deleted = await store.deleteConfig(tenantId,
|
|
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
|
|
3027
|
-
if (!
|
|
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,
|
|
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
|
|
3146
|
-
if (!
|
|
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:
|
|
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
|
|
3121
|
+
const config = await store.createConfig(tenantId, id, configData);
|
|
3197
3122
|
try {
|
|
3198
|
-
import_core18.metricsServerManager.registerServer(
|
|
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:
|
|
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
|
|
3198
|
+
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
3274
3199
|
let configKey = keyOrId;
|
|
3275
|
-
if (!
|
|
3276
|
-
|
|
3277
|
-
if (
|
|
3278
|
-
configKey =
|
|
3200
|
+
if (!config) {
|
|
3201
|
+
config = await store.getConfigById(tenantId, keyOrId);
|
|
3202
|
+
if (config) {
|
|
3203
|
+
configKey = config.key;
|
|
3279
3204
|
}
|
|
3280
3205
|
}
|
|
3281
|
-
if (!
|
|
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,
|
|
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
|
|
3321
|
-
if (!
|
|
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,
|
|
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
|
|
3372
|
-
if (!
|
|
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,
|
|
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
|
|
3411
|
-
if (!
|
|
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,
|
|
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,29 +3379,31 @@ 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
|
|
3458
|
-
if (!
|
|
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 (
|
|
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 =
|
|
3397
|
+
const semanticConfig = config.config;
|
|
3473
3398
|
const client = new import_core18.SemanticMetricsClient(semanticConfig);
|
|
3474
|
-
const
|
|
3399
|
+
const allDatasources = await client.getDataSources();
|
|
3400
|
+
const selectedIds = semanticConfig.selectedDataSources || [];
|
|
3401
|
+
const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
|
|
3475
3402
|
return {
|
|
3476
3403
|
success: true,
|
|
3477
3404
|
message: "Data sources retrieved successfully",
|
|
3478
3405
|
data: {
|
|
3479
|
-
datasources
|
|
3406
|
+
datasources: filteredDatasources
|
|
3480
3407
|
}
|
|
3481
3408
|
};
|
|
3482
3409
|
} catch (error) {
|
|
@@ -3493,22 +3420,22 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
3493
3420
|
try {
|
|
3494
3421
|
const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
|
|
3495
3422
|
const store = storeLattice.store;
|
|
3496
|
-
const
|
|
3497
|
-
if (!
|
|
3423
|
+
const config = await store.getConfigByKey(tenantId, key);
|
|
3424
|
+
if (!config) {
|
|
3498
3425
|
reply.code(404);
|
|
3499
3426
|
return {
|
|
3500
3427
|
success: false,
|
|
3501
3428
|
message: "Metrics server configuration not found"
|
|
3502
3429
|
};
|
|
3503
3430
|
}
|
|
3504
|
-
if (
|
|
3431
|
+
if (config.config.type !== "semantic") {
|
|
3505
3432
|
reply.code(400);
|
|
3506
3433
|
return {
|
|
3507
3434
|
success: false,
|
|
3508
3435
|
message: "This endpoint is only available for semantic metrics servers"
|
|
3509
3436
|
};
|
|
3510
3437
|
}
|
|
3511
|
-
const semanticConfig =
|
|
3438
|
+
const semanticConfig = config.config;
|
|
3512
3439
|
const client = new import_core18.SemanticMetricsClient(semanticConfig);
|
|
3513
3440
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
3514
3441
|
return {
|
|
@@ -3531,15 +3458,15 @@ async function querySemanticMetrics(request, reply) {
|
|
|
3531
3458
|
try {
|
|
3532
3459
|
const storeLattice = (0, import_core18.getStoreLattice)("default", "metrics");
|
|
3533
3460
|
const store = storeLattice.store;
|
|
3534
|
-
const
|
|
3535
|
-
if (!
|
|
3461
|
+
const config = await store.getConfigByKey(tenantId, key);
|
|
3462
|
+
if (!config) {
|
|
3536
3463
|
reply.code(404);
|
|
3537
3464
|
return {
|
|
3538
3465
|
success: false,
|
|
3539
3466
|
message: "Metrics server configuration not found"
|
|
3540
3467
|
};
|
|
3541
3468
|
}
|
|
3542
|
-
if (
|
|
3469
|
+
if (config.config.type !== "semantic") {
|
|
3543
3470
|
reply.code(400);
|
|
3544
3471
|
return {
|
|
3545
3472
|
success: false,
|
|
@@ -3553,7 +3480,7 @@ async function querySemanticMetrics(request, reply) {
|
|
|
3553
3480
|
message: "datasourceId and metrics array are required"
|
|
3554
3481
|
};
|
|
3555
3482
|
}
|
|
3556
|
-
const semanticConfig =
|
|
3483
|
+
const semanticConfig = config.config;
|
|
3557
3484
|
const client = new import_core18.SemanticMetricsClient(semanticConfig);
|
|
3558
3485
|
const result = await client.semanticQuery(body);
|
|
3559
3486
|
return {
|
|
@@ -3697,8 +3624,8 @@ async function getMcpServerConfig(request, reply) {
|
|
|
3697
3624
|
try {
|
|
3698
3625
|
const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
|
|
3699
3626
|
const store = storeLattice.store;
|
|
3700
|
-
const
|
|
3701
|
-
if (!
|
|
3627
|
+
const config = await store.getConfigByKey(tenantId, key);
|
|
3628
|
+
if (!config) {
|
|
3702
3629
|
return {
|
|
3703
3630
|
success: false,
|
|
3704
3631
|
message: "MCP server configuration not found"
|
|
@@ -3707,7 +3634,7 @@ async function getMcpServerConfig(request, reply) {
|
|
|
3707
3634
|
return {
|
|
3708
3635
|
success: true,
|
|
3709
3636
|
message: "MCP server configuration retrieved successfully",
|
|
3710
|
-
data:
|
|
3637
|
+
data: config
|
|
3711
3638
|
};
|
|
3712
3639
|
} catch (error) {
|
|
3713
3640
|
console.error("Failed to get MCP server config:", error);
|
|
@@ -3732,21 +3659,21 @@ async function createMcpServerConfig(request, reply) {
|
|
|
3732
3659
|
};
|
|
3733
3660
|
}
|
|
3734
3661
|
const id = body.id || (0, import_crypto5.randomUUID)();
|
|
3735
|
-
const
|
|
3662
|
+
const config = await store.createConfig(tenantId, id, body);
|
|
3736
3663
|
try {
|
|
3737
|
-
await connectAndRegisterTools(
|
|
3664
|
+
await connectAndRegisterTools(config);
|
|
3738
3665
|
await store.updateConfig(tenantId, id, { status: "connected" });
|
|
3739
|
-
|
|
3666
|
+
config.status = "connected";
|
|
3740
3667
|
} catch (error) {
|
|
3741
3668
|
console.warn("Failed to auto-connect MCP server:", error);
|
|
3742
3669
|
await store.updateConfig(tenantId, id, { status: "error" });
|
|
3743
|
-
|
|
3670
|
+
config.status = "error";
|
|
3744
3671
|
}
|
|
3745
3672
|
reply.code(201);
|
|
3746
3673
|
return {
|
|
3747
3674
|
success: true,
|
|
3748
3675
|
message: "MCP server configuration created successfully",
|
|
3749
|
-
data:
|
|
3676
|
+
data: config
|
|
3750
3677
|
};
|
|
3751
3678
|
} catch (error) {
|
|
3752
3679
|
console.error("Failed to create MCP server config:", error);
|
|
@@ -3812,15 +3739,15 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
3812
3739
|
try {
|
|
3813
3740
|
const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
|
|
3814
3741
|
const store = storeLattice.store;
|
|
3815
|
-
let
|
|
3742
|
+
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
3816
3743
|
let configKey = keyOrId;
|
|
3817
|
-
if (!
|
|
3818
|
-
|
|
3819
|
-
if (
|
|
3820
|
-
configKey =
|
|
3744
|
+
if (!config) {
|
|
3745
|
+
config = await store.getConfigById(tenantId, keyOrId);
|
|
3746
|
+
if (config) {
|
|
3747
|
+
configKey = config.key;
|
|
3821
3748
|
}
|
|
3822
3749
|
}
|
|
3823
|
-
if (!
|
|
3750
|
+
if (!config) {
|
|
3824
3751
|
reply.code(404);
|
|
3825
3752
|
return {
|
|
3826
3753
|
success: false,
|
|
@@ -3834,7 +3761,7 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
3834
3761
|
} catch (error) {
|
|
3835
3762
|
console.warn("Failed to remove from MCP manager:", error);
|
|
3836
3763
|
}
|
|
3837
|
-
const deleted = await store.deleteConfig(tenantId,
|
|
3764
|
+
const deleted = await store.deleteConfig(tenantId, config.id);
|
|
3838
3765
|
if (!deleted) {
|
|
3839
3766
|
return {
|
|
3840
3767
|
success: false,
|
|
@@ -3859,8 +3786,8 @@ async function testMcpServerConnection(request, reply) {
|
|
|
3859
3786
|
try {
|
|
3860
3787
|
const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
|
|
3861
3788
|
const store = storeLattice.store;
|
|
3862
|
-
const
|
|
3863
|
-
if (!
|
|
3789
|
+
const config = await store.getConfigByKey(tenantId, key);
|
|
3790
|
+
if (!config) {
|
|
3864
3791
|
reply.code(404);
|
|
3865
3792
|
return {
|
|
3866
3793
|
success: false,
|
|
@@ -3870,7 +3797,7 @@ async function testMcpServerConnection(request, reply) {
|
|
|
3870
3797
|
const startTime = Date.now();
|
|
3871
3798
|
try {
|
|
3872
3799
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
3873
|
-
const connection = convertToConnection(
|
|
3800
|
+
const connection = convertToConnection(config.config);
|
|
3874
3801
|
import_core19.mcpManager.addServer(testKey, connection);
|
|
3875
3802
|
await import_core19.mcpManager.connect();
|
|
3876
3803
|
const tools = await import_core19.mcpManager.getAllTools();
|
|
@@ -3912,8 +3839,8 @@ async function listMcpServerTools(request, reply) {
|
|
|
3912
3839
|
try {
|
|
3913
3840
|
const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
|
|
3914
3841
|
const store = storeLattice.store;
|
|
3915
|
-
const
|
|
3916
|
-
if (!
|
|
3842
|
+
const config = await store.getConfigByKey(tenantId, key);
|
|
3843
|
+
if (!config) {
|
|
3917
3844
|
reply.code(404);
|
|
3918
3845
|
return {
|
|
3919
3846
|
success: false,
|
|
@@ -3921,7 +3848,7 @@ async function listMcpServerTools(request, reply) {
|
|
|
3921
3848
|
};
|
|
3922
3849
|
}
|
|
3923
3850
|
if (!import_core19.mcpManager.hasServer(key)) {
|
|
3924
|
-
await connectAndRegisterTools(
|
|
3851
|
+
await connectAndRegisterTools(config);
|
|
3925
3852
|
}
|
|
3926
3853
|
const tools = await import_core19.mcpManager.getAllTools();
|
|
3927
3854
|
return {
|
|
@@ -3945,30 +3872,30 @@ async function connectMcpServer(request, reply) {
|
|
|
3945
3872
|
try {
|
|
3946
3873
|
const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
|
|
3947
3874
|
const store = storeLattice.store;
|
|
3948
|
-
const
|
|
3949
|
-
if (!
|
|
3875
|
+
const config = await store.getConfigByKey(tenantId, key);
|
|
3876
|
+
if (!config) {
|
|
3950
3877
|
reply.code(404);
|
|
3951
3878
|
return {
|
|
3952
3879
|
success: false,
|
|
3953
3880
|
message: "MCP server configuration not found"
|
|
3954
3881
|
};
|
|
3955
3882
|
}
|
|
3956
|
-
await connectAndRegisterTools(
|
|
3957
|
-
const updated = await store.updateConfig(tenantId,
|
|
3883
|
+
await connectAndRegisterTools(config);
|
|
3884
|
+
const updated = await store.updateConfig(tenantId, config.id, {
|
|
3958
3885
|
status: "connected"
|
|
3959
3886
|
});
|
|
3960
3887
|
return {
|
|
3961
3888
|
success: true,
|
|
3962
3889
|
message: "MCP server connected successfully",
|
|
3963
|
-
data: updated ||
|
|
3890
|
+
data: updated || config
|
|
3964
3891
|
};
|
|
3965
3892
|
} catch (error) {
|
|
3966
3893
|
console.error("Failed to connect MCP server:", error);
|
|
3967
3894
|
const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
|
|
3968
3895
|
const store = storeLattice.store;
|
|
3969
|
-
const
|
|
3970
|
-
if (
|
|
3971
|
-
await store.updateConfig(tenantId,
|
|
3896
|
+
const config = await store.getConfigByKey(tenantId, key);
|
|
3897
|
+
if (config) {
|
|
3898
|
+
await store.updateConfig(tenantId, config.id, { status: "error" });
|
|
3972
3899
|
}
|
|
3973
3900
|
return {
|
|
3974
3901
|
success: false,
|
|
@@ -3982,8 +3909,8 @@ async function disconnectMcpServer(request, reply) {
|
|
|
3982
3909
|
try {
|
|
3983
3910
|
const storeLattice = (0, import_core19.getStoreLattice)("default", "mcp");
|
|
3984
3911
|
const store = storeLattice.store;
|
|
3985
|
-
const
|
|
3986
|
-
if (!
|
|
3912
|
+
const config = await store.getConfigByKey(tenantId, key);
|
|
3913
|
+
if (!config) {
|
|
3987
3914
|
reply.code(404);
|
|
3988
3915
|
return {
|
|
3989
3916
|
success: false,
|
|
@@ -3993,13 +3920,13 @@ async function disconnectMcpServer(request, reply) {
|
|
|
3993
3920
|
if (import_core19.mcpManager.hasServer(key)) {
|
|
3994
3921
|
await import_core19.mcpManager.removeServer(key);
|
|
3995
3922
|
}
|
|
3996
|
-
const updated = await store.updateConfig(tenantId,
|
|
3923
|
+
const updated = await store.updateConfig(tenantId, config.id, {
|
|
3997
3924
|
status: "disconnected"
|
|
3998
3925
|
});
|
|
3999
3926
|
return {
|
|
4000
3927
|
success: true,
|
|
4001
3928
|
message: "MCP server disconnected successfully",
|
|
4002
|
-
data: updated ||
|
|
3929
|
+
data: updated || config
|
|
4003
3930
|
};
|
|
4004
3931
|
} catch (error) {
|
|
4005
3932
|
console.error("Failed to disconnect MCP server:", error);
|
|
@@ -4040,32 +3967,32 @@ async function testMcpServerTools(request, reply) {
|
|
|
4040
3967
|
};
|
|
4041
3968
|
}
|
|
4042
3969
|
}
|
|
4043
|
-
function convertToConnection(
|
|
3970
|
+
function convertToConnection(config) {
|
|
4044
3971
|
const baseConfig = {
|
|
4045
|
-
env:
|
|
3972
|
+
env: config.env
|
|
4046
3973
|
};
|
|
4047
|
-
if (
|
|
3974
|
+
if (config.transport === "stdio") {
|
|
4048
3975
|
return {
|
|
4049
3976
|
...baseConfig,
|
|
4050
3977
|
transport: "stdio",
|
|
4051
|
-
command:
|
|
4052
|
-
args:
|
|
3978
|
+
command: config.command,
|
|
3979
|
+
args: config.args || []
|
|
4053
3980
|
};
|
|
4054
3981
|
} else {
|
|
4055
3982
|
return {
|
|
4056
3983
|
...baseConfig,
|
|
4057
|
-
transport:
|
|
4058
|
-
url:
|
|
3984
|
+
transport: config.transport === "streamable_http" ? "http" : config.transport,
|
|
3985
|
+
url: config.url
|
|
4059
3986
|
};
|
|
4060
3987
|
}
|
|
4061
3988
|
}
|
|
4062
|
-
async function connectAndRegisterTools(
|
|
4063
|
-
const connection = convertToConnection(
|
|
4064
|
-
import_core19.mcpManager.addServer(
|
|
3989
|
+
async function connectAndRegisterTools(config) {
|
|
3990
|
+
const connection = convertToConnection(config.config);
|
|
3991
|
+
import_core19.mcpManager.addServer(config.key, connection);
|
|
4065
3992
|
await import_core19.mcpManager.connect();
|
|
4066
3993
|
const allTools = await import_core19.mcpManager.getAllTools();
|
|
4067
3994
|
const selectedTools = allTools.filter(
|
|
4068
|
-
(tool) =>
|
|
3995
|
+
(tool) => config.selectedTools.includes(tool.name)
|
|
4069
3996
|
);
|
|
4070
3997
|
for (const tool of selectedTools) {
|
|
4071
3998
|
import_core19.toolLatticeManager.registerExistingTool(tool.name, tool);
|
|
@@ -4243,11 +4170,11 @@ var defaultAuthConfig = {
|
|
|
4243
4170
|
tokenExpiration: 86400
|
|
4244
4171
|
};
|
|
4245
4172
|
var AuthController = class {
|
|
4246
|
-
constructor(
|
|
4173
|
+
constructor(config = {}) {
|
|
4247
4174
|
this.userStore = (0, import_core22.getStoreLattice)("default", "user").store;
|
|
4248
4175
|
this.tenantStore = (0, import_core22.getStoreLattice)("default", "tenant").store;
|
|
4249
4176
|
this.userTenantLinkStore = (0, import_core22.getStoreLattice)("default", "userTenantLink").store;
|
|
4250
|
-
this.config = { ...defaultAuthConfig, ...
|
|
4177
|
+
this.config = { ...defaultAuthConfig, ...config };
|
|
4251
4178
|
}
|
|
4252
4179
|
async register(request, reply) {
|
|
4253
4180
|
const { email, password, name } = request.body;
|
|
@@ -4522,8 +4449,8 @@ var AuthController = class {
|
|
|
4522
4449
|
return btoa(JSON.stringify(payload));
|
|
4523
4450
|
}
|
|
4524
4451
|
};
|
|
4525
|
-
function registerAuthRoutes(app2,
|
|
4526
|
-
const controller = new AuthController(
|
|
4452
|
+
function registerAuthRoutes(app2, config) {
|
|
4453
|
+
const controller = new AuthController(config);
|
|
4527
4454
|
const authHook = async (request, reply) => {
|
|
4528
4455
|
const authHeader = request.headers.authorization;
|
|
4529
4456
|
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
@@ -5053,11 +4980,11 @@ var DEFAULT_LOGGER_CONFIG = {
|
|
|
5053
4980
|
};
|
|
5054
4981
|
var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
|
|
5055
4982
|
var logger = loggerLattice.client;
|
|
5056
|
-
function initializeLogger(
|
|
4983
|
+
function initializeLogger(config) {
|
|
5057
4984
|
if (import_core24.loggerLatticeManager.hasLattice("default")) {
|
|
5058
4985
|
import_core24.loggerLatticeManager.removeLattice("default");
|
|
5059
4986
|
}
|
|
5060
|
-
(0, import_core24.registerLoggerLattice)("default",
|
|
4987
|
+
(0, import_core24.registerLoggerLattice)("default", config);
|
|
5061
4988
|
return (0, import_core24.getLoggerLattice)("default");
|
|
5062
4989
|
}
|
|
5063
4990
|
var app = (0, import_fastify.default)({
|
|
@@ -5135,23 +5062,23 @@ app.setErrorHandler((error, request, reply) => {
|
|
|
5135
5062
|
error: error.message || "\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEF"
|
|
5136
5063
|
});
|
|
5137
5064
|
});
|
|
5138
|
-
var start = async (
|
|
5065
|
+
var start = async (config) => {
|
|
5139
5066
|
try {
|
|
5140
|
-
if (
|
|
5067
|
+
if (config?.loggerConfig) {
|
|
5141
5068
|
const loggerConfig = {
|
|
5142
5069
|
...DEFAULT_LOGGER_CONFIG,
|
|
5143
|
-
...
|
|
5070
|
+
...config.loggerConfig,
|
|
5144
5071
|
// Merge file config if provided
|
|
5145
|
-
file:
|
|
5072
|
+
file: config.loggerConfig.file || DEFAULT_LOGGER_CONFIG.file
|
|
5146
5073
|
};
|
|
5147
5074
|
loggerLattice = initializeLogger(loggerConfig);
|
|
5148
5075
|
logger = loggerLattice.client;
|
|
5149
5076
|
}
|
|
5150
5077
|
app.decorate("loggerLattice", loggerLattice);
|
|
5151
|
-
const target_port =
|
|
5078
|
+
const target_port = config?.port || Number(process.env.PORT) || 4001;
|
|
5152
5079
|
await app.listen({ port: target_port, host: "0.0.0.0" });
|
|
5153
5080
|
logger.info(`Lattice Gateway is running on port: ${target_port}`);
|
|
5154
|
-
const queueServiceConfig =
|
|
5081
|
+
const queueServiceConfig = config?.queueServiceConfig;
|
|
5155
5082
|
if (queueServiceConfig) {
|
|
5156
5083
|
setQueueServiceType(queueServiceConfig.type);
|
|
5157
5084
|
if (queueServiceConfig.defaultStartPollingQueue) {
|