@axiom-lattice/gateway 2.1.44 → 2.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -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 import_core2 = require("@axiom-lattice/core");
45
+ var import_core = require("@axiom-lattice/core");
305
46
  var import_crypto = require("crypto");
306
- var import_core3 = require("@axiom-lattice/core");
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 import_core3.agentLatticeManager.getAllAgentConfigsByTenant(tenantId);
72
+ const agentConfigs = await import_core2.agentLatticeManager.getAllAgentConfigsByTenant(tenantId);
332
73
  const codeConfiguredAssistants = agentConfigs.map(
333
74
  convertAgentConfigToAssistant
334
75
  );
335
- const storeLattice = (0, import_core2.getStoreLattice)("default", "assistant");
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, import_core2.getStoreLattice)("default", "assistant");
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 import_core3.agentLatticeManager.getAgentConfigWithTenant(tenantId, id);
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, import_core2.getStoreLattice)("default", "assistant");
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
- import_core3.eventBus.publish("assistant:updated", { id: assistant.id, name: assistant.name, tenantId });
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
- import_core3.eventBus.publish("assistant:created", { id: assistant.id, name: assistant.name, tenantId });
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, import_core2.getStoreLattice)("default", "assistant");
178
+ const storeLattice = (0, import_core.getStoreLattice)("default", "assistant");
438
179
  const assistantStore = storeLattice.store;
439
- const agentConfig = await import_core3.agentLatticeManager.getAgentConfigWithTenant(tenantId, id);
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
- import_core3.eventBus.publish("assistant:deleted", { id, tenantId });
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
- import_core3.eventBus.publish("assistant:deleted", { id, tenantId });
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 imageData = await draw_graph(assistantId, tenant_id);
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 import_uuid2 = require("uuid");
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, import_uuid2.v4)();
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,14 @@ var createRun = async (request, reply) => {
541
273
  "Access-Control-Allow-Origin": "*"
542
274
  });
543
275
  try {
544
- let chunkCount = 0;
276
+ const result = await agent.addMessage({
277
+ input,
278
+ command,
279
+ custom_run_config
280
+ });
281
+ const stream = agent.chunkStream(result.messageId);
545
282
  for await (const chunk of stream) {
546
- chunkCount++;
283
+ console.log(input.message, chunk.data.content);
547
284
  const success = reply.raw.write(`data: ${JSON.stringify(chunk)}
548
285
 
549
286
  `);
@@ -555,7 +292,7 @@ var createRun = async (request, reply) => {
555
292
  const errorEvent = {
556
293
  type: "error",
557
294
  data: {
558
- id: (0, import_uuid2.v4)(),
295
+ id: (0, import_uuid.v4)(),
559
296
  content: error.message || "Stream processing error"
560
297
  }
561
298
  };
@@ -566,18 +303,16 @@ var createRun = async (request, reply) => {
566
303
  reply.raw.end();
567
304
  }
568
305
  } else {
569
- const result = await agent_invoke({
570
- assistant_id,
571
- input,
306
+ const { message: msg, ...restInputNonStream } = input;
307
+ const result = await agent.invoke({
308
+ input: { message: msg, ...restInputNonStream },
572
309
  command,
573
- thread_id,
574
- tenant_id,
575
- workspace_id,
576
- project_id,
577
- run_id: x_request_id,
578
310
  custom_run_config
579
311
  });
580
- reply.status(200).send(result);
312
+ reply.status(200).send({
313
+ success: true,
314
+ ...result
315
+ });
581
316
  }
582
317
  } catch (error) {
583
318
  reply.status(500).send({
@@ -604,12 +339,12 @@ var resumeStream = async (request, reply) => {
604
339
  "Access-Control-Allow-Origin": "*"
605
340
  });
606
341
  try {
607
- const stream = await resume_stream({
342
+ const agent = new import_core3.Agent({
343
+ assistant_id: "",
608
344
  thread_id,
609
- message_id,
610
- known_content,
611
- poll_interval: poll_interval || 100
345
+ tenant_id: ""
612
346
  });
347
+ const stream = agent.chunkStream(message_id, known_content);
613
348
  for await (const chunk of stream) {
614
349
  reply.raw.write(`data: ${JSON.stringify(chunk)}
615
350
 
@@ -619,7 +354,7 @@ var resumeStream = async (request, reply) => {
619
354
  const errorEvent = {
620
355
  type: "error",
621
356
  data: {
622
- id: (0, import_uuid2.v4)(),
357
+ id: (0, import_uuid.v4)(),
623
358
  content: error.message || "Resume stream processing error"
624
359
  }
625
360
  };
@@ -638,6 +373,7 @@ var resumeStream = async (request, reply) => {
638
373
  };
639
374
 
640
375
  // src/controllers/memory.ts
376
+ var import_core4 = require("@axiom-lattice/core");
641
377
  var setMemoryItem = async (request, reply) => {
642
378
  try {
643
379
  const { assistantId, key } = request.params;
@@ -702,11 +438,8 @@ var getAllMemoryItems = async (request, reply) => {
702
438
  });
703
439
  return;
704
440
  }
705
- const result = await agent_messages({
706
- assistant_id: assistantId,
707
- thread_id,
708
- tenant_id
709
- });
441
+ const agent = import_core4.agentInstanceManager.getAgent({ assistant_id: assistantId, tenant_id, thread_id });
442
+ const result = await agent.getCurrentMessages();
710
443
  if (!result) {
711
444
  reply.status(500).send(result);
712
445
  return;
@@ -737,16 +470,18 @@ var getAgentState = async (request, reply) => {
737
470
  return;
738
471
  }
739
472
  const tenant_id = request.headers["x-tenant-id"];
740
- const result = await agent_state({
741
- assistant_id: assistantId,
742
- thread_id,
743
- tenant_id
744
- });
473
+ const agent = import_core4.agentInstanceManager.getAgent({ assistant_id: assistantId, tenant_id, thread_id });
474
+ const result = await agent.getCurrentState();
475
+ const pendingMessages = await agent.getPendingMessages();
745
476
  if (!result) {
746
477
  reply.status(500).send(result);
747
478
  return;
748
479
  }
749
- reply.send(result);
480
+ const mergedResult = {
481
+ ...result,
482
+ pendingMessages
483
+ };
484
+ reply.send(mergedResult);
750
485
  } catch (error) {
751
486
  reply.status(500).send({
752
487
  success: false,
@@ -799,7 +534,7 @@ var clearMemory = async (request, reply) => {
799
534
  };
800
535
 
801
536
  // src/controllers/agent_task.ts
802
- var import_core4 = require("@axiom-lattice/core");
537
+ var import_core5 = require("@axiom-lattice/core");
803
538
  var triggerAgentTask = async (request, reply) => {
804
539
  try {
805
540
  const { assistant_id, thread_id, input, command } = request.body;
@@ -818,7 +553,7 @@ var triggerAgentTask = async (request, reply) => {
818
553
  });
819
554
  return;
820
555
  }
821
- const agentManager = import_core4.AgentManager.getInstance();
556
+ const agentManager = import_core5.AgentManager.getInstance();
822
557
  const result = await agentManager.callAgentInQueue({
823
558
  assistant_id,
824
559
  thread_id,
@@ -838,7 +573,7 @@ var triggerAgentTask = async (request, reply) => {
838
573
  };
839
574
 
840
575
  // src/controllers/threads.ts
841
- var import_core5 = require("@axiom-lattice/core");
576
+ var import_core6 = require("@axiom-lattice/core");
842
577
  var import_crypto2 = require("crypto");
843
578
  function getTenantId2(request) {
844
579
  const userTenantId = request.user?.tenantId;
@@ -850,7 +585,7 @@ function getTenantId2(request) {
850
585
  async function getThreadList(request, reply) {
851
586
  const tenantId = getTenantId2(request);
852
587
  const { assistantId } = request.params;
853
- const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
588
+ const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
854
589
  const threadStore = storeLattice.store;
855
590
  const threads = await threadStore.getThreadsByAssistantId(tenantId, assistantId);
856
591
  return {
@@ -865,7 +600,7 @@ async function getThreadList(request, reply) {
865
600
  async function getThread(request, reply) {
866
601
  const tenantId = getTenantId2(request);
867
602
  const { threadId } = request.params;
868
- const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
603
+ const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
869
604
  const threadStore = storeLattice.store;
870
605
  const thread = await threadStore.getThreadById(tenantId, threadId);
871
606
  if (!thread) {
@@ -885,7 +620,7 @@ async function createThread(request, reply) {
885
620
  const { assistantId } = request.params;
886
621
  const data = request.body;
887
622
  const threadId = (0, import_crypto2.randomUUID)();
888
- const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
623
+ const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
889
624
  const threadStore = storeLattice.store;
890
625
  const newThread = await threadStore.createThread(tenantId, assistantId, threadId, data);
891
626
  return reply.status(201).send({
@@ -898,7 +633,7 @@ async function updateThread(request, reply) {
898
633
  const tenantId = getTenantId2(request);
899
634
  const { threadId } = request.params;
900
635
  const updates = request.body;
901
- const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
636
+ const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
902
637
  const threadStore = storeLattice.store;
903
638
  const exists = await threadStore.hasThread(tenantId, threadId);
904
639
  if (!exists) {
@@ -927,7 +662,7 @@ async function updateThread(request, reply) {
927
662
  async function deleteThread(request, reply) {
928
663
  const tenantId = getTenantId2(request);
929
664
  const { threadId } = request.params;
930
- const storeLattice = (0, import_core5.getStoreLattice)("default", "thread");
665
+ const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
931
666
  const threadStore = storeLattice.store;
932
667
  const exists = await threadStore.hasThread(tenantId, threadId);
933
668
  if (!exists) {
@@ -950,7 +685,7 @@ async function deleteThread(request, reply) {
950
685
  }
951
686
 
952
687
  // src/controllers/schedules.ts
953
- var import_core6 = require("@axiom-lattice/core");
688
+ var import_core7 = require("@axiom-lattice/core");
954
689
  function getTenantId3(request) {
955
690
  const userTenantId = request.user?.tenantId;
956
691
  if (userTenantId) {
@@ -959,14 +694,14 @@ function getTenantId3(request) {
959
694
  return request.headers["x-tenant-id"] || "default";
960
695
  }
961
696
  function getScheduleLattice() {
962
- const keys = import_core6.scheduleLatticeManager.getLatticeKeys();
697
+ const keys = import_core7.scheduleLatticeManager.getLatticeKeys();
963
698
  if (keys.length === 0) {
964
699
  return null;
965
700
  }
966
- if (import_core6.scheduleLatticeManager.hasLattice("default")) {
967
- return import_core6.scheduleLatticeManager.getScheduleLattice("default");
701
+ if (import_core7.scheduleLatticeManager.hasLattice("default")) {
702
+ return import_core7.scheduleLatticeManager.getScheduleLattice("default");
968
703
  }
969
- return import_core6.scheduleLatticeManager.getScheduleLattice(keys[0]);
704
+ return import_core7.scheduleLatticeManager.getScheduleLattice(keys[0]);
970
705
  }
971
706
  async function getThreadSchedules(request, reply) {
972
707
  const { assistantId, threadId } = request.params;
@@ -1227,7 +962,7 @@ var ConfigService = class {
1227
962
  var configService = new ConfigService();
1228
963
 
1229
964
  // src/services/queue_service.ts
1230
- var import_core7 = require("@axiom-lattice/core");
965
+ var import_core8 = require("@axiom-lattice/core");
1231
966
  var import_protocols = require("@axiom-lattice/protocols");
1232
967
  var import_queue_redis = require("@axiom-lattice/queue-redis");
1233
968
  var DEFAULT_QUEUE_KEY = "default";
@@ -1246,8 +981,8 @@ var setQueueServiceType = (type) => {
1246
981
  redisPassword: process.env.REDIS_PASSWORD
1247
982
  } : void 0
1248
983
  };
1249
- if (import_core7.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
1250
- import_core7.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
984
+ if (import_core8.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
985
+ import_core8.queueLatticeManager.removeLattice(DEFAULT_QUEUE_KEY);
1251
986
  }
1252
987
  let client;
1253
988
  if (type === "redis") {
@@ -1256,13 +991,13 @@ var setQueueServiceType = (type) => {
1256
991
  redisPassword: process.env.REDIS_PASSWORD
1257
992
  });
1258
993
  }
1259
- (0, import_core7.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
994
+ (0, import_core8.registerQueueLattice)(DEFAULT_QUEUE_KEY, config, client);
1260
995
  };
1261
996
  var getQueueService = () => {
1262
- if (!import_core7.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
997
+ if (!import_core8.queueLatticeManager.hasLattice(DEFAULT_QUEUE_KEY)) {
1263
998
  setQueueServiceType(queueServiceType);
1264
999
  }
1265
- return (0, import_core7.getQueueLattice)(DEFAULT_QUEUE_KEY);
1000
+ return (0, import_core8.getQueueLattice)(DEFAULT_QUEUE_KEY);
1266
1001
  };
1267
1002
  var popAgentTaskFromQueue = async () => {
1268
1003
  const queue = getQueueService();
@@ -1343,16 +1078,18 @@ async function getConfig(request, reply) {
1343
1078
  }
1344
1079
 
1345
1080
  // src/controllers/models.ts
1346
- var import_core8 = require("@axiom-lattice/core");
1081
+ var import_core9 = require("@axiom-lattice/core");
1347
1082
  async function getModels(request, reply) {
1348
1083
  try {
1349
- const allLattices = import_core8.modelLatticeManager.getAllLattices();
1084
+ const allLattices = import_core9.modelLatticeManager.getAllLattices();
1350
1085
  const models = allLattices.map((lattice) => {
1351
1086
  const config = lattice.client.config || {};
1087
+ const displayName = config.displayName || lattice.key.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1352
1088
  return {
1353
1089
  key: lattice.key,
1354
1090
  model: config.model || "",
1355
1091
  provider: config.provider || "openai",
1092
+ displayName,
1356
1093
  streaming: config.streaming || false,
1357
1094
  apiKey: config.apiKey || "",
1358
1095
  baseURL: config.baseURL || "",
@@ -1396,12 +1133,13 @@ async function updateModels(request, reply) {
1396
1133
  continue;
1397
1134
  }
1398
1135
  try {
1399
- if (import_core8.modelLatticeManager.hasLattice(modelConfig.key)) {
1400
- import_core8.modelLatticeManager.removeLattice(modelConfig.key);
1136
+ if (import_core9.modelLatticeManager.hasLattice(modelConfig.key)) {
1137
+ import_core9.modelLatticeManager.removeLattice(modelConfig.key);
1401
1138
  }
1402
1139
  const llmConfig = {
1403
1140
  provider: modelConfig.provider,
1404
1141
  model: modelConfig.model,
1142
+ displayName: modelConfig.displayName,
1405
1143
  streaming: modelConfig.streaming ?? false,
1406
1144
  apiKey: modelConfig.apiKey,
1407
1145
  baseURL: modelConfig.baseURL,
@@ -1410,7 +1148,7 @@ async function updateModels(request, reply) {
1410
1148
  timeout: modelConfig.timeout,
1411
1149
  maxRetries: modelConfig.maxRetries
1412
1150
  };
1413
- (0, import_core8.registerModelLattice)(modelConfig.key, llmConfig);
1151
+ (0, import_core9.registerModelLattice)(modelConfig.key, llmConfig);
1414
1152
  registeredModels.push(modelConfig.key);
1415
1153
  } catch (error) {
1416
1154
  errors.push(
@@ -1468,8 +1206,8 @@ async function getHealth(request, reply) {
1468
1206
  }
1469
1207
 
1470
1208
  // src/controllers/skills.ts
1471
- var import_core9 = require("@axiom-lattice/core");
1472
1209
  var import_core10 = require("@axiom-lattice/core");
1210
+ var import_core11 = require("@axiom-lattice/core");
1473
1211
  function getTenantId4(request) {
1474
1212
  const userTenantId = request.user?.tenantId;
1475
1213
  if (userTenantId) {
@@ -1500,7 +1238,7 @@ function serializeSkill(skill) {
1500
1238
  async function getSkillList(request, reply) {
1501
1239
  try {
1502
1240
  const tenantId = getTenantId4(request);
1503
- const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1241
+ const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
1504
1242
  const skillStore = storeLattice.store;
1505
1243
  const skills = await skillStore.getAllSkills(tenantId);
1506
1244
  const serializedSkills = skills.map(serializeSkill);
@@ -1527,7 +1265,7 @@ async function getSkill(request, reply) {
1527
1265
  try {
1528
1266
  const tenantId = getTenantId4(request);
1529
1267
  const { id } = request.params;
1530
- const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1268
+ const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
1531
1269
  const skillStore = storeLattice.store;
1532
1270
  const skill = await skillStore.getSkillById(tenantId, id);
1533
1271
  if (!skill) {
@@ -1564,7 +1302,7 @@ async function createSkill(request, reply) {
1564
1302
  });
1565
1303
  }
1566
1304
  try {
1567
- (0, import_core10.validateSkillName)(data.name);
1305
+ (0, import_core11.validateSkillName)(data.name);
1568
1306
  } catch (error) {
1569
1307
  return reply.status(400).send({
1570
1308
  success: false,
@@ -1579,7 +1317,7 @@ async function createSkill(request, reply) {
1579
1317
  });
1580
1318
  }
1581
1319
  const tenantId = getTenantId4(request);
1582
- const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1320
+ const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
1583
1321
  const skillStore = storeLattice.store;
1584
1322
  const exists = await skillStore.hasSkill(tenantId, id);
1585
1323
  if (exists) {
@@ -1607,7 +1345,7 @@ async function updateSkill(request, reply) {
1607
1345
  const updates = request.body;
1608
1346
  if (updates.name !== void 0) {
1609
1347
  try {
1610
- (0, import_core10.validateSkillName)(updates.name);
1348
+ (0, import_core11.validateSkillName)(updates.name);
1611
1349
  } catch (error) {
1612
1350
  return reply.status(400).send({
1613
1351
  success: false,
@@ -1616,7 +1354,7 @@ async function updateSkill(request, reply) {
1616
1354
  }
1617
1355
  }
1618
1356
  const tenantId = getTenantId4(request);
1619
- const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1357
+ const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
1620
1358
  const skillStore = storeLattice.store;
1621
1359
  const exists = await skillStore.hasSkill(tenantId, id);
1622
1360
  if (!exists) {
@@ -1648,7 +1386,7 @@ async function deleteSkill(request, reply) {
1648
1386
  try {
1649
1387
  const { id } = request.params;
1650
1388
  const tenantId = getTenantId4(request);
1651
- const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1389
+ const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
1652
1390
  const skillStore = storeLattice.store;
1653
1391
  const exists = await skillStore.hasSkill(tenantId, id);
1654
1392
  if (!exists) {
@@ -1689,7 +1427,7 @@ async function searchSkillsByMetadata(request, reply) {
1689
1427
  });
1690
1428
  }
1691
1429
  const tenantId = getTenantId4(request);
1692
- const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1430
+ const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
1693
1431
  const skillStore = storeLattice.store;
1694
1432
  const skills = await skillStore.searchByMetadata(tenantId, key, value);
1695
1433
  const serializedSkills = skills.map(serializeSkill);
@@ -1726,7 +1464,7 @@ async function filterSkillsByCompatibility(request, reply) {
1726
1464
  });
1727
1465
  }
1728
1466
  const tenantId = getTenantId4(request);
1729
- const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1467
+ const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
1730
1468
  const skillStore = storeLattice.store;
1731
1469
  const skills = await skillStore.filterByCompatibility(tenantId, compatibility);
1732
1470
  const serializedSkills = skills.map(serializeSkill);
@@ -1763,7 +1501,7 @@ async function filterSkillsByLicense(request, reply) {
1763
1501
  });
1764
1502
  }
1765
1503
  const tenantId = getTenantId4(request);
1766
- const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1504
+ const storeLattice = (0, import_core10.getStoreLattice)("default", "skill");
1767
1505
  const skillStore = storeLattice.store;
1768
1506
  const skills = await skillStore.filterByLicense(tenantId, license);
1769
1507
  const serializedSkills = skills.map(serializeSkill);
@@ -1788,7 +1526,7 @@ async function filterSkillsByLicense(request, reply) {
1788
1526
  }
1789
1527
 
1790
1528
  // src/controllers/tools.ts
1791
- var import_core11 = require("@axiom-lattice/core");
1529
+ var import_core12 = require("@axiom-lattice/core");
1792
1530
  function serializeSchema(schema) {
1793
1531
  if (!schema) {
1794
1532
  return void 0;
@@ -1832,7 +1570,7 @@ function serializeSchema(schema) {
1832
1570
  }
1833
1571
  async function getToolConfigs(request, reply) {
1834
1572
  try {
1835
- const allLattices = import_core11.toolLatticeManager.getAllLattices();
1573
+ const allLattices = import_core12.toolLatticeManager.getAllLattices();
1836
1574
  const toolConfigs = allLattices.map((lattice) => {
1837
1575
  const config = { ...lattice.config };
1838
1576
  const serializedSchema = config.schema ? serializeSchema(config.schema) : void 0;
@@ -1870,7 +1608,7 @@ async function getToolConfigs(request, reply) {
1870
1608
  }
1871
1609
 
1872
1610
  // src/controllers/data-query.ts
1873
- var import_core12 = require("@axiom-lattice/core");
1611
+ var import_core13 = require("@axiom-lattice/core");
1874
1612
  function getTenantId5(request) {
1875
1613
  return request.headers["x-tenant-id"] || "default";
1876
1614
  }
@@ -1901,7 +1639,7 @@ async function executeDataQuery(request, reply) {
1901
1639
  message: "Cannot provide both metrics and customSql. Use one query type only."
1902
1640
  };
1903
1641
  }
1904
- const storeLattice = (0, import_core12.getStoreLattice)("default", "metrics");
1642
+ const storeLattice = (0, import_core13.getStoreLattice)("default", "metrics");
1905
1643
  const store = storeLattice.store;
1906
1644
  if (!body.serverKey) {
1907
1645
  reply.code(400);
@@ -1932,14 +1670,14 @@ async function executeDataQuery(request, reply) {
1932
1670
  message: "datasourceId is required"
1933
1671
  };
1934
1672
  }
1935
- if (!import_core12.metricsServerManager.hasServer(tenantId, body.serverKey)) {
1673
+ if (!import_core13.metricsServerManager.hasServer(tenantId, body.serverKey)) {
1936
1674
  reply.code(400);
1937
1675
  return {
1938
1676
  success: false,
1939
1677
  message: `Metrics server not registered: ${body.serverKey}. Please register the server first.`
1940
1678
  };
1941
1679
  }
1942
- const client = import_core12.metricsServerManager.getClient(tenantId, body.serverKey);
1680
+ const client = import_core13.metricsServerManager.getClient(tenantId, body.serverKey);
1943
1681
  if (isSemanticQuery) {
1944
1682
  return await executeSemanticQuery(client, body, reply);
1945
1683
  } else {
@@ -2350,7 +2088,7 @@ var getHealthSchema = {
2350
2088
  var import_stream = require("stream");
2351
2089
 
2352
2090
  // src/services/sandbox_service.ts
2353
- var import_core13 = require("@axiom-lattice/core");
2091
+ var import_core14 = require("@axiom-lattice/core");
2354
2092
  var ERROR_HTML = `<!DOCTYPE html>
2355
2093
  <html lang="zh-CN">
2356
2094
  <head>
@@ -2462,7 +2200,7 @@ var ERROR_HTML = `<!DOCTYPE html>
2462
2200
  </html>`;
2463
2201
  var SandboxService = class {
2464
2202
  getFilesystemIsolatedLevel(tenantId, assistantId) {
2465
- const agentLattice = import_core13.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
2203
+ const agentLattice = import_core14.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
2466
2204
  if (!agentLattice) {
2467
2205
  return null;
2468
2206
  }
@@ -2487,10 +2225,10 @@ var SandboxService = class {
2487
2225
  sandboxName = "global";
2488
2226
  break;
2489
2227
  }
2490
- return (0, import_core13.normalizeSandboxName)(sandboxName);
2228
+ return (0, import_core14.normalizeSandboxName)(sandboxName);
2491
2229
  }
2492
2230
  getTargetUrl(sandboxName) {
2493
- const sandboxManager = (0, import_core13.getSandBoxManager)();
2231
+ const sandboxManager = (0, import_core14.getSandBoxManager)();
2494
2232
  return `${sandboxManager.getBaseURL()}/sandbox/${sandboxName}`;
2495
2233
  }
2496
2234
  async getVncHtml(sandboxName) {
@@ -2535,7 +2273,7 @@ var SandboxService = class {
2535
2273
  var sandboxService = new SandboxService();
2536
2274
 
2537
2275
  // src/controllers/sandbox.ts
2538
- var import_core14 = require("@axiom-lattice/core");
2276
+ var import_core15 = require("@axiom-lattice/core");
2539
2277
  function getFilenameFromPath(path3) {
2540
2278
  const segments = path3.replace(/\/+$/, "").split("/");
2541
2279
  return segments[segments.length - 1] || "download";
@@ -2577,7 +2315,7 @@ function registerSandboxProxyRoutes(app2) {
2577
2315
  threadId,
2578
2316
  isolatedLevel
2579
2317
  );
2580
- const sandboxManager = (0, import_core14.getSandBoxManager)();
2318
+ const sandboxManager = (0, import_core15.getSandBoxManager)();
2581
2319
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2582
2320
  try {
2583
2321
  const data = await request.file();
@@ -2624,7 +2362,7 @@ function registerSandboxProxyRoutes(app2) {
2624
2362
  threadId,
2625
2363
  isolatedLevel
2626
2364
  );
2627
- const sandboxManager = (0, import_core14.getSandBoxManager)();
2365
+ const sandboxManager = (0, import_core15.getSandBoxManager)();
2628
2366
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2629
2367
  try {
2630
2368
  const resolvedPath = filePath.startsWith("/home/gem") ? filePath : `/home/gem/${filePath.replace(/^\//, "")}`;
@@ -2680,14 +2418,14 @@ function registerSandboxProxyRoutes(app2) {
2680
2418
  var fs = __toESM(require("fs/promises"));
2681
2419
  var path = __toESM(require("path"));
2682
2420
  var import_stream2 = require("stream");
2683
- var import_core15 = require("@axiom-lattice/core");
2684
2421
  var import_core16 = require("@axiom-lattice/core");
2685
2422
  var import_core17 = require("@axiom-lattice/core");
2686
- var import_uuid3 = require("uuid");
2423
+ var import_core18 = require("@axiom-lattice/core");
2424
+ var import_uuid2 = require("uuid");
2687
2425
  var WorkspaceController = class {
2688
2426
  constructor() {
2689
- this.workspaceStore = (0, import_core15.getStoreLattice)("default", "workspace").store;
2690
- this.projectStore = (0, import_core15.getStoreLattice)("default", "project").store;
2427
+ this.workspaceStore = (0, import_core16.getStoreLattice)("default", "workspace").store;
2428
+ this.projectStore = (0, import_core16.getStoreLattice)("default", "project").store;
2691
2429
  }
2692
2430
  getTenantId(request) {
2693
2431
  const userTenantId = request.user?.tenantId;
@@ -2709,7 +2447,7 @@ var WorkspaceController = class {
2709
2447
  async createWorkspace(request, reply) {
2710
2448
  const tenantId = this.getTenantId(request);
2711
2449
  const data = request.body;
2712
- const id = (0, import_uuid3.v4)();
2450
+ const id = (0, import_uuid2.v4)();
2713
2451
  const workspace = await this.workspaceStore.createWorkspace(
2714
2452
  tenantId,
2715
2453
  id,
@@ -2769,7 +2507,7 @@ var WorkspaceController = class {
2769
2507
  const tenantId = this.getTenantId(request);
2770
2508
  const { workspaceId } = request.params;
2771
2509
  const data = request.body;
2772
- const id = (0, import_uuid3.v4)();
2510
+ const id = (0, import_uuid2.v4)();
2773
2511
  const project = await this.projectStore.createProject(
2774
2512
  tenantId,
2775
2513
  workspaceId,
@@ -2820,11 +2558,11 @@ var WorkspaceController = class {
2820
2558
  throw new Error("Workspace not found");
2821
2559
  }
2822
2560
  if (workspace.storageType === "sandbox") {
2823
- const sandboxManager = (0, import_core17.getSandBoxManager)();
2561
+ const sandboxManager = (0, import_core18.getSandBoxManager)();
2824
2562
  const sandboxName = "global";
2825
2563
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2826
2564
  return {
2827
- backend: new import_core16.SandboxFilesystem({
2565
+ backend: new import_core17.SandboxFilesystem({
2828
2566
  sandboxInstance: sandbox,
2829
2567
  workingDirectory: `/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`
2830
2568
  }),
@@ -2832,7 +2570,7 @@ var WorkspaceController = class {
2832
2570
  };
2833
2571
  } else {
2834
2572
  return {
2835
- backend: new import_core16.FilesystemBackend({
2573
+ backend: new import_core17.FilesystemBackend({
2836
2574
  rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
2837
2575
  virtualMode: true
2838
2576
  }),
@@ -2877,7 +2615,7 @@ var WorkspaceController = class {
2877
2615
  const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
2878
2616
  const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
2879
2617
  if (workspace.storageType === "sandbox") {
2880
- const sandboxManager = (0, import_core17.getSandBoxManager)();
2618
+ const sandboxManager = (0, import_core18.getSandBoxManager)();
2881
2619
  const sandbox = await sandboxManager.createSandbox("global");
2882
2620
  const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
2883
2621
  const filename2 = this.getFilenameFromPath(resolvedPath);
@@ -2946,7 +2684,7 @@ var WorkspaceController = class {
2946
2684
  const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
2947
2685
  const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
2948
2686
  if (workspace.storageType === "sandbox") {
2949
- const sandboxManager = (0, import_core17.getSandBoxManager)();
2687
+ const sandboxManager = (0, import_core18.getSandBoxManager)();
2950
2688
  const sandbox = await sandboxManager.createSandbox("global");
2951
2689
  const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
2952
2690
  const filename2 = this.getFilenameFromPath(resolvedPath);
@@ -3116,7 +2854,7 @@ var WorkspaceController = class {
3116
2854
  return reply.status(400).send({ success: false, error: "Invalid path parameter" });
3117
2855
  }
3118
2856
  if (workspace.storageType === "sandbox") {
3119
- const sandboxManager = (0, import_core17.getSandBoxManager)();
2857
+ const sandboxManager = (0, import_core18.getSandBoxManager)();
3120
2858
  const sandboxName = "global";
3121
2859
  const sandbox = await sandboxManager.createSandbox(sandboxName);
3122
2860
  const baseDir = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId);
@@ -3222,7 +2960,7 @@ function registerWorkspaceRoutes(app2) {
3222
2960
  }
3223
2961
 
3224
2962
  // src/controllers/database-configs.ts
3225
- var import_core18 = require("@axiom-lattice/core");
2963
+ var import_core19 = require("@axiom-lattice/core");
3226
2964
  var import_crypto3 = require("crypto");
3227
2965
  function getTenantId6(request) {
3228
2966
  const userTenantId = request.user?.tenantId;
@@ -3234,7 +2972,7 @@ function getTenantId6(request) {
3234
2972
  async function getDatabaseConfigList(request, reply) {
3235
2973
  const tenantId = getTenantId6(request);
3236
2974
  try {
3237
- const storeLattice = (0, import_core18.getStoreLattice)("default", "database");
2975
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3238
2976
  const store = storeLattice.store;
3239
2977
  const configs = await store.getAllConfigs(tenantId);
3240
2978
  console.log("Backend: getAllConfigs returned:", configs);
@@ -3265,7 +3003,7 @@ async function getDatabaseConfig(request, reply) {
3265
3003
  const tenantId = getTenantId6(request);
3266
3004
  const { key } = request.params;
3267
3005
  try {
3268
- const storeLattice = (0, import_core18.getStoreLattice)("default", "database");
3006
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3269
3007
  const store = storeLattice.store;
3270
3008
  const config = await store.getConfigByKey(tenantId, key);
3271
3009
  if (!config) {
@@ -3291,7 +3029,7 @@ async function createDatabaseConfig(request, reply) {
3291
3029
  const tenantId = getTenantId6(request);
3292
3030
  const body = request.body;
3293
3031
  try {
3294
- const storeLattice = (0, import_core18.getStoreLattice)("default", "database");
3032
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3295
3033
  const store = storeLattice.store;
3296
3034
  const existing = await store.getConfigByKey(tenantId, body.key);
3297
3035
  if (existing) {
@@ -3304,7 +3042,7 @@ async function createDatabaseConfig(request, reply) {
3304
3042
  const id = body.id || (0, import_crypto3.randomUUID)();
3305
3043
  const config = await store.createConfig(tenantId, id, body);
3306
3044
  try {
3307
- import_core18.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
3045
+ import_core19.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
3308
3046
  } catch (error) {
3309
3047
  console.warn("Failed to auto-register database:", error);
3310
3048
  }
@@ -3327,7 +3065,7 @@ async function updateDatabaseConfig(request, reply) {
3327
3065
  const { key } = request.params;
3328
3066
  const updates = request.body;
3329
3067
  try {
3330
- const storeLattice = (0, import_core18.getStoreLattice)("default", "database");
3068
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3331
3069
  const store = storeLattice.store;
3332
3070
  const existing = await store.getConfigByKey(tenantId, key);
3333
3071
  if (!existing) {
@@ -3346,7 +3084,7 @@ async function updateDatabaseConfig(request, reply) {
3346
3084
  }
3347
3085
  if (updates.config) {
3348
3086
  try {
3349
- import_core18.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
3087
+ import_core19.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
3350
3088
  } catch (error) {
3351
3089
  console.warn("Failed to re-register database:", error);
3352
3090
  }
@@ -3368,7 +3106,7 @@ async function deleteDatabaseConfig(request, reply) {
3368
3106
  const tenantId = getTenantId6(request);
3369
3107
  const { keyOrId } = request.params;
3370
3108
  try {
3371
- const storeLattice = (0, import_core18.getStoreLattice)("default", "database");
3109
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3372
3110
  const store = storeLattice.store;
3373
3111
  console.log("Delete request - keyOrId:", keyOrId);
3374
3112
  let config = await store.getConfigByKey(tenantId, keyOrId);
@@ -3395,8 +3133,8 @@ async function deleteDatabaseConfig(request, reply) {
3395
3133
  };
3396
3134
  }
3397
3135
  try {
3398
- if (import_core18.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
3399
- await import_core18.sqlDatabaseManager.removeDatabase(tenantId, configKey);
3136
+ if (import_core19.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
3137
+ await import_core19.sqlDatabaseManager.removeDatabase(tenantId, configKey);
3400
3138
  }
3401
3139
  } catch (error) {
3402
3140
  console.warn("Failed to remove from SqlDatabaseManager:", error);
@@ -3417,7 +3155,7 @@ async function testDatabaseConnection(request, reply) {
3417
3155
  const tenantId = getTenantId6(request);
3418
3156
  const { key } = request.params;
3419
3157
  try {
3420
- const storeLattice = (0, import_core18.getStoreLattice)("default", "database");
3158
+ const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3421
3159
  const store = storeLattice.store;
3422
3160
  const config = await store.getConfigByKey(tenantId, key);
3423
3161
  if (!config) {
@@ -3428,16 +3166,16 @@ async function testDatabaseConnection(request, reply) {
3428
3166
  };
3429
3167
  }
3430
3168
  const testKey = `__test_${key}_${Date.now()}`;
3431
- import_core18.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
3169
+ import_core19.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
3432
3170
  const startTime = Date.now();
3433
- const db = await import_core18.sqlDatabaseManager.getDatabase(tenantId, testKey);
3171
+ const db = await import_core19.sqlDatabaseManager.getDatabase(tenantId, testKey);
3434
3172
  try {
3435
3173
  await db.connect();
3436
3174
  await db.listTables();
3437
3175
  const latency = Date.now() - startTime;
3438
3176
  await new Promise((resolve) => setTimeout(resolve, 100));
3439
3177
  await db.disconnect();
3440
- await import_core18.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3178
+ await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3441
3179
  return {
3442
3180
  success: true,
3443
3181
  message: "Connection test successful",
@@ -3449,7 +3187,7 @@ async function testDatabaseConnection(request, reply) {
3449
3187
  } catch (error) {
3450
3188
  try {
3451
3189
  await db.disconnect();
3452
- await import_core18.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3190
+ await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3453
3191
  } catch {
3454
3192
  }
3455
3193
  return {
@@ -3501,7 +3239,7 @@ function registerDatabaseConfigRoutes(app2) {
3501
3239
  }
3502
3240
 
3503
3241
  // src/controllers/metrics-configs.ts
3504
- var import_core19 = require("@axiom-lattice/core");
3242
+ var import_core20 = require("@axiom-lattice/core");
3505
3243
  var import_crypto4 = require("crypto");
3506
3244
  function getTenantId7(request) {
3507
3245
  const userTenantId = request.user?.tenantId;
@@ -3513,7 +3251,7 @@ function getTenantId7(request) {
3513
3251
  async function getMetricsServerConfigList(request, reply) {
3514
3252
  const tenantId = getTenantId7(request);
3515
3253
  try {
3516
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3254
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3517
3255
  const store = storeLattice.store;
3518
3256
  const configs = await store.getAllConfigs(tenantId);
3519
3257
  return {
@@ -3540,7 +3278,7 @@ async function getMetricsServerConfig(request, reply) {
3540
3278
  const tenantId = getTenantId7(request);
3541
3279
  const { key } = request.params;
3542
3280
  try {
3543
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3281
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3544
3282
  const store = storeLattice.store;
3545
3283
  const config = await store.getConfigByKey(tenantId, key);
3546
3284
  if (!config) {
@@ -3566,7 +3304,7 @@ async function createMetricsServerConfig(request, reply) {
3566
3304
  const tenantId = getTenantId7(request);
3567
3305
  const body = request.body;
3568
3306
  try {
3569
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3307
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3570
3308
  const store = storeLattice.store;
3571
3309
  const existing = await store.getConfigByKey(tenantId, body.key);
3572
3310
  if (existing) {
@@ -3595,7 +3333,7 @@ async function createMetricsServerConfig(request, reply) {
3595
3333
  };
3596
3334
  const config = await store.createConfig(tenantId, id, configData);
3597
3335
  try {
3598
- import_core19.metricsServerManager.registerServer(tenantId, config.key, config.config);
3336
+ import_core20.metricsServerManager.registerServer(tenantId, config.key, config.config);
3599
3337
  } catch (error) {
3600
3338
  console.warn("Failed to auto-register metrics server:", error);
3601
3339
  }
@@ -3618,7 +3356,7 @@ async function updateMetricsServerConfig(request, reply) {
3618
3356
  const { key } = request.params;
3619
3357
  const updates = request.body;
3620
3358
  try {
3621
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3359
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3622
3360
  const store = storeLattice.store;
3623
3361
  const existing = await store.getConfigByKey(tenantId, key);
3624
3362
  if (!existing) {
@@ -3646,7 +3384,7 @@ async function updateMetricsServerConfig(request, reply) {
3646
3384
  }
3647
3385
  if (updates.config) {
3648
3386
  try {
3649
- import_core19.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
3387
+ import_core20.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
3650
3388
  } catch (error) {
3651
3389
  console.warn("Failed to re-register metrics server:", error);
3652
3390
  }
@@ -3668,7 +3406,7 @@ async function deleteMetricsServerConfig(request, reply) {
3668
3406
  const tenantId = getTenantId7(request);
3669
3407
  const { keyOrId } = request.params;
3670
3408
  try {
3671
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3409
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3672
3410
  const store = storeLattice.store;
3673
3411
  let config = await store.getConfigByKey(tenantId, keyOrId);
3674
3412
  let configKey = keyOrId;
@@ -3693,8 +3431,8 @@ async function deleteMetricsServerConfig(request, reply) {
3693
3431
  };
3694
3432
  }
3695
3433
  try {
3696
- if (import_core19.metricsServerManager.hasServer(tenantId, configKey)) {
3697
- import_core19.metricsServerManager.removeServer(tenantId, configKey);
3434
+ if (import_core20.metricsServerManager.hasServer(tenantId, configKey)) {
3435
+ import_core20.metricsServerManager.removeServer(tenantId, configKey);
3698
3436
  }
3699
3437
  } catch (error) {
3700
3438
  console.warn("Failed to remove from MetricsServerManager:", error);
@@ -3715,7 +3453,7 @@ async function testMetricsServerConnection(request, reply) {
3715
3453
  const tenantId = getTenantId7(request);
3716
3454
  const { key } = request.params;
3717
3455
  try {
3718
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3456
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3719
3457
  const store = storeLattice.store;
3720
3458
  const config = await store.getConfigByKey(tenantId, key);
3721
3459
  if (!config) {
@@ -3726,11 +3464,11 @@ async function testMetricsServerConnection(request, reply) {
3726
3464
  };
3727
3465
  }
3728
3466
  const testKey = `__test_${key}_${Date.now()}`;
3729
- import_core19.metricsServerManager.registerServer(tenantId, testKey, config.config);
3467
+ import_core20.metricsServerManager.registerServer(tenantId, testKey, config.config);
3730
3468
  try {
3731
- const client = import_core19.metricsServerManager.getClient(tenantId, testKey);
3469
+ const client = import_core20.metricsServerManager.getClient(tenantId, testKey);
3732
3470
  const result = await client.testConnection();
3733
- import_core19.metricsServerManager.removeServer(tenantId, testKey);
3471
+ import_core20.metricsServerManager.removeServer(tenantId, testKey);
3734
3472
  return {
3735
3473
  success: true,
3736
3474
  message: result.connected ? "Connection test successful" : "Connection test failed",
@@ -3738,7 +3476,7 @@ async function testMetricsServerConnection(request, reply) {
3738
3476
  };
3739
3477
  } catch (error) {
3740
3478
  try {
3741
- import_core19.metricsServerManager.removeServer(tenantId, testKey);
3479
+ import_core20.metricsServerManager.removeServer(tenantId, testKey);
3742
3480
  } catch {
3743
3481
  }
3744
3482
  return {
@@ -3766,7 +3504,7 @@ async function listAvailableMetrics(request, reply) {
3766
3504
  const tenantId = getTenantId7(request);
3767
3505
  const { key } = request.params;
3768
3506
  try {
3769
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3507
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3770
3508
  const store = storeLattice.store;
3771
3509
  const config = await store.getConfigByKey(tenantId, key);
3772
3510
  if (!config) {
@@ -3776,10 +3514,10 @@ async function listAvailableMetrics(request, reply) {
3776
3514
  message: "Metrics server configuration not found"
3777
3515
  };
3778
3516
  }
3779
- if (!import_core19.metricsServerManager.hasServer(tenantId, key)) {
3780
- import_core19.metricsServerManager.registerServer(tenantId, key, config.config);
3517
+ if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
3518
+ import_core20.metricsServerManager.registerServer(tenantId, key, config.config);
3781
3519
  }
3782
- const client = import_core19.metricsServerManager.getClient(tenantId, key);
3520
+ const client = import_core20.metricsServerManager.getClient(tenantId, key);
3783
3521
  const metrics = await client.listMetrics();
3784
3522
  return {
3785
3523
  success: true,
@@ -3805,7 +3543,7 @@ async function queryMetricsData(request, reply) {
3805
3543
  const { key } = request.params;
3806
3544
  const { metricName, startTime, endTime, step, labels } = request.body;
3807
3545
  try {
3808
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3546
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3809
3547
  const store = storeLattice.store;
3810
3548
  const config = await store.getConfigByKey(tenantId, key);
3811
3549
  if (!config) {
@@ -3822,10 +3560,10 @@ async function queryMetricsData(request, reply) {
3822
3560
  message: "metricName is required"
3823
3561
  };
3824
3562
  }
3825
- if (!import_core19.metricsServerManager.hasServer(tenantId, key)) {
3826
- import_core19.metricsServerManager.registerServer(tenantId, key, config.config);
3563
+ if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
3564
+ import_core20.metricsServerManager.registerServer(tenantId, key, config.config);
3827
3565
  }
3828
- const client = import_core19.metricsServerManager.getClient(tenantId, key);
3566
+ const client = import_core20.metricsServerManager.getClient(tenantId, key);
3829
3567
  const result = await client.queryMetricData(metricName, {
3830
3568
  startTime,
3831
3569
  endTime,
@@ -3852,7 +3590,7 @@ async function getDataSources(request, reply) {
3852
3590
  const tenantId = getTenantId7(request);
3853
3591
  const { key } = request.params;
3854
3592
  try {
3855
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3593
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3856
3594
  const store = storeLattice.store;
3857
3595
  const config = await store.getConfigByKey(tenantId, key);
3858
3596
  if (!config) {
@@ -3870,7 +3608,7 @@ async function getDataSources(request, reply) {
3870
3608
  };
3871
3609
  }
3872
3610
  const semanticConfig = config.config;
3873
- const client = new import_core19.SemanticMetricsClient(semanticConfig);
3611
+ const client = new import_core20.SemanticMetricsClient(semanticConfig);
3874
3612
  const allDatasources = await client.getDataSources();
3875
3613
  const selectedIds = semanticConfig.selectedDataSources || [];
3876
3614
  const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
@@ -3893,7 +3631,7 @@ async function getDatasourceMetrics(request, reply) {
3893
3631
  const tenantId = getTenantId7(request);
3894
3632
  const { key, datasourceId } = request.params;
3895
3633
  try {
3896
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3634
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3897
3635
  const store = storeLattice.store;
3898
3636
  const config = await store.getConfigByKey(tenantId, key);
3899
3637
  if (!config) {
@@ -3911,7 +3649,7 @@ async function getDatasourceMetrics(request, reply) {
3911
3649
  };
3912
3650
  }
3913
3651
  const semanticConfig = config.config;
3914
- const client = new import_core19.SemanticMetricsClient(semanticConfig);
3652
+ const client = new import_core20.SemanticMetricsClient(semanticConfig);
3915
3653
  const metrics = await client.getDatasourceMetrics(datasourceId);
3916
3654
  return {
3917
3655
  success: true,
@@ -3931,7 +3669,7 @@ async function querySemanticMetrics(request, reply) {
3931
3669
  const { key } = request.params;
3932
3670
  const body = request.body;
3933
3671
  try {
3934
- const storeLattice = (0, import_core19.getStoreLattice)("default", "metrics");
3672
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3935
3673
  const store = storeLattice.store;
3936
3674
  const config = await store.getConfigByKey(tenantId, key);
3937
3675
  if (!config) {
@@ -3956,7 +3694,7 @@ async function querySemanticMetrics(request, reply) {
3956
3694
  };
3957
3695
  }
3958
3696
  const semanticConfig = config.config;
3959
- const client = new import_core19.SemanticMetricsClient(semanticConfig);
3697
+ const client = new import_core20.SemanticMetricsClient(semanticConfig);
3960
3698
  const result = await client.semanticQuery(body);
3961
3699
  const columnNames = result.columns.map((col) => col.name);
3962
3700
  const allDataPoints = [];
@@ -4016,7 +3754,7 @@ async function testSemanticDataSources(request, reply) {
4016
3754
  password: body.password,
4017
3755
  headers: body.headers
4018
3756
  };
4019
- const client = new import_core19.SemanticMetricsClient(testConfig);
3757
+ const client = new import_core20.SemanticMetricsClient(testConfig);
4020
3758
  const datasources = await client.getDataSources();
4021
3759
  return {
4022
3760
  success: true,
@@ -4052,7 +3790,7 @@ async function testDatasourceMetrics(request, reply) {
4052
3790
  password: body.password,
4053
3791
  headers: body.headers
4054
3792
  };
4055
- const client = new import_core19.SemanticMetricsClient(testConfig);
3793
+ const client = new import_core20.SemanticMetricsClient(testConfig);
4056
3794
  const metrics = await client.getDatasourceMetrics(datasourceId);
4057
3795
  return {
4058
3796
  success: true,
@@ -4084,7 +3822,7 @@ function registerMetricsServerConfigRoutes(app2) {
4084
3822
  }
4085
3823
 
4086
3824
  // src/controllers/mcp-configs.ts
4087
- var import_core20 = require("@axiom-lattice/core");
3825
+ var import_core21 = require("@axiom-lattice/core");
4088
3826
  var import_crypto5 = require("crypto");
4089
3827
  function getTenantId8(request) {
4090
3828
  const userTenantId = request.user?.tenantId;
@@ -4096,7 +3834,7 @@ function getTenantId8(request) {
4096
3834
  async function getMcpServerConfigList(request, reply) {
4097
3835
  const tenantId = getTenantId8(request);
4098
3836
  try {
4099
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
3837
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4100
3838
  const store = storeLattice.store;
4101
3839
  const configs = await store.getAllConfigs(tenantId);
4102
3840
  return {
@@ -4123,7 +3861,7 @@ async function getMcpServerConfig(request, reply) {
4123
3861
  const tenantId = getTenantId8(request);
4124
3862
  const { key } = request.params;
4125
3863
  try {
4126
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
3864
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4127
3865
  const store = storeLattice.store;
4128
3866
  const config = await store.getConfigByKey(tenantId, key);
4129
3867
  if (!config) {
@@ -4149,7 +3887,7 @@ async function createMcpServerConfig(request, reply) {
4149
3887
  const tenantId = getTenantId8(request);
4150
3888
  const body = request.body;
4151
3889
  try {
4152
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
3890
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4153
3891
  const store = storeLattice.store;
4154
3892
  const existing = await store.getConfigByKey(tenantId, body.key);
4155
3893
  if (existing) {
@@ -4189,7 +3927,7 @@ async function updateMcpServerConfig(request, reply) {
4189
3927
  const { key } = request.params;
4190
3928
  const updates = request.body;
4191
3929
  try {
4192
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
3930
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4193
3931
  const store = storeLattice.store;
4194
3932
  const existing = await store.getConfigByKey(tenantId, key);
4195
3933
  if (!existing) {
@@ -4209,8 +3947,8 @@ async function updateMcpServerConfig(request, reply) {
4209
3947
  }
4210
3948
  if (shouldReconnect) {
4211
3949
  try {
4212
- if (import_core20.mcpManager.hasServer(key)) {
4213
- await import_core20.mcpManager.removeServer(key);
3950
+ if (import_core21.mcpManager.hasServer(key)) {
3951
+ await import_core21.mcpManager.removeServer(key);
4214
3952
  }
4215
3953
  await connectAndRegisterTools(updated);
4216
3954
  await store.updateConfig(tenantId, existing.id, { status: "connected" });
@@ -4238,7 +3976,7 @@ async function deleteMcpServerConfig(request, reply) {
4238
3976
  const tenantId = getTenantId8(request);
4239
3977
  const { keyOrId } = request.params;
4240
3978
  try {
4241
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
3979
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4242
3980
  const store = storeLattice.store;
4243
3981
  let config = await store.getConfigByKey(tenantId, keyOrId);
4244
3982
  let configKey = keyOrId;
@@ -4256,8 +3994,8 @@ async function deleteMcpServerConfig(request, reply) {
4256
3994
  };
4257
3995
  }
4258
3996
  try {
4259
- if (import_core20.mcpManager.hasServer(configKey)) {
4260
- await import_core20.mcpManager.removeServer(configKey);
3997
+ if (import_core21.mcpManager.hasServer(configKey)) {
3998
+ await import_core21.mcpManager.removeServer(configKey);
4261
3999
  }
4262
4000
  } catch (error) {
4263
4001
  console.warn("Failed to remove from MCP manager:", error);
@@ -4285,7 +4023,7 @@ async function testMcpServerConnection(request, reply) {
4285
4023
  const tenantId = getTenantId8(request);
4286
4024
  const { key } = request.params;
4287
4025
  try {
4288
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
4026
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4289
4027
  const store = storeLattice.store;
4290
4028
  const config = await store.getConfigByKey(tenantId, key);
4291
4029
  if (!config) {
@@ -4299,11 +4037,11 @@ async function testMcpServerConnection(request, reply) {
4299
4037
  try {
4300
4038
  const testKey = `__test_${key}_${Date.now()}`;
4301
4039
  const connection = convertToConnection(config.config);
4302
- import_core20.mcpManager.addServer(testKey, connection);
4303
- await import_core20.mcpManager.connect();
4304
- const tools = await import_core20.mcpManager.getAllTools();
4040
+ import_core21.mcpManager.addServer(testKey, connection);
4041
+ await import_core21.mcpManager.connect();
4042
+ const tools = await import_core21.mcpManager.getAllTools();
4305
4043
  const latency = Date.now() - startTime;
4306
- await import_core20.mcpManager.removeServer(testKey);
4044
+ await import_core21.mcpManager.removeServer(testKey);
4307
4045
  return {
4308
4046
  success: true,
4309
4047
  message: "Connection test successful",
@@ -4338,7 +4076,7 @@ async function listMcpServerTools(request, reply) {
4338
4076
  const tenantId = getTenantId8(request);
4339
4077
  const { key } = request.params;
4340
4078
  try {
4341
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
4079
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4342
4080
  const store = storeLattice.store;
4343
4081
  const config = await store.getConfigByKey(tenantId, key);
4344
4082
  if (!config) {
@@ -4348,10 +4086,10 @@ async function listMcpServerTools(request, reply) {
4348
4086
  message: "MCP server configuration not found"
4349
4087
  };
4350
4088
  }
4351
- if (!import_core20.mcpManager.hasServer(key)) {
4089
+ if (!import_core21.mcpManager.hasServer(key)) {
4352
4090
  await connectAndRegisterTools(config);
4353
4091
  }
4354
- const tools = await import_core20.mcpManager.getAllTools();
4092
+ const tools = await import_core21.mcpManager.getAllTools();
4355
4093
  return {
4356
4094
  success: true,
4357
4095
  message: "Tools retrieved successfully",
@@ -4371,7 +4109,7 @@ async function connectMcpServer(request, reply) {
4371
4109
  const tenantId = getTenantId8(request);
4372
4110
  const { key } = request.params;
4373
4111
  try {
4374
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
4112
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4375
4113
  const store = storeLattice.store;
4376
4114
  const config = await store.getConfigByKey(tenantId, key);
4377
4115
  if (!config) {
@@ -4392,7 +4130,7 @@ async function connectMcpServer(request, reply) {
4392
4130
  };
4393
4131
  } catch (error) {
4394
4132
  console.error("Failed to connect MCP server:", error);
4395
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
4133
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4396
4134
  const store = storeLattice.store;
4397
4135
  const config = await store.getConfigByKey(tenantId, key);
4398
4136
  if (config) {
@@ -4408,7 +4146,7 @@ async function disconnectMcpServer(request, reply) {
4408
4146
  const tenantId = getTenantId8(request);
4409
4147
  const { key } = request.params;
4410
4148
  try {
4411
- const storeLattice = (0, import_core20.getStoreLattice)("default", "mcp");
4149
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4412
4150
  const store = storeLattice.store;
4413
4151
  const config = await store.getConfigByKey(tenantId, key);
4414
4152
  if (!config) {
@@ -4418,8 +4156,8 @@ async function disconnectMcpServer(request, reply) {
4418
4156
  message: "MCP server configuration not found"
4419
4157
  };
4420
4158
  }
4421
- if (import_core20.mcpManager.hasServer(key)) {
4422
- await import_core20.mcpManager.removeServer(key);
4159
+ if (import_core21.mcpManager.hasServer(key)) {
4160
+ await import_core21.mcpManager.removeServer(key);
4423
4161
  }
4424
4162
  const updated = await store.updateConfig(tenantId, config.id, {
4425
4163
  status: "disconnected"
@@ -4449,10 +4187,10 @@ async function testMcpServerTools(request, reply) {
4449
4187
  }
4450
4188
  const testKey = `__test_${Date.now()}`;
4451
4189
  const connection = convertToConnection(body.config);
4452
- import_core20.mcpManager.addServer(testKey, connection);
4453
- await import_core20.mcpManager.connect();
4454
- const tools = await import_core20.mcpManager.getAllTools();
4455
- await import_core20.mcpManager.removeServer(testKey);
4190
+ import_core21.mcpManager.addServer(testKey, connection);
4191
+ await import_core21.mcpManager.connect();
4192
+ const tools = await import_core21.mcpManager.getAllTools();
4193
+ await import_core21.mcpManager.removeServer(testKey);
4456
4194
  return {
4457
4195
  success: true,
4458
4196
  message: "Tools retrieved successfully",
@@ -4489,14 +4227,14 @@ function convertToConnection(config) {
4489
4227
  }
4490
4228
  async function connectAndRegisterTools(config) {
4491
4229
  const connection = convertToConnection(config.config);
4492
- import_core20.mcpManager.addServer(config.key, connection);
4493
- await import_core20.mcpManager.connect();
4494
- const allTools = await import_core20.mcpManager.getAllTools();
4230
+ import_core21.mcpManager.addServer(config.key, connection);
4231
+ await import_core21.mcpManager.connect();
4232
+ const allTools = await import_core21.mcpManager.getAllTools();
4495
4233
  const selectedTools = allTools.filter(
4496
4234
  (tool) => config.selectedTools.includes(tool.name)
4497
4235
  );
4498
4236
  for (const tool of selectedTools) {
4499
- import_core20.toolLatticeManager.registerExistingTool(tool.name, tool);
4237
+ import_core21.toolLatticeManager.registerExistingTool(tool.name, tool);
4500
4238
  }
4501
4239
  }
4502
4240
  function registerMcpServerConfigRoutes(app2) {
@@ -4513,11 +4251,11 @@ function registerMcpServerConfigRoutes(app2) {
4513
4251
  }
4514
4252
 
4515
4253
  // src/controllers/users.ts
4516
- var import_core21 = require("@axiom-lattice/core");
4517
- var import_uuid4 = require("uuid");
4254
+ var import_core22 = require("@axiom-lattice/core");
4255
+ var import_uuid3 = require("uuid");
4518
4256
  var UsersController = class {
4519
4257
  constructor() {
4520
- this.userStore = (0, import_core21.getStoreLattice)("default", "user").store;
4258
+ this.userStore = (0, import_core22.getStoreLattice)("default", "user").store;
4521
4259
  }
4522
4260
  async listUsers(request, reply) {
4523
4261
  const { email } = request.query;
@@ -4530,7 +4268,7 @@ var UsersController = class {
4530
4268
  }
4531
4269
  async createUser(request, reply) {
4532
4270
  const data = request.body;
4533
- const id = (0, import_uuid4.v4)();
4271
+ const id = (0, import_uuid3.v4)();
4534
4272
  const existingUser = await this.userStore.getUserByEmail(data.email);
4535
4273
  if (existingUser) {
4536
4274
  return reply.status(409).send({
@@ -4595,11 +4333,11 @@ function registerUserRoutes(app2) {
4595
4333
  }
4596
4334
 
4597
4335
  // src/controllers/tenants.ts
4598
- var import_core22 = require("@axiom-lattice/core");
4599
- var import_uuid5 = require("uuid");
4336
+ var import_core23 = require("@axiom-lattice/core");
4337
+ var import_uuid4 = require("uuid");
4600
4338
  var TenantsController = class {
4601
4339
  constructor() {
4602
- this.tenantStore = (0, import_core22.getStoreLattice)("default", "tenant").store;
4340
+ this.tenantStore = (0, import_core23.getStoreLattice)("default", "tenant").store;
4603
4341
  }
4604
4342
  // ==================== Tenant CRUD ====================
4605
4343
  async listTenants(request, reply) {
@@ -4608,7 +4346,7 @@ var TenantsController = class {
4608
4346
  }
4609
4347
  async createTenant(request, reply) {
4610
4348
  const data = request.body;
4611
- const id = (0, import_uuid5.v4)();
4349
+ const id = (0, import_uuid4.v4)();
4612
4350
  const tenant = await this.tenantStore.createTenant(id, data);
4613
4351
  return reply.status(201).send({ success: true, data: tenant });
4614
4352
  }
@@ -4663,8 +4401,8 @@ function registerTenantRoutes(app2) {
4663
4401
  }
4664
4402
 
4665
4403
  // src/controllers/auth.ts
4666
- var import_core23 = require("@axiom-lattice/core");
4667
- var import_uuid6 = require("uuid");
4404
+ var import_core24 = require("@axiom-lattice/core");
4405
+ var import_uuid5 = require("uuid");
4668
4406
  var defaultAuthConfig = {
4669
4407
  autoApproveUsers: true,
4670
4408
  allowTenantRegistration: true,
@@ -4672,9 +4410,9 @@ var defaultAuthConfig = {
4672
4410
  };
4673
4411
  var AuthController = class {
4674
4412
  constructor(config = {}) {
4675
- this.userStore = (0, import_core23.getStoreLattice)("default", "user").store;
4676
- this.tenantStore = (0, import_core23.getStoreLattice)("default", "tenant").store;
4677
- this.userTenantLinkStore = (0, import_core23.getStoreLattice)("default", "userTenantLink").store;
4413
+ this.userStore = (0, import_core24.getStoreLattice)("default", "user").store;
4414
+ this.tenantStore = (0, import_core24.getStoreLattice)("default", "tenant").store;
4415
+ this.userTenantLinkStore = (0, import_core24.getStoreLattice)("default", "userTenantLink").store;
4678
4416
  this.config = { ...defaultAuthConfig, ...config };
4679
4417
  }
4680
4418
  async register(request, reply) {
@@ -4687,7 +4425,7 @@ var AuthController = class {
4687
4425
  error: "User with this email already exists"
4688
4426
  });
4689
4427
  }
4690
- const userId = (0, import_uuid6.v4)();
4428
+ const userId = (0, import_uuid5.v4)();
4691
4429
  const userStatus = this.config.autoApproveUsers ? "active" : "pending";
4692
4430
  const userData = {
4693
4431
  email,
@@ -5188,7 +4926,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
5188
4926
  };
5189
4927
 
5190
4928
  // src/services/agent_task_consumer.ts
5191
- var import_core24 = require("@axiom-lattice/core");
4929
+ var import_core25 = require("@axiom-lattice/core");
5192
4930
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
5193
4931
  const {
5194
4932
  assistant_id,
@@ -5205,82 +4943,18 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
5205
4943
  );
5206
4944
  const apiUrl = AgentTaskConsumer.agent_run_endpoint;
5207
4945
  console.log(`apiUrl: ${apiUrl}`);
5208
- const response = await fetch(apiUrl, {
5209
- method: "POST",
5210
- body: JSON.stringify({
5211
- assistant_id,
5212
- streaming: true,
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, {
4946
+ const agent = import_core25.agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
4947
+ await agent.addMessage({ input, command }, import_core25.QueueMode.STEER);
4948
+ if (callback_event) {
4949
+ agent.subscribeOnce("message:completed", (evt) => {
4950
+ import_core25.eventBus.publish(callback_event, {
5274
4951
  success: true,
5275
- state,
4952
+ state: evt.state,
5276
4953
  config: { assistant_id, thread_id, tenant_id }
5277
4954
  });
5278
- }
5279
- console.log(
5280
- `\u4EFB\u52A1\u5904\u7406\u6210\u529F [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
5281
- );
5282
- return true;
4955
+ });
5283
4956
  }
4957
+ return true;
5284
4958
  } catch (error) {
5285
4959
  console.error(
5286
4960
  `Agent\u4EFB\u52A1\u6267\u884C\u5931\u8D25: ${assistant_id}, \u7EBF\u7A0B: ${thread_id}`,
@@ -5297,7 +4971,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
5297
4971
  return handleAgentTask(taskRequest, nextRetryCount);
5298
4972
  }
5299
4973
  if (callback_event) {
5300
- import_core24.eventBus.publish(callback_event, {
4974
+ import_core25.eventBus.publish(callback_event, {
5301
4975
  success: false,
5302
4976
  error: error instanceof Error ? error.message : String(error),
5303
4977
  config: { assistant_id, thread_id, tenant_id }
@@ -5335,7 +5009,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
5335
5009
  * 初始化事件监听和队列轮询
5336
5010
  */
5337
5011
  initialize() {
5338
- import_core24.eventBus.subscribe(import_core24.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
5012
+ import_core25.eventBus.subscribe(import_core25.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
5339
5013
  this.startPollingQueue();
5340
5014
  console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
5341
5015
  }
@@ -5454,7 +5128,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
5454
5128
  handleAgentTask(taskRequest).catch((error) => {
5455
5129
  console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
5456
5130
  if (taskRequest.callback_event) {
5457
- import_core24.eventBus.publish(taskRequest.callback_event, {
5131
+ import_core25.eventBus.publish(taskRequest.callback_event, {
5458
5132
  success: false,
5459
5133
  error: error instanceof Error ? error.message : String(error),
5460
5134
  config: {
@@ -5474,7 +5148,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
5474
5148
  var AgentTaskConsumer = _AgentTaskConsumer;
5475
5149
 
5476
5150
  // src/index.ts
5477
- var import_core25 = require("@axiom-lattice/core");
5151
+ var import_core26 = require("@axiom-lattice/core");
5478
5152
  var import_protocols2 = require("@axiom-lattice/protocols");
5479
5153
  process.on("unhandledRejection", (reason, promise) => {
5480
5154
  console.error("\u672A\u5904\u7406\u7684Promise\u62D2\u7EDD:", reason);
@@ -5489,11 +5163,11 @@ var DEFAULT_LOGGER_CONFIG = {
5489
5163
  var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
5490
5164
  var logger = loggerLattice.client;
5491
5165
  function initializeLogger(config) {
5492
- if (import_core25.loggerLatticeManager.hasLattice("default")) {
5493
- import_core25.loggerLatticeManager.removeLattice("default");
5166
+ if (import_core26.loggerLatticeManager.hasLattice("default")) {
5167
+ import_core26.loggerLatticeManager.removeLattice("default");
5494
5168
  }
5495
- (0, import_core25.registerLoggerLattice)("default", config);
5496
- return (0, import_core25.getLoggerLattice)("default");
5169
+ (0, import_core26.registerLoggerLattice)("default", config);
5170
+ return (0, import_core26.getLoggerLattice)("default");
5497
5171
  }
5498
5172
  var app = (0, import_fastify.default)({
5499
5173
  logger: false,
@@ -5533,7 +5207,6 @@ app.addHook("onResponse", (request, reply, done) => {
5533
5207
  "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
5534
5208
  "x-request-id": getHeaderValue(request.headers["x-request-id"])
5535
5209
  };
5536
- loggerLattice.info(`${request.method} ${request.url} - ${reply.statusCode}`);
5537
5210
  done();
5538
5211
  });
5539
5212
  app.register(import_cors.default, {
@@ -5594,16 +5267,16 @@ var start = async (config) => {
5594
5267
  app.decorate("loggerLattice", loggerLattice);
5595
5268
  registerLatticeRoutes(app);
5596
5269
  try {
5597
- const storeLattice = (0, import_core25.getStoreLattice)("default", "database");
5270
+ const storeLattice = (0, import_core26.getStoreLattice)("default", "database");
5598
5271
  const store = storeLattice.store;
5599
- import_core25.sqlDatabaseManager.setConfigStore(store);
5272
+ import_core26.sqlDatabaseManager.setConfigStore(store);
5600
5273
  logger.info("Database config store set for SqlDatabaseManager");
5601
5274
  } catch (error) {
5602
5275
  logger.warn("Failed to set database config store: " + (error instanceof Error ? error.message : String(error)));
5603
5276
  }
5604
- if (!import_core25.sandboxLatticeManager.hasLattice("default")) {
5277
+ if (!import_core26.sandboxLatticeManager.hasLattice("default")) {
5605
5278
  const sandboxBaseURL = process.env.SANDBOX_BASE_URL || "http://localhost:8080";
5606
- import_core25.sandboxLatticeManager.registerLattice("default", {
5279
+ import_core26.sandboxLatticeManager.registerLattice("default", {
5607
5280
  baseURL: sandboxBaseURL
5608
5281
  });
5609
5282
  logger.info(`Registered sandbox manager with baseURL: ${sandboxBaseURL}`);
@@ -5611,6 +5284,11 @@ var start = async (config) => {
5611
5284
  const target_port = config?.port || Number(process.env.PORT) || 4001;
5612
5285
  await app.listen({ port: target_port, host: "0.0.0.0" });
5613
5286
  logger.info(`Lattice Gateway is running on port: ${target_port}`);
5287
+ try {
5288
+ logger.info("AgentLifecycleManager initialized");
5289
+ } catch (error) {
5290
+ logger.warn("Failed to initialize AgentLifecycleManager", { error });
5291
+ }
5614
5292
  const queueServiceConfig = config?.queueServiceConfig;
5615
5293
  if (queueServiceConfig) {
5616
5294
  setQueueServiceType(queueServiceConfig.type);