@axiom-lattice/gateway 2.1.43 → 2.1.45
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 -8
- package/CHANGELOG.md +18 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +234 -561
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -399
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -4
- package/src/controllers/assistant.ts +5 -4
- package/src/controllers/memory.ts +17 -13
- package/src/controllers/run.ts +62 -52
- package/src/controllers/thread_status.ts +228 -0
- package/src/index.ts +8 -1
- package/src/routes/index.ts +18 -0
- package/src/services/agent_task_consumer.ts +12 -107
- package/src/__tests__/agent_service.test.ts +0 -238
- package/src/services/agent_service.ts +0 -375
package/dist/index.js
CHANGED
|
@@ -41,269 +41,10 @@ var import_websocket = __toESM(require("@fastify/websocket"));
|
|
|
41
41
|
var import_static = __toESM(require("@fastify/static"));
|
|
42
42
|
var import_path = __toESM(require("path"));
|
|
43
43
|
|
|
44
|
-
// src/services/agent_service.ts
|
|
45
|
-
var import_messages = require("@langchain/core/messages");
|
|
46
|
-
var import_langgraph = require("@langchain/langgraph");
|
|
47
|
-
var import_uuid = require("uuid");
|
|
48
|
-
var import_core = require("@axiom-lattice/core");
|
|
49
|
-
async function checkAgentExists(tenant_id, assistant_id) {
|
|
50
|
-
try {
|
|
51
|
-
const agentLattice = import_core.agentLatticeManager.getAgentLatticeWithTenant(tenant_id, assistant_id);
|
|
52
|
-
return agentLattice !== void 0;
|
|
53
|
-
} catch {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function getOrCreateChunkBuffer() {
|
|
58
|
-
if (!(0, import_core.hasChunkBuffer)("default")) {
|
|
59
|
-
const buffer = new import_core.InMemoryChunkBuffer({
|
|
60
|
-
ttl: 60 * 60 * 1e3,
|
|
61
|
-
// 1 hour TTL
|
|
62
|
-
cleanupInterval: 5 * 60 * 1e3
|
|
63
|
-
// Clean every 5 minutes
|
|
64
|
-
});
|
|
65
|
-
(0, import_core.registerChunkBuffer)("default", buffer);
|
|
66
|
-
}
|
|
67
|
-
return (0, import_core.getChunkBuffer)("default");
|
|
68
|
-
}
|
|
69
|
-
async function agent_invoke({
|
|
70
|
-
input,
|
|
71
|
-
thread_id,
|
|
72
|
-
assistant_id,
|
|
73
|
-
tenant_id,
|
|
74
|
-
workspace_id,
|
|
75
|
-
project_id,
|
|
76
|
-
command,
|
|
77
|
-
run_id,
|
|
78
|
-
custom_run_config
|
|
79
|
-
}) {
|
|
80
|
-
const agentLattice = import_core.agentLatticeManager.getAgentLatticeWithTenant(tenant_id, assistant_id);
|
|
81
|
-
const runnable_agent = agentLattice?.client;
|
|
82
|
-
const { message, ...rest } = input;
|
|
83
|
-
const humanMessage = new import_messages.HumanMessage(message || "");
|
|
84
|
-
const messages = [humanMessage];
|
|
85
|
-
if (!runnable_agent) {
|
|
86
|
-
throw new Error(`Agent ${assistant_id} not found`);
|
|
87
|
-
}
|
|
88
|
-
const runConfig = {
|
|
89
|
-
...agentLattice?.config?.runConfig || {},
|
|
90
|
-
tenantId: tenant_id,
|
|
91
|
-
workspaceId: workspace_id,
|
|
92
|
-
projectId: project_id,
|
|
93
|
-
...custom_run_config || {},
|
|
94
|
-
assistant_id
|
|
95
|
-
};
|
|
96
|
-
const result = await runnable_agent.invoke(
|
|
97
|
-
command ? new import_langgraph.Command(command) : { ...rest, messages, "x-tenant-id": tenant_id },
|
|
98
|
-
{
|
|
99
|
-
context: {
|
|
100
|
-
runConfig
|
|
101
|
-
},
|
|
102
|
-
configurable: {
|
|
103
|
-
thread_id,
|
|
104
|
-
run_id: run_id || (0, import_uuid.v4)(),
|
|
105
|
-
"x-tenant-id": tenant_id,
|
|
106
|
-
"x-workspace-id": workspace_id,
|
|
107
|
-
"x-project-id": project_id,
|
|
108
|
-
"x-request-id": run_id,
|
|
109
|
-
"x-thread-id": thread_id,
|
|
110
|
-
"x-assistant-id": assistant_id,
|
|
111
|
-
runConfig
|
|
112
|
-
},
|
|
113
|
-
recursionLimit: 200
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
const data = result.messages.map((message2) => {
|
|
117
|
-
const { type, data: data2 } = message2.toDict();
|
|
118
|
-
return {
|
|
119
|
-
...data2,
|
|
120
|
-
role: type
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
return { messages: data };
|
|
124
|
-
}
|
|
125
|
-
async function agent_stream({
|
|
126
|
-
input,
|
|
127
|
-
thread_id,
|
|
128
|
-
command,
|
|
129
|
-
tenant_id,
|
|
130
|
-
workspace_id,
|
|
131
|
-
project_id,
|
|
132
|
-
assistant_id,
|
|
133
|
-
run_id,
|
|
134
|
-
custom_run_config
|
|
135
|
-
}) {
|
|
136
|
-
const runnable_agent = await (0, import_core.getAgentClient)(tenant_id, assistant_id);
|
|
137
|
-
const agentLattice = import_core.agentLatticeManager.getAgentLatticeWithTenant(tenant_id, assistant_id);
|
|
138
|
-
const { message, ...rest } = input;
|
|
139
|
-
let messages = [];
|
|
140
|
-
if (!command) {
|
|
141
|
-
const humanMessage = new import_messages.HumanMessage(message);
|
|
142
|
-
messages = [humanMessage];
|
|
143
|
-
}
|
|
144
|
-
const chunkBuffer = getOrCreateChunkBuffer();
|
|
145
|
-
const runConfig = {
|
|
146
|
-
...agentLattice?.config?.runConfig || {},
|
|
147
|
-
tenantId: tenant_id,
|
|
148
|
-
workspaceId: workspace_id,
|
|
149
|
-
projectId: project_id,
|
|
150
|
-
...custom_run_config || {},
|
|
151
|
-
assistant_id
|
|
152
|
-
};
|
|
153
|
-
try {
|
|
154
|
-
if (!runnable_agent) {
|
|
155
|
-
throw new Error(`Agent ${assistant_id} not found`);
|
|
156
|
-
}
|
|
157
|
-
const agentStream = await runnable_agent.stream(
|
|
158
|
-
command ? new import_langgraph.Command(command) : {
|
|
159
|
-
...rest,
|
|
160
|
-
messages,
|
|
161
|
-
"x-tenant-id": tenant_id
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
context: {
|
|
165
|
-
runConfig
|
|
166
|
-
},
|
|
167
|
-
configurable: {
|
|
168
|
-
thread_id,
|
|
169
|
-
run_id: run_id || (0, import_uuid.v4)(),
|
|
170
|
-
"x-tenant-id": tenant_id,
|
|
171
|
-
"x-workspace-id": workspace_id,
|
|
172
|
-
"x-project-id": project_id,
|
|
173
|
-
"x-request-id": run_id,
|
|
174
|
-
"x-thread-id": thread_id,
|
|
175
|
-
"x-assistant-id": assistant_id,
|
|
176
|
-
runConfig
|
|
177
|
-
// Inject runConfig for tools to access
|
|
178
|
-
},
|
|
179
|
-
streamMode: ["updates", "messages"],
|
|
180
|
-
subgraphs: false,
|
|
181
|
-
recursionLimit: 200
|
|
182
|
-
}
|
|
183
|
-
);
|
|
184
|
-
return {
|
|
185
|
-
[Symbol.asyncIterator]: async function* () {
|
|
186
|
-
try {
|
|
187
|
-
for await (const chunk of agentStream) {
|
|
188
|
-
let data;
|
|
189
|
-
let chunkContent = "";
|
|
190
|
-
if (chunk[0] === "updates") {
|
|
191
|
-
const update = chunk[1];
|
|
192
|
-
const values = Object.values(update);
|
|
193
|
-
const messages2 = values[0]?.messages;
|
|
194
|
-
if (messages2?.[0]?.tool_call_id) {
|
|
195
|
-
data = messages2[0].toDict();
|
|
196
|
-
}
|
|
197
|
-
} else if (chunk[0] === "messages") {
|
|
198
|
-
const messages2 = chunk[1];
|
|
199
|
-
data = messages2?.[0]?.toDict();
|
|
200
|
-
}
|
|
201
|
-
if (chunk?.[1]?.__interrupt__) {
|
|
202
|
-
data = {
|
|
203
|
-
type: "interrupt",
|
|
204
|
-
id: chunk?.[1]?.__interrupt__[0].id,
|
|
205
|
-
data: { content: chunk?.[1]?.__interrupt__[0].value }
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
if (data) {
|
|
209
|
-
if (data.type !== "interrupt") {
|
|
210
|
-
await chunkBuffer.addChunk(thread_id, data);
|
|
211
|
-
}
|
|
212
|
-
yield data;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
await chunkBuffer.completeThread(thread_id);
|
|
216
|
-
} catch (error) {
|
|
217
|
-
console.error("Stream error:", error);
|
|
218
|
-
await chunkBuffer.abortThread(thread_id);
|
|
219
|
-
throw error;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
} catch (error) {
|
|
224
|
-
await chunkBuffer.abortThread(thread_id);
|
|
225
|
-
throw error;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
async function agent_state({
|
|
229
|
-
assistant_id,
|
|
230
|
-
thread_id,
|
|
231
|
-
tenant_id
|
|
232
|
-
}) {
|
|
233
|
-
const runnable_agent = await (0, import_core.getAgentClient)(tenant_id, assistant_id);
|
|
234
|
-
if (!runnable_agent) {
|
|
235
|
-
throw new Error(`Agent ${assistant_id} not found`);
|
|
236
|
-
}
|
|
237
|
-
const state = await runnable_agent.getState({
|
|
238
|
-
configurable: { thread_id, subgraphs: false }
|
|
239
|
-
});
|
|
240
|
-
return state;
|
|
241
|
-
}
|
|
242
|
-
async function agent_messages({
|
|
243
|
-
thread_id,
|
|
244
|
-
tenant_id,
|
|
245
|
-
assistant_id
|
|
246
|
-
}) {
|
|
247
|
-
const runnable_agent = await (0, import_core.getAgentClient)(tenant_id, assistant_id);
|
|
248
|
-
if (!runnable_agent) {
|
|
249
|
-
throw new Error(`Agent ${assistant_id} not found`);
|
|
250
|
-
}
|
|
251
|
-
const state = await runnable_agent.getState({
|
|
252
|
-
configurable: { thread_id, subgraphs: false }
|
|
253
|
-
});
|
|
254
|
-
const messages = state.values.messages || [];
|
|
255
|
-
const filteredMessages = (0, import_messages.filterMessages)(messages, {
|
|
256
|
-
includeTypes: ["ai", "human", "tool"]
|
|
257
|
-
//["human", "ai", "tool"],
|
|
258
|
-
});
|
|
259
|
-
let messagesArray = filteredMessages.map((message) => ({
|
|
260
|
-
id: message.id,
|
|
261
|
-
role: message.getType(),
|
|
262
|
-
content: message.content,
|
|
263
|
-
...message.lc_kwargs
|
|
264
|
-
}));
|
|
265
|
-
const new_messages = messagesArray;
|
|
266
|
-
return new_messages;
|
|
267
|
-
}
|
|
268
|
-
async function draw_graph(assistant_id, tenant_id) {
|
|
269
|
-
const runnable_agent = await (0, import_core.getAgentClient)(tenant_id, assistant_id);
|
|
270
|
-
if (!runnable_agent) {
|
|
271
|
-
throw new Error(`Agent ${assistant_id} not found`);
|
|
272
|
-
}
|
|
273
|
-
const drawableGraph = await runnable_agent.getGraphAsync();
|
|
274
|
-
const image = await drawableGraph.drawMermaid();
|
|
275
|
-
return image;
|
|
276
|
-
}
|
|
277
|
-
async function resume_stream({
|
|
278
|
-
thread_id,
|
|
279
|
-
message_id,
|
|
280
|
-
known_content,
|
|
281
|
-
poll_interval = 100
|
|
282
|
-
}) {
|
|
283
|
-
const chunkBuffer = getOrCreateChunkBuffer();
|
|
284
|
-
const stream = await chunkBuffer.getNewChunksSinceContentIterator(
|
|
285
|
-
thread_id,
|
|
286
|
-
message_id,
|
|
287
|
-
known_content
|
|
288
|
-
);
|
|
289
|
-
return {
|
|
290
|
-
[Symbol.asyncIterator]: async function* () {
|
|
291
|
-
try {
|
|
292
|
-
for await (const chunk of stream) {
|
|
293
|
-
yield chunk;
|
|
294
|
-
}
|
|
295
|
-
} catch (error) {
|
|
296
|
-
console.error("Resume stream error:", error);
|
|
297
|
-
throw error;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
44
|
// src/controllers/assistant.ts
|
|
304
|
-
var
|
|
45
|
+
var import_core = require("@axiom-lattice/core");
|
|
305
46
|
var import_crypto = require("crypto");
|
|
306
|
-
var
|
|
47
|
+
var import_core2 = require("@axiom-lattice/core");
|
|
307
48
|
function getTenantId(request) {
|
|
308
49
|
const userTenantId = request.user?.tenantId;
|
|
309
50
|
if (userTenantId) {
|
|
@@ -328,11 +69,11 @@ function convertAgentConfigToAssistant(config) {
|
|
|
328
69
|
}
|
|
329
70
|
async function getAssistantList(request, reply) {
|
|
330
71
|
const tenantId = getTenantId(request);
|
|
331
|
-
const agentConfigs = await
|
|
72
|
+
const agentConfigs = await import_core2.agentLatticeManager.getAllAgentConfigsByTenant(tenantId);
|
|
332
73
|
const codeConfiguredAssistants = agentConfigs.map(
|
|
333
74
|
convertAgentConfigToAssistant
|
|
334
75
|
);
|
|
335
|
-
const storeLattice = (0,
|
|
76
|
+
const storeLattice = (0, import_core.getStoreLattice)("default", "assistant");
|
|
336
77
|
const assistantStore = storeLattice.store;
|
|
337
78
|
const storedAssistants = await assistantStore.getAllAssistants(tenantId);
|
|
338
79
|
const assistantMap = /* @__PURE__ */ new Map();
|
|
@@ -355,11 +96,11 @@ async function getAssistantList(request, reply) {
|
|
|
355
96
|
async function getAssistant(request, reply) {
|
|
356
97
|
const { id } = request.params;
|
|
357
98
|
const tenantId = getTenantId(request);
|
|
358
|
-
const storeLattice = (0,
|
|
99
|
+
const storeLattice = (0, import_core.getStoreLattice)("default", "assistant");
|
|
359
100
|
const assistantStore = storeLattice.store;
|
|
360
101
|
let assistant = await assistantStore.getAssistantById(tenantId, id);
|
|
361
102
|
if (!assistant) {
|
|
362
|
-
const agentConfig = await
|
|
103
|
+
const agentConfig = await import_core2.agentLatticeManager.getAgentConfigWithTenant(tenantId, id);
|
|
363
104
|
if (agentConfig) {
|
|
364
105
|
assistant = convertAgentConfigToAssistant(agentConfig);
|
|
365
106
|
}
|
|
@@ -377,7 +118,7 @@ async function getAssistant(request, reply) {
|
|
|
377
118
|
};
|
|
378
119
|
}
|
|
379
120
|
async function upsertAssistant(tenantId, id, data, reply, requireFields = false) {
|
|
380
|
-
const storeLattice = (0,
|
|
121
|
+
const storeLattice = (0, import_core.getStoreLattice)("default", "assistant");
|
|
381
122
|
const assistantStore = storeLattice.store;
|
|
382
123
|
const exists = await assistantStore.hasAssistant(tenantId, id);
|
|
383
124
|
let assistant;
|
|
@@ -389,7 +130,7 @@ async function upsertAssistant(tenantId, id, data, reply, requireFields = false)
|
|
|
389
130
|
message: "Failed to update assistant"
|
|
390
131
|
});
|
|
391
132
|
}
|
|
392
|
-
|
|
133
|
+
import_core2.eventBus.publish("assistant:updated", { id: assistant.id, name: assistant.name, tenantId });
|
|
393
134
|
return {
|
|
394
135
|
success: true,
|
|
395
136
|
message: "Updated assistant",
|
|
@@ -406,7 +147,7 @@ async function upsertAssistant(tenantId, id, data, reply, requireFields = false)
|
|
|
406
147
|
}
|
|
407
148
|
}
|
|
408
149
|
assistant = await assistantStore.createAssistant(tenantId, id, data);
|
|
409
|
-
|
|
150
|
+
import_core2.eventBus.publish("assistant:created", { id: assistant.id, name: assistant.name, tenantId });
|
|
410
151
|
return reply.status(201).send({
|
|
411
152
|
success: true,
|
|
412
153
|
message: "Created assistant",
|
|
@@ -434,9 +175,9 @@ async function updateAssistant(request, reply) {
|
|
|
434
175
|
async function deleteAssistant(request, reply) {
|
|
435
176
|
const tenantId = getTenantId(request);
|
|
436
177
|
const { id } = request.params;
|
|
437
|
-
const storeLattice = (0,
|
|
178
|
+
const storeLattice = (0, import_core.getStoreLattice)("default", "assistant");
|
|
438
179
|
const assistantStore = storeLattice.store;
|
|
439
|
-
const agentConfig = await
|
|
180
|
+
const agentConfig = await import_core2.agentLatticeManager.getAgentConfigWithTenant(tenantId, id);
|
|
440
181
|
const isCodeConfigured = !!agentConfig;
|
|
441
182
|
if (isCodeConfigured) {
|
|
442
183
|
const exists2 = await assistantStore.hasAssistant(tenantId, id);
|
|
@@ -447,7 +188,7 @@ async function deleteAssistant(request, reply) {
|
|
|
447
188
|
});
|
|
448
189
|
}
|
|
449
190
|
await assistantStore.deleteAssistant(tenantId, id);
|
|
450
|
-
|
|
191
|
+
import_core2.eventBus.publish("assistant:deleted", { id, tenantId });
|
|
451
192
|
return {
|
|
452
193
|
success: true,
|
|
453
194
|
message: "Deleted assistant from store (code-configured registration remains)"
|
|
@@ -467,7 +208,7 @@ async function deleteAssistant(request, reply) {
|
|
|
467
208
|
message: "Failed to delete assistant"
|
|
468
209
|
});
|
|
469
210
|
}
|
|
470
|
-
|
|
211
|
+
import_core2.eventBus.publish("assistant:deleted", { id, tenantId });
|
|
471
212
|
return {
|
|
472
213
|
success: true,
|
|
473
214
|
message: "Successfully deleted assistant"
|
|
@@ -477,7 +218,8 @@ var getAgentGraph = async (request, reply) => {
|
|
|
477
218
|
try {
|
|
478
219
|
const { assistantId } = request.params;
|
|
479
220
|
const tenant_id = getTenantId(request);
|
|
480
|
-
const
|
|
221
|
+
const agent = import_core.agentInstanceManager.getAgent({ assistant_id: assistantId, tenant_id, thread_id: "" });
|
|
222
|
+
const imageData = await agent.get_draw_graph();
|
|
481
223
|
reply.header("Content-Type", "application/json").send({
|
|
482
224
|
image: imageData
|
|
483
225
|
});
|
|
@@ -490,7 +232,8 @@ var getAgentGraph = async (request, reply) => {
|
|
|
490
232
|
};
|
|
491
233
|
|
|
492
234
|
// src/controllers/run.ts
|
|
493
|
-
var
|
|
235
|
+
var import_uuid = require("uuid");
|
|
236
|
+
var import_core3 = require("@axiom-lattice/core");
|
|
494
237
|
var createRun = async (request, reply) => {
|
|
495
238
|
try {
|
|
496
239
|
const {
|
|
@@ -505,7 +248,7 @@ var createRun = async (request, reply) => {
|
|
|
505
248
|
const tenant_id = request.headers["x-tenant-id"];
|
|
506
249
|
const workspace_id = request.headers["x-workspace-id"];
|
|
507
250
|
const project_id = request.headers["x-project-id"];
|
|
508
|
-
const x_request_id = request.headers["x-request-id"] || (0,
|
|
251
|
+
const x_request_id = request.headers["x-request-id"] || (0, import_uuid.v4)();
|
|
509
252
|
if (!assistant_id) {
|
|
510
253
|
reply.status(400).send({
|
|
511
254
|
success: false,
|
|
@@ -513,26 +256,15 @@ var createRun = async (request, reply) => {
|
|
|
513
256
|
});
|
|
514
257
|
return;
|
|
515
258
|
}
|
|
259
|
+
const agent = import_core3.agentInstanceManager.getAgent({
|
|
260
|
+
assistant_id,
|
|
261
|
+
thread_id,
|
|
262
|
+
tenant_id,
|
|
263
|
+
workspace_id,
|
|
264
|
+
project_id,
|
|
265
|
+
custom_run_config
|
|
266
|
+
});
|
|
516
267
|
if (streaming) {
|
|
517
|
-
const agentExists = await checkAgentExists(tenant_id, assistant_id);
|
|
518
|
-
if (!agentExists) {
|
|
519
|
-
reply.status(404).send({
|
|
520
|
-
success: false,
|
|
521
|
-
error: `Agent ${assistant_id} not found for tenant ${tenant_id}`
|
|
522
|
-
});
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
const stream = await agent_stream({
|
|
526
|
-
assistant_id,
|
|
527
|
-
input,
|
|
528
|
-
thread_id,
|
|
529
|
-
command,
|
|
530
|
-
tenant_id,
|
|
531
|
-
workspace_id,
|
|
532
|
-
project_id,
|
|
533
|
-
run_id: x_request_id,
|
|
534
|
-
custom_run_config
|
|
535
|
-
});
|
|
536
268
|
reply.hijack();
|
|
537
269
|
reply.raw.writeHead(200, {
|
|
538
270
|
"Content-Type": "text/event-stream",
|
|
@@ -541,9 +273,13 @@ var createRun = async (request, reply) => {
|
|
|
541
273
|
"Access-Control-Allow-Origin": "*"
|
|
542
274
|
});
|
|
543
275
|
try {
|
|
544
|
-
|
|
276
|
+
const result = await agent.addMessage({
|
|
277
|
+
input,
|
|
278
|
+
command
|
|
279
|
+
});
|
|
280
|
+
const stream = agent.chunkStream(result.messageId);
|
|
545
281
|
for await (const chunk of stream) {
|
|
546
|
-
|
|
282
|
+
console.log(input.message, chunk.data.content);
|
|
547
283
|
const success = reply.raw.write(`data: ${JSON.stringify(chunk)}
|
|
548
284
|
|
|
549
285
|
`);
|
|
@@ -555,7 +291,7 @@ var createRun = async (request, reply) => {
|
|
|
555
291
|
const errorEvent = {
|
|
556
292
|
type: "error",
|
|
557
293
|
data: {
|
|
558
|
-
id: (0,
|
|
294
|
+
id: (0, import_uuid.v4)(),
|
|
559
295
|
content: error.message || "Stream processing error"
|
|
560
296
|
}
|
|
561
297
|
};
|
|
@@ -566,18 +302,15 @@ var createRun = async (request, reply) => {
|
|
|
566
302
|
reply.raw.end();
|
|
567
303
|
}
|
|
568
304
|
} else {
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
input,
|
|
572
|
-
command
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
run_id: x_request_id,
|
|
578
|
-
custom_run_config
|
|
305
|
+
const { message: msg, ...restInputNonStream } = input;
|
|
306
|
+
const result = await agent.invoke({
|
|
307
|
+
input: { message: msg, ...restInputNonStream },
|
|
308
|
+
command
|
|
309
|
+
});
|
|
310
|
+
reply.status(200).send({
|
|
311
|
+
success: true,
|
|
312
|
+
...result
|
|
579
313
|
});
|
|
580
|
-
reply.status(200).send(result);
|
|
581
314
|
}
|
|
582
315
|
} catch (error) {
|
|
583
316
|
reply.status(500).send({
|
|
@@ -604,12 +337,12 @@ var resumeStream = async (request, reply) => {
|
|
|
604
337
|
"Access-Control-Allow-Origin": "*"
|
|
605
338
|
});
|
|
606
339
|
try {
|
|
607
|
-
const
|
|
340
|
+
const agent = new import_core3.Agent({
|
|
341
|
+
assistant_id: "",
|
|
608
342
|
thread_id,
|
|
609
|
-
|
|
610
|
-
known_content,
|
|
611
|
-
poll_interval: poll_interval || 100
|
|
343
|
+
tenant_id: ""
|
|
612
344
|
});
|
|
345
|
+
const stream = agent.chunkStream(message_id, known_content);
|
|
613
346
|
for await (const chunk of stream) {
|
|
614
347
|
reply.raw.write(`data: ${JSON.stringify(chunk)}
|
|
615
348
|
|
|
@@ -619,7 +352,7 @@ var resumeStream = async (request, reply) => {
|
|
|
619
352
|
const errorEvent = {
|
|
620
353
|
type: "error",
|
|
621
354
|
data: {
|
|
622
|
-
id: (0,
|
|
355
|
+
id: (0, import_uuid.v4)(),
|
|
623
356
|
content: error.message || "Resume stream processing error"
|
|
624
357
|
}
|
|
625
358
|
};
|
|
@@ -638,6 +371,7 @@ var resumeStream = async (request, reply) => {
|
|
|
638
371
|
};
|
|
639
372
|
|
|
640
373
|
// src/controllers/memory.ts
|
|
374
|
+
var import_core4 = require("@axiom-lattice/core");
|
|
641
375
|
var setMemoryItem = async (request, reply) => {
|
|
642
376
|
try {
|
|
643
377
|
const { assistantId, key } = request.params;
|
|
@@ -702,11 +436,8 @@ var getAllMemoryItems = async (request, reply) => {
|
|
|
702
436
|
});
|
|
703
437
|
return;
|
|
704
438
|
}
|
|
705
|
-
const
|
|
706
|
-
|
|
707
|
-
thread_id,
|
|
708
|
-
tenant_id
|
|
709
|
-
});
|
|
439
|
+
const agent = import_core4.agentInstanceManager.getAgent({ assistant_id: assistantId, tenant_id, thread_id });
|
|
440
|
+
const result = await agent.getCurrentMessages();
|
|
710
441
|
if (!result) {
|
|
711
442
|
reply.status(500).send(result);
|
|
712
443
|
return;
|
|
@@ -737,16 +468,18 @@ var getAgentState = async (request, reply) => {
|
|
|
737
468
|
return;
|
|
738
469
|
}
|
|
739
470
|
const tenant_id = request.headers["x-tenant-id"];
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
tenant_id
|
|
744
|
-
});
|
|
471
|
+
const agent = import_core4.agentInstanceManager.getAgent({ assistant_id: assistantId, tenant_id, thread_id });
|
|
472
|
+
const result = await agent.getCurrentState();
|
|
473
|
+
const pendingMessages = await agent.getPendingMessages();
|
|
745
474
|
if (!result) {
|
|
746
475
|
reply.status(500).send(result);
|
|
747
476
|
return;
|
|
748
477
|
}
|
|
749
|
-
|
|
478
|
+
const mergedResult = {
|
|
479
|
+
...result,
|
|
480
|
+
pendingMessages
|
|
481
|
+
};
|
|
482
|
+
reply.send(mergedResult);
|
|
750
483
|
} catch (error) {
|
|
751
484
|
reply.status(500).send({
|
|
752
485
|
success: false,
|
|
@@ -799,7 +532,7 @@ var clearMemory = async (request, reply) => {
|
|
|
799
532
|
};
|
|
800
533
|
|
|
801
534
|
// src/controllers/agent_task.ts
|
|
802
|
-
var
|
|
535
|
+
var import_core5 = require("@axiom-lattice/core");
|
|
803
536
|
var triggerAgentTask = async (request, reply) => {
|
|
804
537
|
try {
|
|
805
538
|
const { assistant_id, thread_id, input, command } = request.body;
|
|
@@ -818,7 +551,7 @@ var triggerAgentTask = async (request, reply) => {
|
|
|
818
551
|
});
|
|
819
552
|
return;
|
|
820
553
|
}
|
|
821
|
-
const agentManager =
|
|
554
|
+
const agentManager = import_core5.AgentManager.getInstance();
|
|
822
555
|
const result = await agentManager.callAgentInQueue({
|
|
823
556
|
assistant_id,
|
|
824
557
|
thread_id,
|
|
@@ -838,7 +571,7 @@ var triggerAgentTask = async (request, reply) => {
|
|
|
838
571
|
};
|
|
839
572
|
|
|
840
573
|
// src/controllers/threads.ts
|
|
841
|
-
var
|
|
574
|
+
var import_core6 = require("@axiom-lattice/core");
|
|
842
575
|
var import_crypto2 = require("crypto");
|
|
843
576
|
function getTenantId2(request) {
|
|
844
577
|
const userTenantId = request.user?.tenantId;
|
|
@@ -850,7 +583,7 @@ function getTenantId2(request) {
|
|
|
850
583
|
async function getThreadList(request, reply) {
|
|
851
584
|
const tenantId = getTenantId2(request);
|
|
852
585
|
const { assistantId } = request.params;
|
|
853
|
-
const storeLattice = (0,
|
|
586
|
+
const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
|
|
854
587
|
const threadStore = storeLattice.store;
|
|
855
588
|
const threads = await threadStore.getThreadsByAssistantId(tenantId, assistantId);
|
|
856
589
|
return {
|
|
@@ -865,7 +598,7 @@ async function getThreadList(request, reply) {
|
|
|
865
598
|
async function getThread(request, reply) {
|
|
866
599
|
const tenantId = getTenantId2(request);
|
|
867
600
|
const { threadId } = request.params;
|
|
868
|
-
const storeLattice = (0,
|
|
601
|
+
const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
|
|
869
602
|
const threadStore = storeLattice.store;
|
|
870
603
|
const thread = await threadStore.getThreadById(tenantId, threadId);
|
|
871
604
|
if (!thread) {
|
|
@@ -885,7 +618,7 @@ async function createThread(request, reply) {
|
|
|
885
618
|
const { assistantId } = request.params;
|
|
886
619
|
const data = request.body;
|
|
887
620
|
const threadId = (0, import_crypto2.randomUUID)();
|
|
888
|
-
const storeLattice = (0,
|
|
621
|
+
const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
|
|
889
622
|
const threadStore = storeLattice.store;
|
|
890
623
|
const newThread = await threadStore.createThread(tenantId, assistantId, threadId, data);
|
|
891
624
|
return reply.status(201).send({
|
|
@@ -898,7 +631,7 @@ async function updateThread(request, reply) {
|
|
|
898
631
|
const tenantId = getTenantId2(request);
|
|
899
632
|
const { threadId } = request.params;
|
|
900
633
|
const updates = request.body;
|
|
901
|
-
const storeLattice = (0,
|
|
634
|
+
const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
|
|
902
635
|
const threadStore = storeLattice.store;
|
|
903
636
|
const exists = await threadStore.hasThread(tenantId, threadId);
|
|
904
637
|
if (!exists) {
|
|
@@ -927,7 +660,7 @@ async function updateThread(request, reply) {
|
|
|
927
660
|
async function deleteThread(request, reply) {
|
|
928
661
|
const tenantId = getTenantId2(request);
|
|
929
662
|
const { threadId } = request.params;
|
|
930
|
-
const storeLattice = (0,
|
|
663
|
+
const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
|
|
931
664
|
const threadStore = storeLattice.store;
|
|
932
665
|
const exists = await threadStore.hasThread(tenantId, threadId);
|
|
933
666
|
if (!exists) {
|
|
@@ -950,7 +683,7 @@ async function deleteThread(request, reply) {
|
|
|
950
683
|
}
|
|
951
684
|
|
|
952
685
|
// src/controllers/schedules.ts
|
|
953
|
-
var
|
|
686
|
+
var import_core7 = require("@axiom-lattice/core");
|
|
954
687
|
function getTenantId3(request) {
|
|
955
688
|
const userTenantId = request.user?.tenantId;
|
|
956
689
|
if (userTenantId) {
|
|
@@ -959,14 +692,14 @@ function getTenantId3(request) {
|
|
|
959
692
|
return request.headers["x-tenant-id"] || "default";
|
|
960
693
|
}
|
|
961
694
|
function getScheduleLattice() {
|
|
962
|
-
const keys =
|
|
695
|
+
const keys = import_core7.scheduleLatticeManager.getLatticeKeys();
|
|
963
696
|
if (keys.length === 0) {
|
|
964
697
|
return null;
|
|
965
698
|
}
|
|
966
|
-
if (
|
|
967
|
-
return
|
|
699
|
+
if (import_core7.scheduleLatticeManager.hasLattice("default")) {
|
|
700
|
+
return import_core7.scheduleLatticeManager.getScheduleLattice("default");
|
|
968
701
|
}
|
|
969
|
-
return
|
|
702
|
+
return import_core7.scheduleLatticeManager.getScheduleLattice(keys[0]);
|
|
970
703
|
}
|
|
971
704
|
async function getThreadSchedules(request, reply) {
|
|
972
705
|
const { assistantId, threadId } = request.params;
|
|
@@ -1227,7 +960,7 @@ var ConfigService = class {
|
|
|
1227
960
|
var configService = new ConfigService();
|
|
1228
961
|
|
|
1229
962
|
// src/services/queue_service.ts
|
|
1230
|
-
var
|
|
963
|
+
var import_core8 = require("@axiom-lattice/core");
|
|
1231
964
|
var import_protocols = require("@axiom-lattice/protocols");
|
|
1232
965
|
var import_queue_redis = require("@axiom-lattice/queue-redis");
|
|
1233
966
|
var DEFAULT_QUEUE_KEY = "default";
|
|
@@ -1246,8 +979,8 @@ var setQueueServiceType = (type) => {
|
|
|
1246
979
|
redisPassword: process.env.REDIS_PASSWORD
|
|
1247
980
|
} : void 0
|
|
1248
981
|
};
|
|
1249
|
-
if (
|
|
1250
|
-
|
|
982
|
+
if (import_core8.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
983
|
+
import_core8.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
|
|
1251
984
|
}
|
|
1252
985
|
let client;
|
|
1253
986
|
if (type === "redis") {
|
|
@@ -1256,13 +989,13 @@ var setQueueServiceType = (type) => {
|
|
|
1256
989
|
redisPassword: process.env.REDIS_PASSWORD
|
|
1257
990
|
});
|
|
1258
991
|
}
|
|
1259
|
-
(0,
|
|
992
|
+
(0, import_core8.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
|
|
1260
993
|
};
|
|
1261
994
|
var getQueueService = () => {
|
|
1262
|
-
if (!
|
|
995
|
+
if (!import_core8.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
|
|
1263
996
|
setQueueServiceType(queueServiceType);
|
|
1264
997
|
}
|
|
1265
|
-
return (0,
|
|
998
|
+
return (0, import_core8.getQueueLattice)(DEFAULT_QUEUE_KEY);
|
|
1266
999
|
};
|
|
1267
1000
|
var popAgentTaskFromQueue = async () => {
|
|
1268
1001
|
const queue = getQueueService();
|
|
@@ -1343,10 +1076,10 @@ async function getConfig(request, reply) {
|
|
|
1343
1076
|
}
|
|
1344
1077
|
|
|
1345
1078
|
// src/controllers/models.ts
|
|
1346
|
-
var
|
|
1079
|
+
var import_core9 = require("@axiom-lattice/core");
|
|
1347
1080
|
async function getModels(request, reply) {
|
|
1348
1081
|
try {
|
|
1349
|
-
const allLattices =
|
|
1082
|
+
const allLattices = import_core9.modelLatticeManager.getAllLattices();
|
|
1350
1083
|
const models = allLattices.map((lattice) => {
|
|
1351
1084
|
const config = lattice.client.config || {};
|
|
1352
1085
|
return {
|
|
@@ -1396,8 +1129,8 @@ async function updateModels(request, reply) {
|
|
|
1396
1129
|
continue;
|
|
1397
1130
|
}
|
|
1398
1131
|
try {
|
|
1399
|
-
if (
|
|
1400
|
-
|
|
1132
|
+
if (import_core9.modelLatticeManager.hasLattice(modelConfig.key)) {
|
|
1133
|
+
import_core9.modelLatticeManager.removeLattice(modelConfig.key);
|
|
1401
1134
|
}
|
|
1402
1135
|
const llmConfig = {
|
|
1403
1136
|
provider: modelConfig.provider,
|
|
@@ -1410,7 +1143,7 @@ async function updateModels(request, reply) {
|
|
|
1410
1143
|
timeout: modelConfig.timeout,
|
|
1411
1144
|
maxRetries: modelConfig.maxRetries
|
|
1412
1145
|
};
|
|
1413
|
-
(0,
|
|
1146
|
+
(0, import_core9.registerModelLattice)(modelConfig.key, llmConfig);
|
|
1414
1147
|
registeredModels.push(modelConfig.key);
|
|
1415
1148
|
} catch (error) {
|
|
1416
1149
|
errors.push(
|
|
@@ -1468,8 +1201,8 @@ async function getHealth(request, reply) {
|
|
|
1468
1201
|
}
|
|
1469
1202
|
|
|
1470
1203
|
// src/controllers/skills.ts
|
|
1471
|
-
var import_core9 = require("@axiom-lattice/core");
|
|
1472
1204
|
var import_core10 = require("@axiom-lattice/core");
|
|
1205
|
+
var import_core11 = require("@axiom-lattice/core");
|
|
1473
1206
|
function getTenantId4(request) {
|
|
1474
1207
|
const userTenantId = request.user?.tenantId;
|
|
1475
1208
|
if (userTenantId) {
|
|
@@ -1500,7 +1233,7 @@ function serializeSkill(skill) {
|
|
|
1500
1233
|
async function getSkillList(request, reply) {
|
|
1501
1234
|
try {
|
|
1502
1235
|
const tenantId = getTenantId4(request);
|
|
1503
|
-
const storeLattice = (0,
|
|
1236
|
+
const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
|
|
1504
1237
|
const skillStore = storeLattice.store;
|
|
1505
1238
|
const skills = await skillStore.getAllSkills(tenantId);
|
|
1506
1239
|
const serializedSkills = skills.map(serializeSkill);
|
|
@@ -1527,7 +1260,7 @@ async function getSkill(request, reply) {
|
|
|
1527
1260
|
try {
|
|
1528
1261
|
const tenantId = getTenantId4(request);
|
|
1529
1262
|
const { id } = request.params;
|
|
1530
|
-
const storeLattice = (0,
|
|
1263
|
+
const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
|
|
1531
1264
|
const skillStore = storeLattice.store;
|
|
1532
1265
|
const skill = await skillStore.getSkillById(tenantId, id);
|
|
1533
1266
|
if (!skill) {
|
|
@@ -1564,7 +1297,7 @@ async function createSkill(request, reply) {
|
|
|
1564
1297
|
});
|
|
1565
1298
|
}
|
|
1566
1299
|
try {
|
|
1567
|
-
(0,
|
|
1300
|
+
(0, import_core11.validateSkillName)(data.name);
|
|
1568
1301
|
} catch (error) {
|
|
1569
1302
|
return reply.status(400).send({
|
|
1570
1303
|
success: false,
|
|
@@ -1579,7 +1312,7 @@ async function createSkill(request, reply) {
|
|
|
1579
1312
|
});
|
|
1580
1313
|
}
|
|
1581
1314
|
const tenantId = getTenantId4(request);
|
|
1582
|
-
const storeLattice = (0,
|
|
1315
|
+
const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
|
|
1583
1316
|
const skillStore = storeLattice.store;
|
|
1584
1317
|
const exists = await skillStore.hasSkill(tenantId, id);
|
|
1585
1318
|
if (exists) {
|
|
@@ -1607,7 +1340,7 @@ async function updateSkill(request, reply) {
|
|
|
1607
1340
|
const updates = request.body;
|
|
1608
1341
|
if (updates.name !== void 0) {
|
|
1609
1342
|
try {
|
|
1610
|
-
(0,
|
|
1343
|
+
(0, import_core11.validateSkillName)(updates.name);
|
|
1611
1344
|
} catch (error) {
|
|
1612
1345
|
return reply.status(400).send({
|
|
1613
1346
|
success: false,
|
|
@@ -1616,7 +1349,7 @@ async function updateSkill(request, reply) {
|
|
|
1616
1349
|
}
|
|
1617
1350
|
}
|
|
1618
1351
|
const tenantId = getTenantId4(request);
|
|
1619
|
-
const storeLattice = (0,
|
|
1352
|
+
const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
|
|
1620
1353
|
const skillStore = storeLattice.store;
|
|
1621
1354
|
const exists = await skillStore.hasSkill(tenantId, id);
|
|
1622
1355
|
if (!exists) {
|
|
@@ -1648,7 +1381,7 @@ async function deleteSkill(request, reply) {
|
|
|
1648
1381
|
try {
|
|
1649
1382
|
const { id } = request.params;
|
|
1650
1383
|
const tenantId = getTenantId4(request);
|
|
1651
|
-
const storeLattice = (0,
|
|
1384
|
+
const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
|
|
1652
1385
|
const skillStore = storeLattice.store;
|
|
1653
1386
|
const exists = await skillStore.hasSkill(tenantId, id);
|
|
1654
1387
|
if (!exists) {
|
|
@@ -1689,7 +1422,7 @@ async function searchSkillsByMetadata(request, reply) {
|
|
|
1689
1422
|
});
|
|
1690
1423
|
}
|
|
1691
1424
|
const tenantId = getTenantId4(request);
|
|
1692
|
-
const storeLattice = (0,
|
|
1425
|
+
const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
|
|
1693
1426
|
const skillStore = storeLattice.store;
|
|
1694
1427
|
const skills = await skillStore.searchByMetadata(tenantId, key, value);
|
|
1695
1428
|
const serializedSkills = skills.map(serializeSkill);
|
|
@@ -1726,7 +1459,7 @@ async function filterSkillsByCompatibility(request, reply) {
|
|
|
1726
1459
|
});
|
|
1727
1460
|
}
|
|
1728
1461
|
const tenantId = getTenantId4(request);
|
|
1729
|
-
const storeLattice = (0,
|
|
1462
|
+
const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
|
|
1730
1463
|
const skillStore = storeLattice.store;
|
|
1731
1464
|
const skills = await skillStore.filterByCompatibility(tenantId, compatibility);
|
|
1732
1465
|
const serializedSkills = skills.map(serializeSkill);
|
|
@@ -1763,7 +1496,7 @@ async function filterSkillsByLicense(request, reply) {
|
|
|
1763
1496
|
});
|
|
1764
1497
|
}
|
|
1765
1498
|
const tenantId = getTenantId4(request);
|
|
1766
|
-
const storeLattice = (0,
|
|
1499
|
+
const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
|
|
1767
1500
|
const skillStore = storeLattice.store;
|
|
1768
1501
|
const skills = await skillStore.filterByLicense(tenantId, license);
|
|
1769
1502
|
const serializedSkills = skills.map(serializeSkill);
|
|
@@ -1788,7 +1521,7 @@ async function filterSkillsByLicense(request, reply) {
|
|
|
1788
1521
|
}
|
|
1789
1522
|
|
|
1790
1523
|
// src/controllers/tools.ts
|
|
1791
|
-
var
|
|
1524
|
+
var import_core12 = require("@axiom-lattice/core");
|
|
1792
1525
|
function serializeSchema(schema) {
|
|
1793
1526
|
if (!schema) {
|
|
1794
1527
|
return void 0;
|
|
@@ -1832,7 +1565,7 @@ function serializeSchema(schema) {
|
|
|
1832
1565
|
}
|
|
1833
1566
|
async function getToolConfigs(request, reply) {
|
|
1834
1567
|
try {
|
|
1835
|
-
const allLattices =
|
|
1568
|
+
const allLattices = import_core12.toolLatticeManager.getAllLattices();
|
|
1836
1569
|
const toolConfigs = allLattices.map((lattice) => {
|
|
1837
1570
|
const config = { ...lattice.config };
|
|
1838
1571
|
const serializedSchema = config.schema ? serializeSchema(config.schema) : void 0;
|
|
@@ -1870,7 +1603,7 @@ async function getToolConfigs(request, reply) {
|
|
|
1870
1603
|
}
|
|
1871
1604
|
|
|
1872
1605
|
// src/controllers/data-query.ts
|
|
1873
|
-
var
|
|
1606
|
+
var import_core13 = require("@axiom-lattice/core");
|
|
1874
1607
|
function getTenantId5(request) {
|
|
1875
1608
|
return request.headers["x-tenant-id"] || "default";
|
|
1876
1609
|
}
|
|
@@ -1901,7 +1634,7 @@ async function executeDataQuery(request, reply) {
|
|
|
1901
1634
|
message: "Cannot provide both metrics and customSql. Use one query type only."
|
|
1902
1635
|
};
|
|
1903
1636
|
}
|
|
1904
|
-
const storeLattice = (0,
|
|
1637
|
+
const storeLattice = (0, import_core13.getStoreLattice)("default", "metrics");
|
|
1905
1638
|
const store = storeLattice.store;
|
|
1906
1639
|
if (!body.serverKey) {
|
|
1907
1640
|
reply.code(400);
|
|
@@ -1932,14 +1665,14 @@ async function executeDataQuery(request, reply) {
|
|
|
1932
1665
|
message: "datasourceId is required"
|
|
1933
1666
|
};
|
|
1934
1667
|
}
|
|
1935
|
-
if (!
|
|
1668
|
+
if (!import_core13.metricsServerManager.hasServer(tenantId, body.serverKey)) {
|
|
1936
1669
|
reply.code(400);
|
|
1937
1670
|
return {
|
|
1938
1671
|
success: false,
|
|
1939
1672
|
message: `Metrics server not registered: ${body.serverKey}. Please register the server first.`
|
|
1940
1673
|
};
|
|
1941
1674
|
}
|
|
1942
|
-
const client =
|
|
1675
|
+
const client = import_core13.metricsServerManager.getClient(tenantId, body.serverKey);
|
|
1943
1676
|
if (isSemanticQuery) {
|
|
1944
1677
|
return await executeSemanticQuery(client, body, reply);
|
|
1945
1678
|
} else {
|
|
@@ -2350,7 +2083,7 @@ var getHealthSchema = {
|
|
|
2350
2083
|
var import_stream = require("stream");
|
|
2351
2084
|
|
|
2352
2085
|
// src/services/sandbox_service.ts
|
|
2353
|
-
var
|
|
2086
|
+
var import_core14 = require("@axiom-lattice/core");
|
|
2354
2087
|
var ERROR_HTML = `<!DOCTYPE html>
|
|
2355
2088
|
<html lang="zh-CN">
|
|
2356
2089
|
<head>
|
|
@@ -2462,7 +2195,7 @@ var ERROR_HTML = `<!DOCTYPE html>
|
|
|
2462
2195
|
</html>`;
|
|
2463
2196
|
var SandboxService = class {
|
|
2464
2197
|
getFilesystemIsolatedLevel(tenantId, assistantId) {
|
|
2465
|
-
const agentLattice =
|
|
2198
|
+
const agentLattice = import_core14.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
|
|
2466
2199
|
if (!agentLattice) {
|
|
2467
2200
|
return null;
|
|
2468
2201
|
}
|
|
@@ -2487,10 +2220,10 @@ var SandboxService = class {
|
|
|
2487
2220
|
sandboxName = "global";
|
|
2488
2221
|
break;
|
|
2489
2222
|
}
|
|
2490
|
-
return (0,
|
|
2223
|
+
return (0, import_core14.normalizeSandboxName)(sandboxName);
|
|
2491
2224
|
}
|
|
2492
2225
|
getTargetUrl(sandboxName) {
|
|
2493
|
-
const sandboxManager = (0,
|
|
2226
|
+
const sandboxManager = (0, import_core14.getSandBoxManager)();
|
|
2494
2227
|
return `${sandboxManager.getBaseURL()}/sandbox/${sandboxName}`;
|
|
2495
2228
|
}
|
|
2496
2229
|
async getVncHtml(sandboxName) {
|
|
@@ -2535,7 +2268,7 @@ var SandboxService = class {
|
|
|
2535
2268
|
var sandboxService = new SandboxService();
|
|
2536
2269
|
|
|
2537
2270
|
// src/controllers/sandbox.ts
|
|
2538
|
-
var
|
|
2271
|
+
var import_core15 = require("@axiom-lattice/core");
|
|
2539
2272
|
function getFilenameFromPath(path3) {
|
|
2540
2273
|
const segments = path3.replace(/\/+$/, "").split("/");
|
|
2541
2274
|
return segments[segments.length - 1] || "download";
|
|
@@ -2577,7 +2310,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2577
2310
|
threadId,
|
|
2578
2311
|
isolatedLevel
|
|
2579
2312
|
);
|
|
2580
|
-
const sandboxManager = (0,
|
|
2313
|
+
const sandboxManager = (0, import_core15.getSandBoxManager)();
|
|
2581
2314
|
const sandbox = await sandboxManager.createSandbox(sandboxName);
|
|
2582
2315
|
try {
|
|
2583
2316
|
const data = await request.file();
|
|
@@ -2624,7 +2357,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2624
2357
|
threadId,
|
|
2625
2358
|
isolatedLevel
|
|
2626
2359
|
);
|
|
2627
|
-
const sandboxManager = (0,
|
|
2360
|
+
const sandboxManager = (0, import_core15.getSandBoxManager)();
|
|
2628
2361
|
const sandbox = await sandboxManager.createSandbox(sandboxName);
|
|
2629
2362
|
try {
|
|
2630
2363
|
const resolvedPath = filePath.startsWith("/home/gem") ? filePath : `/home/gem/${filePath.replace(/^\//, "")}`;
|
|
@@ -2680,14 +2413,14 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2680
2413
|
var fs = __toESM(require("fs/promises"));
|
|
2681
2414
|
var path = __toESM(require("path"));
|
|
2682
2415
|
var import_stream2 = require("stream");
|
|
2683
|
-
var import_core15 = require("@axiom-lattice/core");
|
|
2684
2416
|
var import_core16 = require("@axiom-lattice/core");
|
|
2685
2417
|
var import_core17 = require("@axiom-lattice/core");
|
|
2686
|
-
var
|
|
2418
|
+
var import_core18 = require("@axiom-lattice/core");
|
|
2419
|
+
var import_uuid2 = require("uuid");
|
|
2687
2420
|
var WorkspaceController = class {
|
|
2688
2421
|
constructor() {
|
|
2689
|
-
this.workspaceStore = (0,
|
|
2690
|
-
this.projectStore = (0,
|
|
2422
|
+
this.workspaceStore = (0, import_core16.getStoreLattice)("default", "workspace").store;
|
|
2423
|
+
this.projectStore = (0, import_core16.getStoreLattice)("default", "project").store;
|
|
2691
2424
|
}
|
|
2692
2425
|
getTenantId(request) {
|
|
2693
2426
|
const userTenantId = request.user?.tenantId;
|
|
@@ -2709,7 +2442,7 @@ var WorkspaceController = class {
|
|
|
2709
2442
|
async createWorkspace(request, reply) {
|
|
2710
2443
|
const tenantId = this.getTenantId(request);
|
|
2711
2444
|
const data = request.body;
|
|
2712
|
-
const id = (0,
|
|
2445
|
+
const id = (0, import_uuid2.v4)();
|
|
2713
2446
|
const workspace = await this.workspaceStore.createWorkspace(
|
|
2714
2447
|
tenantId,
|
|
2715
2448
|
id,
|
|
@@ -2769,7 +2502,7 @@ var WorkspaceController = class {
|
|
|
2769
2502
|
const tenantId = this.getTenantId(request);
|
|
2770
2503
|
const { workspaceId } = request.params;
|
|
2771
2504
|
const data = request.body;
|
|
2772
|
-
const id = (0,
|
|
2505
|
+
const id = (0, import_uuid2.v4)();
|
|
2773
2506
|
const project = await this.projectStore.createProject(
|
|
2774
2507
|
tenantId,
|
|
2775
2508
|
workspaceId,
|
|
@@ -2820,11 +2553,11 @@ var WorkspaceController = class {
|
|
|
2820
2553
|
throw new Error("Workspace not found");
|
|
2821
2554
|
}
|
|
2822
2555
|
if (workspace.storageType === "sandbox") {
|
|
2823
|
-
const sandboxManager = (0,
|
|
2556
|
+
const sandboxManager = (0, import_core18.getSandBoxManager)();
|
|
2824
2557
|
const sandboxName = "global";
|
|
2825
2558
|
const sandbox = await sandboxManager.createSandbox(sandboxName);
|
|
2826
2559
|
return {
|
|
2827
|
-
backend: new
|
|
2560
|
+
backend: new import_core17.SandboxFilesystem({
|
|
2828
2561
|
sandboxInstance: sandbox,
|
|
2829
2562
|
workingDirectory: `/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`
|
|
2830
2563
|
}),
|
|
@@ -2832,7 +2565,7 @@ var WorkspaceController = class {
|
|
|
2832
2565
|
};
|
|
2833
2566
|
} else {
|
|
2834
2567
|
return {
|
|
2835
|
-
backend: new
|
|
2568
|
+
backend: new import_core17.FilesystemBackend({
|
|
2836
2569
|
rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
|
|
2837
2570
|
virtualMode: true
|
|
2838
2571
|
}),
|
|
@@ -2877,7 +2610,7 @@ var WorkspaceController = class {
|
|
|
2877
2610
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
|
|
2878
2611
|
const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
|
|
2879
2612
|
if (workspace.storageType === "sandbox") {
|
|
2880
|
-
const sandboxManager = (0,
|
|
2613
|
+
const sandboxManager = (0, import_core18.getSandBoxManager)();
|
|
2881
2614
|
const sandbox = await sandboxManager.createSandbox("global");
|
|
2882
2615
|
const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
|
|
2883
2616
|
const filename2 = this.getFilenameFromPath(resolvedPath);
|
|
@@ -2946,7 +2679,7 @@ var WorkspaceController = class {
|
|
|
2946
2679
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
|
|
2947
2680
|
const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
|
|
2948
2681
|
if (workspace.storageType === "sandbox") {
|
|
2949
|
-
const sandboxManager = (0,
|
|
2682
|
+
const sandboxManager = (0, import_core18.getSandBoxManager)();
|
|
2950
2683
|
const sandbox = await sandboxManager.createSandbox("global");
|
|
2951
2684
|
const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
|
|
2952
2685
|
const filename2 = this.getFilenameFromPath(resolvedPath);
|
|
@@ -3116,7 +2849,7 @@ var WorkspaceController = class {
|
|
|
3116
2849
|
return reply.status(400).send({ success: false, error: "Invalid path parameter" });
|
|
3117
2850
|
}
|
|
3118
2851
|
if (workspace.storageType === "sandbox") {
|
|
3119
|
-
const sandboxManager = (0,
|
|
2852
|
+
const sandboxManager = (0, import_core18.getSandBoxManager)();
|
|
3120
2853
|
const sandboxName = "global";
|
|
3121
2854
|
const sandbox = await sandboxManager.createSandbox(sandboxName);
|
|
3122
2855
|
const baseDir = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId);
|
|
@@ -3222,7 +2955,7 @@ function registerWorkspaceRoutes(app2) {
|
|
|
3222
2955
|
}
|
|
3223
2956
|
|
|
3224
2957
|
// src/controllers/database-configs.ts
|
|
3225
|
-
var
|
|
2958
|
+
var import_core19 = require("@axiom-lattice/core");
|
|
3226
2959
|
var import_crypto3 = require("crypto");
|
|
3227
2960
|
function getTenantId6(request) {
|
|
3228
2961
|
const userTenantId = request.user?.tenantId;
|
|
@@ -3234,7 +2967,7 @@ function getTenantId6(request) {
|
|
|
3234
2967
|
async function getDatabaseConfigList(request, reply) {
|
|
3235
2968
|
const tenantId = getTenantId6(request);
|
|
3236
2969
|
try {
|
|
3237
|
-
const storeLattice = (0,
|
|
2970
|
+
const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
|
|
3238
2971
|
const store = storeLattice.store;
|
|
3239
2972
|
const configs = await store.getAllConfigs(tenantId);
|
|
3240
2973
|
console.log("Backend: getAllConfigs returned:", configs);
|
|
@@ -3265,7 +2998,7 @@ async function getDatabaseConfig(request, reply) {
|
|
|
3265
2998
|
const tenantId = getTenantId6(request);
|
|
3266
2999
|
const { key } = request.params;
|
|
3267
3000
|
try {
|
|
3268
|
-
const storeLattice = (0,
|
|
3001
|
+
const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
|
|
3269
3002
|
const store = storeLattice.store;
|
|
3270
3003
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3271
3004
|
if (!config) {
|
|
@@ -3291,7 +3024,7 @@ async function createDatabaseConfig(request, reply) {
|
|
|
3291
3024
|
const tenantId = getTenantId6(request);
|
|
3292
3025
|
const body = request.body;
|
|
3293
3026
|
try {
|
|
3294
|
-
const storeLattice = (0,
|
|
3027
|
+
const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
|
|
3295
3028
|
const store = storeLattice.store;
|
|
3296
3029
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3297
3030
|
if (existing) {
|
|
@@ -3304,7 +3037,7 @@ async function createDatabaseConfig(request, reply) {
|
|
|
3304
3037
|
const id = body.id || (0, import_crypto3.randomUUID)();
|
|
3305
3038
|
const config = await store.createConfig(tenantId, id, body);
|
|
3306
3039
|
try {
|
|
3307
|
-
|
|
3040
|
+
import_core19.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
|
|
3308
3041
|
} catch (error) {
|
|
3309
3042
|
console.warn("Failed to auto-register database:", error);
|
|
3310
3043
|
}
|
|
@@ -3327,7 +3060,7 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
3327
3060
|
const { key } = request.params;
|
|
3328
3061
|
const updates = request.body;
|
|
3329
3062
|
try {
|
|
3330
|
-
const storeLattice = (0,
|
|
3063
|
+
const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
|
|
3331
3064
|
const store = storeLattice.store;
|
|
3332
3065
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3333
3066
|
if (!existing) {
|
|
@@ -3346,7 +3079,7 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
3346
3079
|
}
|
|
3347
3080
|
if (updates.config) {
|
|
3348
3081
|
try {
|
|
3349
|
-
|
|
3082
|
+
import_core19.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
|
|
3350
3083
|
} catch (error) {
|
|
3351
3084
|
console.warn("Failed to re-register database:", error);
|
|
3352
3085
|
}
|
|
@@ -3368,7 +3101,7 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
3368
3101
|
const tenantId = getTenantId6(request);
|
|
3369
3102
|
const { keyOrId } = request.params;
|
|
3370
3103
|
try {
|
|
3371
|
-
const storeLattice = (0,
|
|
3104
|
+
const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
|
|
3372
3105
|
const store = storeLattice.store;
|
|
3373
3106
|
console.log("Delete request - keyOrId:", keyOrId);
|
|
3374
3107
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
@@ -3395,8 +3128,8 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
3395
3128
|
};
|
|
3396
3129
|
}
|
|
3397
3130
|
try {
|
|
3398
|
-
if (
|
|
3399
|
-
await
|
|
3131
|
+
if (import_core19.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
|
|
3132
|
+
await import_core19.sqlDatabaseManager.removeDatabase(tenantId, configKey);
|
|
3400
3133
|
}
|
|
3401
3134
|
} catch (error) {
|
|
3402
3135
|
console.warn("Failed to remove from SqlDatabaseManager:", error);
|
|
@@ -3417,7 +3150,7 @@ async function testDatabaseConnection(request, reply) {
|
|
|
3417
3150
|
const tenantId = getTenantId6(request);
|
|
3418
3151
|
const { key } = request.params;
|
|
3419
3152
|
try {
|
|
3420
|
-
const storeLattice = (0,
|
|
3153
|
+
const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
|
|
3421
3154
|
const store = storeLattice.store;
|
|
3422
3155
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3423
3156
|
if (!config) {
|
|
@@ -3428,16 +3161,16 @@ async function testDatabaseConnection(request, reply) {
|
|
|
3428
3161
|
};
|
|
3429
3162
|
}
|
|
3430
3163
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
3431
|
-
|
|
3164
|
+
import_core19.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
|
|
3432
3165
|
const startTime = Date.now();
|
|
3433
|
-
const db = await
|
|
3166
|
+
const db = await import_core19.sqlDatabaseManager.getDatabase(tenantId, testKey);
|
|
3434
3167
|
try {
|
|
3435
3168
|
await db.connect();
|
|
3436
3169
|
await db.listTables();
|
|
3437
3170
|
const latency = Date.now() - startTime;
|
|
3438
3171
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3439
3172
|
await db.disconnect();
|
|
3440
|
-
await
|
|
3173
|
+
await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
3441
3174
|
return {
|
|
3442
3175
|
success: true,
|
|
3443
3176
|
message: "Connection test successful",
|
|
@@ -3449,7 +3182,7 @@ async function testDatabaseConnection(request, reply) {
|
|
|
3449
3182
|
} catch (error) {
|
|
3450
3183
|
try {
|
|
3451
3184
|
await db.disconnect();
|
|
3452
|
-
await
|
|
3185
|
+
await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
3453
3186
|
} catch {
|
|
3454
3187
|
}
|
|
3455
3188
|
return {
|
|
@@ -3501,7 +3234,7 @@ function registerDatabaseConfigRoutes(app2) {
|
|
|
3501
3234
|
}
|
|
3502
3235
|
|
|
3503
3236
|
// src/controllers/metrics-configs.ts
|
|
3504
|
-
var
|
|
3237
|
+
var import_core20 = require("@axiom-lattice/core");
|
|
3505
3238
|
var import_crypto4 = require("crypto");
|
|
3506
3239
|
function getTenantId7(request) {
|
|
3507
3240
|
const userTenantId = request.user?.tenantId;
|
|
@@ -3513,7 +3246,7 @@ function getTenantId7(request) {
|
|
|
3513
3246
|
async function getMetricsServerConfigList(request, reply) {
|
|
3514
3247
|
const tenantId = getTenantId7(request);
|
|
3515
3248
|
try {
|
|
3516
|
-
const storeLattice = (0,
|
|
3249
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3517
3250
|
const store = storeLattice.store;
|
|
3518
3251
|
const configs = await store.getAllConfigs(tenantId);
|
|
3519
3252
|
return {
|
|
@@ -3540,7 +3273,7 @@ async function getMetricsServerConfig(request, reply) {
|
|
|
3540
3273
|
const tenantId = getTenantId7(request);
|
|
3541
3274
|
const { key } = request.params;
|
|
3542
3275
|
try {
|
|
3543
|
-
const storeLattice = (0,
|
|
3276
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3544
3277
|
const store = storeLattice.store;
|
|
3545
3278
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3546
3279
|
if (!config) {
|
|
@@ -3566,7 +3299,7 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
3566
3299
|
const tenantId = getTenantId7(request);
|
|
3567
3300
|
const body = request.body;
|
|
3568
3301
|
try {
|
|
3569
|
-
const storeLattice = (0,
|
|
3302
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3570
3303
|
const store = storeLattice.store;
|
|
3571
3304
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3572
3305
|
if (existing) {
|
|
@@ -3595,7 +3328,7 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
3595
3328
|
};
|
|
3596
3329
|
const config = await store.createConfig(tenantId, id, configData);
|
|
3597
3330
|
try {
|
|
3598
|
-
|
|
3331
|
+
import_core20.metricsServerManager.registerServer(tenantId, config.key, config.config);
|
|
3599
3332
|
} catch (error) {
|
|
3600
3333
|
console.warn("Failed to auto-register metrics server:", error);
|
|
3601
3334
|
}
|
|
@@ -3618,7 +3351,7 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
3618
3351
|
const { key } = request.params;
|
|
3619
3352
|
const updates = request.body;
|
|
3620
3353
|
try {
|
|
3621
|
-
const storeLattice = (0,
|
|
3354
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3622
3355
|
const store = storeLattice.store;
|
|
3623
3356
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3624
3357
|
if (!existing) {
|
|
@@ -3646,7 +3379,7 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
3646
3379
|
}
|
|
3647
3380
|
if (updates.config) {
|
|
3648
3381
|
try {
|
|
3649
|
-
|
|
3382
|
+
import_core20.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
|
|
3650
3383
|
} catch (error) {
|
|
3651
3384
|
console.warn("Failed to re-register metrics server:", error);
|
|
3652
3385
|
}
|
|
@@ -3668,7 +3401,7 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
3668
3401
|
const tenantId = getTenantId7(request);
|
|
3669
3402
|
const { keyOrId } = request.params;
|
|
3670
3403
|
try {
|
|
3671
|
-
const storeLattice = (0,
|
|
3404
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3672
3405
|
const store = storeLattice.store;
|
|
3673
3406
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
3674
3407
|
let configKey = keyOrId;
|
|
@@ -3693,8 +3426,8 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
3693
3426
|
};
|
|
3694
3427
|
}
|
|
3695
3428
|
try {
|
|
3696
|
-
if (
|
|
3697
|
-
|
|
3429
|
+
if (import_core20.metricsServerManager.hasServer(tenantId, configKey)) {
|
|
3430
|
+
import_core20.metricsServerManager.removeServer(tenantId, configKey);
|
|
3698
3431
|
}
|
|
3699
3432
|
} catch (error) {
|
|
3700
3433
|
console.warn("Failed to remove from MetricsServerManager:", error);
|
|
@@ -3715,7 +3448,7 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3715
3448
|
const tenantId = getTenantId7(request);
|
|
3716
3449
|
const { key } = request.params;
|
|
3717
3450
|
try {
|
|
3718
|
-
const storeLattice = (0,
|
|
3451
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3719
3452
|
const store = storeLattice.store;
|
|
3720
3453
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3721
3454
|
if (!config) {
|
|
@@ -3726,11 +3459,11 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3726
3459
|
};
|
|
3727
3460
|
}
|
|
3728
3461
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
3729
|
-
|
|
3462
|
+
import_core20.metricsServerManager.registerServer(tenantId, testKey, config.config);
|
|
3730
3463
|
try {
|
|
3731
|
-
const client =
|
|
3464
|
+
const client = import_core20.metricsServerManager.getClient(tenantId, testKey);
|
|
3732
3465
|
const result = await client.testConnection();
|
|
3733
|
-
|
|
3466
|
+
import_core20.metricsServerManager.removeServer(tenantId, testKey);
|
|
3734
3467
|
return {
|
|
3735
3468
|
success: true,
|
|
3736
3469
|
message: result.connected ? "Connection test successful" : "Connection test failed",
|
|
@@ -3738,7 +3471,7 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3738
3471
|
};
|
|
3739
3472
|
} catch (error) {
|
|
3740
3473
|
try {
|
|
3741
|
-
|
|
3474
|
+
import_core20.metricsServerManager.removeServer(tenantId, testKey);
|
|
3742
3475
|
} catch {
|
|
3743
3476
|
}
|
|
3744
3477
|
return {
|
|
@@ -3766,7 +3499,7 @@ async function listAvailableMetrics(request, reply) {
|
|
|
3766
3499
|
const tenantId = getTenantId7(request);
|
|
3767
3500
|
const { key } = request.params;
|
|
3768
3501
|
try {
|
|
3769
|
-
const storeLattice = (0,
|
|
3502
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3770
3503
|
const store = storeLattice.store;
|
|
3771
3504
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3772
3505
|
if (!config) {
|
|
@@ -3776,10 +3509,10 @@ async function listAvailableMetrics(request, reply) {
|
|
|
3776
3509
|
message: "Metrics server configuration not found"
|
|
3777
3510
|
};
|
|
3778
3511
|
}
|
|
3779
|
-
if (!
|
|
3780
|
-
|
|
3512
|
+
if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
|
|
3513
|
+
import_core20.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
3781
3514
|
}
|
|
3782
|
-
const client =
|
|
3515
|
+
const client = import_core20.metricsServerManager.getClient(tenantId, key);
|
|
3783
3516
|
const metrics = await client.listMetrics();
|
|
3784
3517
|
return {
|
|
3785
3518
|
success: true,
|
|
@@ -3805,7 +3538,7 @@ async function queryMetricsData(request, reply) {
|
|
|
3805
3538
|
const { key } = request.params;
|
|
3806
3539
|
const { metricName, startTime, endTime, step, labels } = request.body;
|
|
3807
3540
|
try {
|
|
3808
|
-
const storeLattice = (0,
|
|
3541
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3809
3542
|
const store = storeLattice.store;
|
|
3810
3543
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3811
3544
|
if (!config) {
|
|
@@ -3822,10 +3555,10 @@ async function queryMetricsData(request, reply) {
|
|
|
3822
3555
|
message: "metricName is required"
|
|
3823
3556
|
};
|
|
3824
3557
|
}
|
|
3825
|
-
if (!
|
|
3826
|
-
|
|
3558
|
+
if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
|
|
3559
|
+
import_core20.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
3827
3560
|
}
|
|
3828
|
-
const client =
|
|
3561
|
+
const client = import_core20.metricsServerManager.getClient(tenantId, key);
|
|
3829
3562
|
const result = await client.queryMetricData(metricName, {
|
|
3830
3563
|
startTime,
|
|
3831
3564
|
endTime,
|
|
@@ -3852,7 +3585,7 @@ async function getDataSources(request, reply) {
|
|
|
3852
3585
|
const tenantId = getTenantId7(request);
|
|
3853
3586
|
const { key } = request.params;
|
|
3854
3587
|
try {
|
|
3855
|
-
const storeLattice = (0,
|
|
3588
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3856
3589
|
const store = storeLattice.store;
|
|
3857
3590
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3858
3591
|
if (!config) {
|
|
@@ -3870,7 +3603,7 @@ async function getDataSources(request, reply) {
|
|
|
3870
3603
|
};
|
|
3871
3604
|
}
|
|
3872
3605
|
const semanticConfig = config.config;
|
|
3873
|
-
const client = new
|
|
3606
|
+
const client = new import_core20.SemanticMetricsClient(semanticConfig);
|
|
3874
3607
|
const allDatasources = await client.getDataSources();
|
|
3875
3608
|
const selectedIds = semanticConfig.selectedDataSources || [];
|
|
3876
3609
|
const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
|
|
@@ -3893,7 +3626,7 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
3893
3626
|
const tenantId = getTenantId7(request);
|
|
3894
3627
|
const { key, datasourceId } = request.params;
|
|
3895
3628
|
try {
|
|
3896
|
-
const storeLattice = (0,
|
|
3629
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3897
3630
|
const store = storeLattice.store;
|
|
3898
3631
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3899
3632
|
if (!config) {
|
|
@@ -3911,7 +3644,7 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
3911
3644
|
};
|
|
3912
3645
|
}
|
|
3913
3646
|
const semanticConfig = config.config;
|
|
3914
|
-
const client = new
|
|
3647
|
+
const client = new import_core20.SemanticMetricsClient(semanticConfig);
|
|
3915
3648
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
3916
3649
|
return {
|
|
3917
3650
|
success: true,
|
|
@@ -3931,7 +3664,7 @@ async function querySemanticMetrics(request, reply) {
|
|
|
3931
3664
|
const { key } = request.params;
|
|
3932
3665
|
const body = request.body;
|
|
3933
3666
|
try {
|
|
3934
|
-
const storeLattice = (0,
|
|
3667
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
|
|
3935
3668
|
const store = storeLattice.store;
|
|
3936
3669
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3937
3670
|
if (!config) {
|
|
@@ -3956,7 +3689,7 @@ async function querySemanticMetrics(request, reply) {
|
|
|
3956
3689
|
};
|
|
3957
3690
|
}
|
|
3958
3691
|
const semanticConfig = config.config;
|
|
3959
|
-
const client = new
|
|
3692
|
+
const client = new import_core20.SemanticMetricsClient(semanticConfig);
|
|
3960
3693
|
const result = await client.semanticQuery(body);
|
|
3961
3694
|
const columnNames = result.columns.map((col) => col.name);
|
|
3962
3695
|
const allDataPoints = [];
|
|
@@ -4016,7 +3749,7 @@ async function testSemanticDataSources(request, reply) {
|
|
|
4016
3749
|
password: body.password,
|
|
4017
3750
|
headers: body.headers
|
|
4018
3751
|
};
|
|
4019
|
-
const client = new
|
|
3752
|
+
const client = new import_core20.SemanticMetricsClient(testConfig);
|
|
4020
3753
|
const datasources = await client.getDataSources();
|
|
4021
3754
|
return {
|
|
4022
3755
|
success: true,
|
|
@@ -4052,7 +3785,7 @@ async function testDatasourceMetrics(request, reply) {
|
|
|
4052
3785
|
password: body.password,
|
|
4053
3786
|
headers: body.headers
|
|
4054
3787
|
};
|
|
4055
|
-
const client = new
|
|
3788
|
+
const client = new import_core20.SemanticMetricsClient(testConfig);
|
|
4056
3789
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
4057
3790
|
return {
|
|
4058
3791
|
success: true,
|
|
@@ -4084,7 +3817,7 @@ function registerMetricsServerConfigRoutes(app2) {
|
|
|
4084
3817
|
}
|
|
4085
3818
|
|
|
4086
3819
|
// src/controllers/mcp-configs.ts
|
|
4087
|
-
var
|
|
3820
|
+
var import_core21 = require("@axiom-lattice/core");
|
|
4088
3821
|
var import_crypto5 = require("crypto");
|
|
4089
3822
|
function getTenantId8(request) {
|
|
4090
3823
|
const userTenantId = request.user?.tenantId;
|
|
@@ -4096,7 +3829,7 @@ function getTenantId8(request) {
|
|
|
4096
3829
|
async function getMcpServerConfigList(request, reply) {
|
|
4097
3830
|
const tenantId = getTenantId8(request);
|
|
4098
3831
|
try {
|
|
4099
|
-
const storeLattice = (0,
|
|
3832
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4100
3833
|
const store = storeLattice.store;
|
|
4101
3834
|
const configs = await store.getAllConfigs(tenantId);
|
|
4102
3835
|
return {
|
|
@@ -4123,7 +3856,7 @@ async function getMcpServerConfig(request, reply) {
|
|
|
4123
3856
|
const tenantId = getTenantId8(request);
|
|
4124
3857
|
const { key } = request.params;
|
|
4125
3858
|
try {
|
|
4126
|
-
const storeLattice = (0,
|
|
3859
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4127
3860
|
const store = storeLattice.store;
|
|
4128
3861
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4129
3862
|
if (!config) {
|
|
@@ -4149,7 +3882,7 @@ async function createMcpServerConfig(request, reply) {
|
|
|
4149
3882
|
const tenantId = getTenantId8(request);
|
|
4150
3883
|
const body = request.body;
|
|
4151
3884
|
try {
|
|
4152
|
-
const storeLattice = (0,
|
|
3885
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4153
3886
|
const store = storeLattice.store;
|
|
4154
3887
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
4155
3888
|
if (existing) {
|
|
@@ -4189,7 +3922,7 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
4189
3922
|
const { key } = request.params;
|
|
4190
3923
|
const updates = request.body;
|
|
4191
3924
|
try {
|
|
4192
|
-
const storeLattice = (0,
|
|
3925
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4193
3926
|
const store = storeLattice.store;
|
|
4194
3927
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
4195
3928
|
if (!existing) {
|
|
@@ -4209,8 +3942,8 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
4209
3942
|
}
|
|
4210
3943
|
if (shouldReconnect) {
|
|
4211
3944
|
try {
|
|
4212
|
-
if (
|
|
4213
|
-
await
|
|
3945
|
+
if (import_core21.mcpManager.hasServer(key)) {
|
|
3946
|
+
await import_core21.mcpManager.removeServer(key);
|
|
4214
3947
|
}
|
|
4215
3948
|
await connectAndRegisterTools(updated);
|
|
4216
3949
|
await store.updateConfig(tenantId, existing.id, { status: "connected" });
|
|
@@ -4238,7 +3971,7 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
4238
3971
|
const tenantId = getTenantId8(request);
|
|
4239
3972
|
const { keyOrId } = request.params;
|
|
4240
3973
|
try {
|
|
4241
|
-
const storeLattice = (0,
|
|
3974
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4242
3975
|
const store = storeLattice.store;
|
|
4243
3976
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
4244
3977
|
let configKey = keyOrId;
|
|
@@ -4256,8 +3989,8 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
4256
3989
|
};
|
|
4257
3990
|
}
|
|
4258
3991
|
try {
|
|
4259
|
-
if (
|
|
4260
|
-
await
|
|
3992
|
+
if (import_core21.mcpManager.hasServer(configKey)) {
|
|
3993
|
+
await import_core21.mcpManager.removeServer(configKey);
|
|
4261
3994
|
}
|
|
4262
3995
|
} catch (error) {
|
|
4263
3996
|
console.warn("Failed to remove from MCP manager:", error);
|
|
@@ -4285,7 +4018,7 @@ async function testMcpServerConnection(request, reply) {
|
|
|
4285
4018
|
const tenantId = getTenantId8(request);
|
|
4286
4019
|
const { key } = request.params;
|
|
4287
4020
|
try {
|
|
4288
|
-
const storeLattice = (0,
|
|
4021
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4289
4022
|
const store = storeLattice.store;
|
|
4290
4023
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4291
4024
|
if (!config) {
|
|
@@ -4299,11 +4032,11 @@ async function testMcpServerConnection(request, reply) {
|
|
|
4299
4032
|
try {
|
|
4300
4033
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
4301
4034
|
const connection = convertToConnection(config.config);
|
|
4302
|
-
|
|
4303
|
-
await
|
|
4304
|
-
const tools = await
|
|
4035
|
+
import_core21.mcpManager.addServer(testKey, connection);
|
|
4036
|
+
await import_core21.mcpManager.connect();
|
|
4037
|
+
const tools = await import_core21.mcpManager.getAllTools();
|
|
4305
4038
|
const latency = Date.now() - startTime;
|
|
4306
|
-
await
|
|
4039
|
+
await import_core21.mcpManager.removeServer(testKey);
|
|
4307
4040
|
return {
|
|
4308
4041
|
success: true,
|
|
4309
4042
|
message: "Connection test successful",
|
|
@@ -4338,7 +4071,7 @@ async function listMcpServerTools(request, reply) {
|
|
|
4338
4071
|
const tenantId = getTenantId8(request);
|
|
4339
4072
|
const { key } = request.params;
|
|
4340
4073
|
try {
|
|
4341
|
-
const storeLattice = (0,
|
|
4074
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4342
4075
|
const store = storeLattice.store;
|
|
4343
4076
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4344
4077
|
if (!config) {
|
|
@@ -4348,10 +4081,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
4348
4081
|
message: "MCP server configuration not found"
|
|
4349
4082
|
};
|
|
4350
4083
|
}
|
|
4351
|
-
if (!
|
|
4084
|
+
if (!import_core21.mcpManager.hasServer(key)) {
|
|
4352
4085
|
await connectAndRegisterTools(config);
|
|
4353
4086
|
}
|
|
4354
|
-
const tools = await
|
|
4087
|
+
const tools = await import_core21.mcpManager.getAllTools();
|
|
4355
4088
|
return {
|
|
4356
4089
|
success: true,
|
|
4357
4090
|
message: "Tools retrieved successfully",
|
|
@@ -4371,7 +4104,7 @@ async function connectMcpServer(request, reply) {
|
|
|
4371
4104
|
const tenantId = getTenantId8(request);
|
|
4372
4105
|
const { key } = request.params;
|
|
4373
4106
|
try {
|
|
4374
|
-
const storeLattice = (0,
|
|
4107
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4375
4108
|
const store = storeLattice.store;
|
|
4376
4109
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4377
4110
|
if (!config) {
|
|
@@ -4392,7 +4125,7 @@ async function connectMcpServer(request, reply) {
|
|
|
4392
4125
|
};
|
|
4393
4126
|
} catch (error) {
|
|
4394
4127
|
console.error("Failed to connect MCP server:", error);
|
|
4395
|
-
const storeLattice = (0,
|
|
4128
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4396
4129
|
const store = storeLattice.store;
|
|
4397
4130
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4398
4131
|
if (config) {
|
|
@@ -4408,7 +4141,7 @@ async function disconnectMcpServer(request, reply) {
|
|
|
4408
4141
|
const tenantId = getTenantId8(request);
|
|
4409
4142
|
const { key } = request.params;
|
|
4410
4143
|
try {
|
|
4411
|
-
const storeLattice = (0,
|
|
4144
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
|
|
4412
4145
|
const store = storeLattice.store;
|
|
4413
4146
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4414
4147
|
if (!config) {
|
|
@@ -4418,8 +4151,8 @@ async function disconnectMcpServer(request, reply) {
|
|
|
4418
4151
|
message: "MCP server configuration not found"
|
|
4419
4152
|
};
|
|
4420
4153
|
}
|
|
4421
|
-
if (
|
|
4422
|
-
await
|
|
4154
|
+
if (import_core21.mcpManager.hasServer(key)) {
|
|
4155
|
+
await import_core21.mcpManager.removeServer(key);
|
|
4423
4156
|
}
|
|
4424
4157
|
const updated = await store.updateConfig(tenantId, config.id, {
|
|
4425
4158
|
status: "disconnected"
|
|
@@ -4449,10 +4182,10 @@ async function testMcpServerTools(request, reply) {
|
|
|
4449
4182
|
}
|
|
4450
4183
|
const testKey = `__test_${Date.now()}`;
|
|
4451
4184
|
const connection = convertToConnection(body.config);
|
|
4452
|
-
|
|
4453
|
-
await
|
|
4454
|
-
const tools = await
|
|
4455
|
-
await
|
|
4185
|
+
import_core21.mcpManager.addServer(testKey, connection);
|
|
4186
|
+
await import_core21.mcpManager.connect();
|
|
4187
|
+
const tools = await import_core21.mcpManager.getAllTools();
|
|
4188
|
+
await import_core21.mcpManager.removeServer(testKey);
|
|
4456
4189
|
return {
|
|
4457
4190
|
success: true,
|
|
4458
4191
|
message: "Tools retrieved successfully",
|
|
@@ -4489,14 +4222,14 @@ function convertToConnection(config) {
|
|
|
4489
4222
|
}
|
|
4490
4223
|
async function connectAndRegisterTools(config) {
|
|
4491
4224
|
const connection = convertToConnection(config.config);
|
|
4492
|
-
|
|
4493
|
-
await
|
|
4494
|
-
const allTools = await
|
|
4225
|
+
import_core21.mcpManager.addServer(config.key, connection);
|
|
4226
|
+
await import_core21.mcpManager.connect();
|
|
4227
|
+
const allTools = await import_core21.mcpManager.getAllTools();
|
|
4495
4228
|
const selectedTools = allTools.filter(
|
|
4496
4229
|
(tool) => config.selectedTools.includes(tool.name)
|
|
4497
4230
|
);
|
|
4498
4231
|
for (const tool of selectedTools) {
|
|
4499
|
-
|
|
4232
|
+
import_core21.toolLatticeManager.registerExistingTool(tool.name, tool);
|
|
4500
4233
|
}
|
|
4501
4234
|
}
|
|
4502
4235
|
function registerMcpServerConfigRoutes(app2) {
|
|
@@ -4513,11 +4246,11 @@ function registerMcpServerConfigRoutes(app2) {
|
|
|
4513
4246
|
}
|
|
4514
4247
|
|
|
4515
4248
|
// src/controllers/users.ts
|
|
4516
|
-
var
|
|
4517
|
-
var
|
|
4249
|
+
var import_core22 = require("@axiom-lattice/core");
|
|
4250
|
+
var import_uuid3 = require("uuid");
|
|
4518
4251
|
var UsersController = class {
|
|
4519
4252
|
constructor() {
|
|
4520
|
-
this.userStore = (0,
|
|
4253
|
+
this.userStore = (0, import_core22.getStoreLattice)("default", "user").store;
|
|
4521
4254
|
}
|
|
4522
4255
|
async listUsers(request, reply) {
|
|
4523
4256
|
const { email } = request.query;
|
|
@@ -4530,7 +4263,7 @@ var UsersController = class {
|
|
|
4530
4263
|
}
|
|
4531
4264
|
async createUser(request, reply) {
|
|
4532
4265
|
const data = request.body;
|
|
4533
|
-
const id = (0,
|
|
4266
|
+
const id = (0, import_uuid3.v4)();
|
|
4534
4267
|
const existingUser = await this.userStore.getUserByEmail(data.email);
|
|
4535
4268
|
if (existingUser) {
|
|
4536
4269
|
return reply.status(409).send({
|
|
@@ -4595,11 +4328,11 @@ function registerUserRoutes(app2) {
|
|
|
4595
4328
|
}
|
|
4596
4329
|
|
|
4597
4330
|
// src/controllers/tenants.ts
|
|
4598
|
-
var
|
|
4599
|
-
var
|
|
4331
|
+
var import_core23 = require("@axiom-lattice/core");
|
|
4332
|
+
var import_uuid4 = require("uuid");
|
|
4600
4333
|
var TenantsController = class {
|
|
4601
4334
|
constructor() {
|
|
4602
|
-
this.tenantStore = (0,
|
|
4335
|
+
this.tenantStore = (0, import_core23.getStoreLattice)("default", "tenant").store;
|
|
4603
4336
|
}
|
|
4604
4337
|
// ==================== Tenant CRUD ====================
|
|
4605
4338
|
async listTenants(request, reply) {
|
|
@@ -4608,7 +4341,7 @@ var TenantsController = class {
|
|
|
4608
4341
|
}
|
|
4609
4342
|
async createTenant(request, reply) {
|
|
4610
4343
|
const data = request.body;
|
|
4611
|
-
const id = (0,
|
|
4344
|
+
const id = (0, import_uuid4.v4)();
|
|
4612
4345
|
const tenant = await this.tenantStore.createTenant(id, data);
|
|
4613
4346
|
return reply.status(201).send({ success: true, data: tenant });
|
|
4614
4347
|
}
|
|
@@ -4663,8 +4396,8 @@ function registerTenantRoutes(app2) {
|
|
|
4663
4396
|
}
|
|
4664
4397
|
|
|
4665
4398
|
// src/controllers/auth.ts
|
|
4666
|
-
var
|
|
4667
|
-
var
|
|
4399
|
+
var import_core24 = require("@axiom-lattice/core");
|
|
4400
|
+
var import_uuid5 = require("uuid");
|
|
4668
4401
|
var defaultAuthConfig = {
|
|
4669
4402
|
autoApproveUsers: true,
|
|
4670
4403
|
allowTenantRegistration: true,
|
|
@@ -4672,9 +4405,9 @@ var defaultAuthConfig = {
|
|
|
4672
4405
|
};
|
|
4673
4406
|
var AuthController = class {
|
|
4674
4407
|
constructor(config = {}) {
|
|
4675
|
-
this.userStore = (0,
|
|
4676
|
-
this.tenantStore = (0,
|
|
4677
|
-
this.userTenantLinkStore = (0,
|
|
4408
|
+
this.userStore = (0, import_core24.getStoreLattice)("default", "user").store;
|
|
4409
|
+
this.tenantStore = (0, import_core24.getStoreLattice)("default", "tenant").store;
|
|
4410
|
+
this.userTenantLinkStore = (0, import_core24.getStoreLattice)("default", "userTenantLink").store;
|
|
4678
4411
|
this.config = { ...defaultAuthConfig, ...config };
|
|
4679
4412
|
}
|
|
4680
4413
|
async register(request, reply) {
|
|
@@ -4687,7 +4420,7 @@ var AuthController = class {
|
|
|
4687
4420
|
error: "User with this email already exists"
|
|
4688
4421
|
});
|
|
4689
4422
|
}
|
|
4690
|
-
const userId = (0,
|
|
4423
|
+
const userId = (0, import_uuid5.v4)();
|
|
4691
4424
|
const userStatus = this.config.autoApproveUsers ? "active" : "pending";
|
|
4692
4425
|
const userData = {
|
|
4693
4426
|
email,
|
|
@@ -5188,7 +4921,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
|
|
|
5188
4921
|
};
|
|
5189
4922
|
|
|
5190
4923
|
// src/services/agent_task_consumer.ts
|
|
5191
|
-
var
|
|
4924
|
+
var import_core25 = require("@axiom-lattice/core");
|
|
5192
4925
|
var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
5193
4926
|
const {
|
|
5194
4927
|
assistant_id,
|
|
@@ -5205,82 +4938,18 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
5205
4938
|
);
|
|
5206
4939
|
const apiUrl = AgentTaskConsumer.agent_run_endpoint;
|
|
5207
4940
|
console.log(`apiUrl: ${apiUrl}`);
|
|
5208
|
-
const
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
...input,
|
|
5214
|
-
thread_id,
|
|
5215
|
-
command,
|
|
5216
|
-
custom_run_config: runConfig
|
|
5217
|
-
}),
|
|
5218
|
-
headers: {
|
|
5219
|
-
"Content-Type": "application/json",
|
|
5220
|
-
"x-tenant-id": tenant_id,
|
|
5221
|
-
"x-workspace-id": runConfig?.workspaceId,
|
|
5222
|
-
"x-project-id": runConfig?.projectId
|
|
5223
|
-
}
|
|
5224
|
-
}).catch((err) => {
|
|
5225
|
-
console.error(`fetch\u8BF7\u6C42\u5931\u8D25: ${err.message || String(err)}`);
|
|
5226
|
-
throw new Error(`fetch\u5931\u8D25: ${err.message || String(err)}`);
|
|
5227
|
-
});
|
|
5228
|
-
if (!response.ok) {
|
|
5229
|
-
throw new Error(`API\u8BF7\u6C42\u5931\u8D25: ${response.status} ${response.statusText}`);
|
|
5230
|
-
}
|
|
5231
|
-
const contentType = response.headers.get("content-type");
|
|
5232
|
-
if (contentType?.includes("text/event-stream")) {
|
|
5233
|
-
const reader = response.body?.getReader();
|
|
5234
|
-
const decoder = new TextDecoder();
|
|
5235
|
-
if (!reader) {
|
|
5236
|
-
throw new Error("Response body is not readable");
|
|
5237
|
-
}
|
|
5238
|
-
let buffer = "";
|
|
5239
|
-
let streamEnded = false;
|
|
5240
|
-
try {
|
|
5241
|
-
while (true) {
|
|
5242
|
-
const { done, value } = await reader.read();
|
|
5243
|
-
if (done) {
|
|
5244
|
-
streamEnded = true;
|
|
5245
|
-
console.log(
|
|
5246
|
-
`SSE\u6D41\u5DF2\u7ED3\u675F [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
5247
|
-
);
|
|
5248
|
-
break;
|
|
5249
|
-
}
|
|
5250
|
-
}
|
|
5251
|
-
} catch (streamError) {
|
|
5252
|
-
console.error("Error reading SSE stream:", streamError);
|
|
5253
|
-
throw streamError;
|
|
5254
|
-
} finally {
|
|
5255
|
-
reader.releaseLock();
|
|
5256
|
-
}
|
|
5257
|
-
if (callback_event) {
|
|
5258
|
-
const state = await agent_state({ assistant_id, thread_id, tenant_id });
|
|
5259
|
-
import_core24.eventBus.publish(callback_event, {
|
|
5260
|
-
success: true,
|
|
5261
|
-
state,
|
|
5262
|
-
config: { assistant_id, thread_id, tenant_id }
|
|
5263
|
-
});
|
|
5264
|
-
}
|
|
5265
|
-
console.log(
|
|
5266
|
-
`\u4EFB\u52A1\u5904\u7406\u6210\u529F [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
5267
|
-
);
|
|
5268
|
-
return true;
|
|
5269
|
-
} else {
|
|
5270
|
-
await response.text();
|
|
5271
|
-
if (callback_event) {
|
|
5272
|
-
const state = await agent_state({ assistant_id, thread_id, tenant_id });
|
|
5273
|
-
import_core24.eventBus.publish(callback_event, {
|
|
4941
|
+
const agent = import_core25.agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
|
|
4942
|
+
await agent.addMessage({ input, command }, import_core25.QueueMode.STEER);
|
|
4943
|
+
if (callback_event) {
|
|
4944
|
+
agent.subscribeOnce("message:completed", (evt) => {
|
|
4945
|
+
import_core25.eventBus.publish(callback_event, {
|
|
5274
4946
|
success: true,
|
|
5275
|
-
state,
|
|
4947
|
+
state: evt.state,
|
|
5276
4948
|
config: { assistant_id, thread_id, tenant_id }
|
|
5277
4949
|
});
|
|
5278
|
-
}
|
|
5279
|
-
console.log(
|
|
5280
|
-
`\u4EFB\u52A1\u5904\u7406\u6210\u529F [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
5281
|
-
);
|
|
5282
|
-
return true;
|
|
4950
|
+
});
|
|
5283
4951
|
}
|
|
4952
|
+
return true;
|
|
5284
4953
|
} catch (error) {
|
|
5285
4954
|
console.error(
|
|
5286
4955
|
`Agent\u4EFB\u52A1\u6267\u884C\u5931\u8D25: ${assistant_id}, \u7EBF\u7A0B: ${thread_id}`,
|
|
@@ -5297,7 +4966,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
5297
4966
|
return handleAgentTask(taskRequest, nextRetryCount);
|
|
5298
4967
|
}
|
|
5299
4968
|
if (callback_event) {
|
|
5300
|
-
|
|
4969
|
+
import_core25.eventBus.publish(callback_event, {
|
|
5301
4970
|
success: false,
|
|
5302
4971
|
error: error instanceof Error ? error.message : String(error),
|
|
5303
4972
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -5335,7 +5004,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
5335
5004
|
* 初始化事件监听和队列轮询
|
|
5336
5005
|
*/
|
|
5337
5006
|
initialize() {
|
|
5338
|
-
|
|
5007
|
+
import_core25.eventBus.subscribe(import_core25.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
|
|
5339
5008
|
this.startPollingQueue();
|
|
5340
5009
|
console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
|
|
5341
5010
|
}
|
|
@@ -5454,7 +5123,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
5454
5123
|
handleAgentTask(taskRequest).catch((error) => {
|
|
5455
5124
|
console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
|
|
5456
5125
|
if (taskRequest.callback_event) {
|
|
5457
|
-
|
|
5126
|
+
import_core25.eventBus.publish(taskRequest.callback_event, {
|
|
5458
5127
|
success: false,
|
|
5459
5128
|
error: error instanceof Error ? error.message : String(error),
|
|
5460
5129
|
config: {
|
|
@@ -5474,7 +5143,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
|
|
|
5474
5143
|
var AgentTaskConsumer = _AgentTaskConsumer;
|
|
5475
5144
|
|
|
5476
5145
|
// src/index.ts
|
|
5477
|
-
var
|
|
5146
|
+
var import_core26 = require("@axiom-lattice/core");
|
|
5478
5147
|
var import_protocols2 = require("@axiom-lattice/protocols");
|
|
5479
5148
|
process.on("unhandledRejection", (reason, promise) => {
|
|
5480
5149
|
console.error("\u672A\u5904\u7406\u7684Promise\u62D2\u7EDD:", reason);
|
|
@@ -5489,11 +5158,11 @@ var DEFAULT_LOGGER_CONFIG = {
|
|
|
5489
5158
|
var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
|
|
5490
5159
|
var logger = loggerLattice.client;
|
|
5491
5160
|
function initializeLogger(config) {
|
|
5492
|
-
if (
|
|
5493
|
-
|
|
5161
|
+
if (import_core26.loggerLatticeManager.hasLattice("default")) {
|
|
5162
|
+
import_core26.loggerLatticeManager.removeLattice("default");
|
|
5494
5163
|
}
|
|
5495
|
-
(0,
|
|
5496
|
-
return (0,
|
|
5164
|
+
(0, import_core26.registerLoggerLattice)("default", config);
|
|
5165
|
+
return (0, import_core26.getLoggerLattice)("default");
|
|
5497
5166
|
}
|
|
5498
5167
|
var app = (0, import_fastify.default)({
|
|
5499
5168
|
logger: false,
|
|
@@ -5533,7 +5202,6 @@ app.addHook("onResponse", (request, reply, done) => {
|
|
|
5533
5202
|
"x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
|
|
5534
5203
|
"x-request-id": getHeaderValue(request.headers["x-request-id"])
|
|
5535
5204
|
};
|
|
5536
|
-
loggerLattice.info(`${request.method} ${request.url} - ${reply.statusCode}`);
|
|
5537
5205
|
done();
|
|
5538
5206
|
});
|
|
5539
5207
|
app.register(import_cors.default, {
|
|
@@ -5594,16 +5262,16 @@ var start = async (config) => {
|
|
|
5594
5262
|
app.decorate("loggerLattice", loggerLattice);
|
|
5595
5263
|
registerLatticeRoutes(app);
|
|
5596
5264
|
try {
|
|
5597
|
-
const storeLattice = (0,
|
|
5265
|
+
const storeLattice = (0, import_core26.getStoreLattice)("default", "database");
|
|
5598
5266
|
const store = storeLattice.store;
|
|
5599
|
-
|
|
5267
|
+
import_core26.sqlDatabaseManager.setConfigStore(store);
|
|
5600
5268
|
logger.info("Database config store set for SqlDatabaseManager");
|
|
5601
5269
|
} catch (error) {
|
|
5602
5270
|
logger.warn("Failed to set database config store: " + (error instanceof Error ? error.message : String(error)));
|
|
5603
5271
|
}
|
|
5604
|
-
if (!
|
|
5272
|
+
if (!import_core26.sandboxLatticeManager.hasLattice("default")) {
|
|
5605
5273
|
const sandboxBaseURL = process.env.SANDBOX_BASE_URL || "http://localhost:8080";
|
|
5606
|
-
|
|
5274
|
+
import_core26.sandboxLatticeManager.registerLattice("default", {
|
|
5607
5275
|
baseURL: sandboxBaseURL
|
|
5608
5276
|
});
|
|
5609
5277
|
logger.info(`Registered sandbox manager with baseURL: ${sandboxBaseURL}`);
|
|
@@ -5611,6 +5279,11 @@ var start = async (config) => {
|
|
|
5611
5279
|
const target_port = config?.port || Number(process.env.PORT) || 4001;
|
|
5612
5280
|
await app.listen({ port: target_port, host: "0.0.0.0" });
|
|
5613
5281
|
logger.info(`Lattice Gateway is running on port: ${target_port}`);
|
|
5282
|
+
try {
|
|
5283
|
+
logger.info("AgentLifecycleManager initialized");
|
|
5284
|
+
} catch (error) {
|
|
5285
|
+
logger.warn("Failed to initialize AgentLifecycleManager", { error });
|
|
5286
|
+
}
|
|
5614
5287
|
const queueServiceConfig = config?.queueServiceConfig;
|
|
5615
5288
|
if (queueServiceConfig) {
|
|
5616
5289
|
setQueueServiceType(queueServiceConfig.type);
|