@axiom-lattice/gateway 2.1.92 → 2.1.93

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.mjs CHANGED
@@ -19,6 +19,11 @@ function getTenantId(request) {
19
19
  }
20
20
  return request.headers["x-tenant-id"] || "default";
21
21
  }
22
+ function getUserId(request) {
23
+ const userId = request.user?.id;
24
+ if (userId) return userId;
25
+ return request.headers["x-user-id"] || void 0;
26
+ }
22
27
  function convertAgentConfigToAssistant(config) {
23
28
  return {
24
29
  id: config.key,
@@ -51,12 +56,17 @@ async function getAssistantList(request, reply) {
51
56
  assistantMap.set(assistant.id, assistant);
52
57
  });
53
58
  const allAssistants = Array.from(assistantMap.values());
59
+ const userId = getUserId(request);
60
+ const filtered = allAssistants.filter((a) => {
61
+ if (!a.ownerUserId) return true;
62
+ return a.ownerUserId === userId;
63
+ });
54
64
  return {
55
65
  success: true,
56
66
  message: "Successfully retrieved assistant list",
57
67
  data: {
58
- records: allAssistants,
59
- total: allAssistants.length
68
+ records: filtered,
69
+ total: filtered.length
60
70
  }
61
71
  };
62
72
  }
@@ -204,7 +214,7 @@ import {
204
214
  agentInstanceManager as agentInstanceManager2
205
215
  } from "@axiom-lattice/core";
206
216
  import { MessageChunkTypes } from "@axiom-lattice/protocols";
207
- function getUserId(request) {
217
+ function getUserId2(request) {
208
218
  const authUser = request.user;
209
219
  if (authUser?.id) return authUser.id;
210
220
  return request.headers["x-user-id"] || void 0;
@@ -226,7 +236,7 @@ var createRun = async (request, reply) => {
226
236
  const workspace_id = request.headers["x-workspace-id"];
227
237
  const project_id = request.headers["x-project-id"];
228
238
  const x_request_id = request.headers["x-request-id"] || v4();
229
- const user_id = getUserId(request);
239
+ const user_id = getUserId2(request);
230
240
  const mergedConfig = user_id ? { ...custom_run_config, user_id } : custom_run_config;
231
241
  if (!assistant_id) {
232
242
  reply.status(400).send({
@@ -380,6 +390,33 @@ var abortRun = async (request, reply) => {
380
390
  });
381
391
  }
382
392
  };
393
+ var recoverRun = async (request, reply) => {
394
+ try {
395
+ const { assistantId, threadId } = request.params;
396
+ const tenant_id = request.headers["x-tenant-id"];
397
+ const workspace_id = request.headers["x-workspace-id"] || "default";
398
+ const project_id = request.headers["x-project-id"] || "default";
399
+ const agent = agentInstanceManager2.getAgent({
400
+ assistant_id: assistantId,
401
+ thread_id: threadId,
402
+ tenant_id,
403
+ workspace_id,
404
+ project_id
405
+ });
406
+ await agent.resumeTask();
407
+ const status = await agent.getRunStatus();
408
+ reply.status(200).send({
409
+ success: true,
410
+ threadId,
411
+ status
412
+ });
413
+ } catch (error) {
414
+ reply.status(500).send({
415
+ success: false,
416
+ error: `Recover failed: ${error.message}`
417
+ });
418
+ }
419
+ };
383
420
 
384
421
  // src/controllers/memory.ts
385
422
  import { agentInstanceManager as agentInstanceManager3 } from "@axiom-lattice/core";
@@ -552,6 +589,8 @@ var triggerAgentTask = async (request, reply) => {
552
589
  try {
553
590
  const { assistant_id, thread_id, input, command } = request.body;
554
591
  const tenant_id = request.headers["x-tenant-id"];
592
+ const workspace_id = request.headers["x-workspace-id"];
593
+ const project_id = request.headers["x-project-id"];
555
594
  if (!assistant_id) {
556
595
  reply.status(400).send({
557
596
  success: false,
@@ -572,7 +611,12 @@ var triggerAgentTask = async (request, reply) => {
572
611
  thread_id,
573
612
  input,
574
613
  command,
575
- "x-tenant-id": tenant_id
614
+ "x-tenant-id": tenant_id,
615
+ runConfig: {
616
+ workspaceId: workspace_id,
617
+ projectId: project_id,
618
+ user_id: request.user?.id
619
+ }
576
620
  });
577
621
  reply.status(200).send({
578
622
  success: true
@@ -2167,6 +2211,268 @@ async function replyInboxTask(request, reply) {
2167
2211
  }
2168
2212
  }
2169
2213
 
2214
+ // src/controllers/personal-assistant.ts
2215
+ import { getStoreLattice as getStoreLattice5, PersonalAssistantConfig } from "@axiom-lattice/core";
2216
+ import { randomUUID as randomUUID3 } from "crypto";
2217
+ function getWorkspaceId2(request) {
2218
+ return request.headers["x-workspace-id"] || "default";
2219
+ }
2220
+ function getTenantId7(request) {
2221
+ const userTenantId = request.user?.tenantId;
2222
+ if (userTenantId) return userTenantId;
2223
+ return request.headers["x-tenant-id"] || "default";
2224
+ }
2225
+ function getUserId3(request) {
2226
+ const userId = request.user?.id || request.headers["x-user-id"];
2227
+ if (!userId) throw new Error("User ID is required");
2228
+ return userId;
2229
+ }
2230
+ function getLinkStore() {
2231
+ return getStoreLattice5("default", "userTenantLink").store;
2232
+ }
2233
+ function getAssistantStore() {
2234
+ return getStoreLattice5("default", "assistant").store;
2235
+ }
2236
+ function getProjectStore() {
2237
+ return getStoreLattice5("default", "project").store;
2238
+ }
2239
+ async function getLinkMeta(userId, tenantId) {
2240
+ const link = await getLinkStore().getLink(userId, tenantId);
2241
+ return link?.metadata || {};
2242
+ }
2243
+ async function updateLinkMeta(userId, tenantId, meta) {
2244
+ await getLinkStore().updateLink(userId, tenantId, { metadata: meta });
2245
+ }
2246
+ async function createPersonalAssistant(request, reply) {
2247
+ const tenantId = getTenantId7(request);
2248
+ const userId = getUserId3(request);
2249
+ const { name, personality } = request.body;
2250
+ if (!name || !personality) {
2251
+ return reply.status(400).send({ success: false, message: "name and personality are required" });
2252
+ }
2253
+ const store = getAssistantStore();
2254
+ const existing = await store.getByOwner(tenantId, userId);
2255
+ if (existing) {
2256
+ return reply.status(409).send({ success: false, message: "You already have a personal assistant" });
2257
+ }
2258
+ const assistantId = randomUUID3();
2259
+ const projectStore = getProjectStore();
2260
+ const projectId = randomUUID3();
2261
+ const wsId = getWorkspaceId2(request);
2262
+ await projectStore.createProject(tenantId, wsId, projectId, {
2263
+ name: `${name}'s Space`,
2264
+ description: "Personal workspace for your assistant"
2265
+ });
2266
+ const config = PersonalAssistantConfig.get();
2267
+ config.key = assistantId;
2268
+ PersonalAssistantConfig.render(config, name, personality);
2269
+ const data = { name, graphDefinition: config, ownerUserId: userId };
2270
+ const assistant = await store.createAssistant(tenantId, assistantId, data);
2271
+ const meta = await getLinkMeta(userId, tenantId);
2272
+ meta.personalAssistantId = assistantId;
2273
+ meta.personalProjectId = projectId;
2274
+ meta.personalWorkspaceId = wsId;
2275
+ await updateLinkMeta(userId, tenantId, meta);
2276
+ return reply.status(201).send({
2277
+ success: true,
2278
+ message: "Personal assistant created",
2279
+ data: { id: assistant.id, name: assistant.name, projectId, workspaceId: wsId, createdAt: assistant.createdAt }
2280
+ });
2281
+ }
2282
+ async function getPersonalAssistant(request, reply) {
2283
+ const tenantId = getTenantId7(request);
2284
+ const userId = getUserId3(request);
2285
+ const store = getAssistantStore();
2286
+ const assistant = await store.getByOwner(tenantId, userId);
2287
+ if (!assistant) {
2288
+ return reply.status(404).send({ success: false, message: "No personal assistant found" });
2289
+ }
2290
+ const meta = await getLinkMeta(userId, tenantId);
2291
+ const projectId = meta.personalProjectId || "default";
2292
+ const workspaceId = meta.personalWorkspaceId || "default";
2293
+ return {
2294
+ success: true,
2295
+ message: "Personal assistant found",
2296
+ data: { id: assistant.id, name: assistant.name, projectId, workspaceId, createdAt: assistant.createdAt }
2297
+ };
2298
+ }
2299
+ async function deletePersonalAssistant(request, reply) {
2300
+ const tenantId = getTenantId7(request);
2301
+ const userId = getUserId3(request);
2302
+ const store = getAssistantStore();
2303
+ const assistant = await store.getByOwner(tenantId, userId);
2304
+ if (!assistant) {
2305
+ return reply.status(404).send({ success: false, message: "No personal assistant found" });
2306
+ }
2307
+ const deleted = await store.deleteAssistant(tenantId, assistant.id);
2308
+ if (!deleted) {
2309
+ return reply.status(500).send({ success: false, message: "Failed to delete personal assistant" });
2310
+ }
2311
+ const threadStore = getStoreLattice5("default", "thread").store;
2312
+ try {
2313
+ const threads = await threadStore.getThreadsByAssistantId(tenantId, assistant.id);
2314
+ for (const t of threads) {
2315
+ await threadStore.deleteThread(tenantId, t.id);
2316
+ }
2317
+ } catch {
2318
+ }
2319
+ const meta = await getLinkMeta(userId, tenantId);
2320
+ const projectId = meta.personalProjectId;
2321
+ const wsId = meta.personalWorkspaceId;
2322
+ if (projectId && wsId) {
2323
+ try {
2324
+ await getProjectStore().deleteProject(tenantId, projectId);
2325
+ } catch {
2326
+ }
2327
+ }
2328
+ delete meta.personalAssistantId;
2329
+ delete meta.personalProjectId;
2330
+ delete meta.personalWorkspaceId;
2331
+ await updateLinkMeta(userId, tenantId, meta);
2332
+ return { success: true, message: "Personal assistant deleted" };
2333
+ }
2334
+
2335
+ // src/controllers/tasks.ts
2336
+ import { getStoreLattice as getStoreLattice6 } from "@axiom-lattice/core";
2337
+ function getTenantId8(request) {
2338
+ const userTenantId = request.user?.tenantId;
2339
+ if (userTenantId) return userTenantId;
2340
+ return request.headers["x-tenant-id"] || "default";
2341
+ }
2342
+ function getUserId4(request) {
2343
+ const userId = request.user?.id || request.headers["x-user-id"];
2344
+ if (!userId) throw new Error("User ID is required");
2345
+ return userId;
2346
+ }
2347
+ function getStore() {
2348
+ return getStoreLattice6("default", "task").store;
2349
+ }
2350
+ async function listTasks(request, reply) {
2351
+ try {
2352
+ const tenantId = getTenantId8(request);
2353
+ const userId = getUserId4(request);
2354
+ const query = request.query;
2355
+ const store = getStore();
2356
+ const tasks = await store.list({
2357
+ tenantId,
2358
+ ownerId: query.ownerId || userId,
2359
+ status: query.status,
2360
+ priority: query.priority,
2361
+ ownerType: query.ownerType,
2362
+ metadata: query.metadata ? JSON.parse(query.metadata) : void 0,
2363
+ limit: query.limit ? parseInt(query.limit) : void 0,
2364
+ offset: query.offset ? parseInt(query.offset) : void 0
2365
+ });
2366
+ return { success: true, data: tasks, count: tasks.length };
2367
+ } catch (error) {
2368
+ return { success: false, error: error.message };
2369
+ }
2370
+ }
2371
+ async function getTask(request, reply) {
2372
+ try {
2373
+ const tenantId = getTenantId8(request);
2374
+ const userId = getUserId4(request);
2375
+ const { id } = request.params;
2376
+ const store = getStore();
2377
+ const task = await store.getById(tenantId, id);
2378
+ if (!task) {
2379
+ return reply.status(404).send({ success: false, error: "Task not found" });
2380
+ }
2381
+ if (task.ownerType === "user" && task.ownerId !== userId) {
2382
+ return reply.status(403).send({ success: false, error: "Access denied" });
2383
+ }
2384
+ return { success: true, data: task };
2385
+ } catch (error) {
2386
+ return { success: false, error: error.message };
2387
+ }
2388
+ }
2389
+ async function createTask(request, reply) {
2390
+ try {
2391
+ const tenantId = getTenantId8(request);
2392
+ const userId = getUserId4(request);
2393
+ const body = request.body;
2394
+ if (!body.title) {
2395
+ return reply.status(400).send({ success: false, error: "title is required" });
2396
+ }
2397
+ const store = getStore();
2398
+ const task = await store.create({
2399
+ ...body,
2400
+ tenantId,
2401
+ ownerType: body.ownerType || "user",
2402
+ ownerId: body.ownerId || userId
2403
+ });
2404
+ return reply.status(201).send({ success: true, data: task });
2405
+ } catch (error) {
2406
+ return reply.status(500).send({ success: false, error: error.message });
2407
+ }
2408
+ }
2409
+ async function updateTask(request, reply) {
2410
+ try {
2411
+ const tenantId = getTenantId8(request);
2412
+ const userId = getUserId4(request);
2413
+ const { id } = request.params;
2414
+ const store = getStore();
2415
+ const existing = await store.getById(tenantId, id);
2416
+ if (!existing) {
2417
+ return reply.status(404).send({ success: false, error: "Task not found" });
2418
+ }
2419
+ if (existing.ownerType === "user" && existing.ownerId !== userId) {
2420
+ return reply.status(403).send({ success: false, error: "Access denied" });
2421
+ }
2422
+ const task = await store.update(tenantId, id, request.body);
2423
+ if (!task) {
2424
+ return reply.status(404).send({ success: false, error: "Task not found" });
2425
+ }
2426
+ return { success: true, data: task };
2427
+ } catch (error) {
2428
+ return reply.status(500).send({ success: false, error: error.message });
2429
+ }
2430
+ }
2431
+ async function deleteTask(request, reply) {
2432
+ try {
2433
+ const tenantId = getTenantId8(request);
2434
+ const userId = getUserId4(request);
2435
+ const { id } = request.params;
2436
+ const store = getStore();
2437
+ const existing = await store.getById(tenantId, id);
2438
+ if (!existing) {
2439
+ return reply.status(404).send({ success: false, error: "Task not found" });
2440
+ }
2441
+ if (existing.ownerType === "user" && existing.ownerId !== userId) {
2442
+ return reply.status(403).send({ success: false, error: "Access denied" });
2443
+ }
2444
+ const deleted = await store.delete(tenantId, id);
2445
+ if (!deleted) {
2446
+ return reply.status(404).send({ success: false, error: "Task not found" });
2447
+ }
2448
+ return { success: true, message: "Task deleted" };
2449
+ } catch (error) {
2450
+ return reply.status(500).send({ success: false, error: error.message });
2451
+ }
2452
+ }
2453
+ async function completeTask(request, reply) {
2454
+ try {
2455
+ const tenantId = getTenantId8(request);
2456
+ const userId = getUserId4(request);
2457
+ const { id } = request.params;
2458
+ const store = getStore();
2459
+ const existing = await store.getById(tenantId, id);
2460
+ if (!existing) {
2461
+ return reply.status(404).send({ success: false, error: "Task not found" });
2462
+ }
2463
+ if (existing.ownerType === "user" && existing.ownerId !== userId) {
2464
+ return reply.status(403).send({ success: false, error: "Access denied" });
2465
+ }
2466
+ const task = await store.update(tenantId, id, { status: "completed" });
2467
+ if (!task) {
2468
+ return reply.status(404).send({ success: false, error: "Task not found" });
2469
+ }
2470
+ return { success: true, data: task };
2471
+ } catch (error) {
2472
+ return reply.status(500).send({ success: false, error: error.message });
2473
+ }
2474
+ }
2475
+
2170
2476
  // src/schemas/data-query.ts
2171
2477
  var dataQuerySchema = {
2172
2478
  description: "Execute data query (semantic or SQL)",
@@ -2731,9 +3037,9 @@ var SandboxService = class {
2731
3037
  );
2732
3038
  return rewritten;
2733
3039
  }
2734
- generateErrorHtml(assistantId, threadId, vmIsolation, errorMessage) {
2735
- const encodedError = encodeURIComponent(errorMessage);
2736
- return ERROR_HTML.replace("{assistantId}", assistantId).replace("{threadId}", threadId).replace("{vmIsolation}", vmIsolation).replace("{errorMessage}", errorMessage);
3040
+ generateErrorHtml(assistantId, threadId, vmIsolation, errorMessage2) {
3041
+ const encodedError = encodeURIComponent(errorMessage2);
3042
+ return ERROR_HTML.replace("{assistantId}", assistantId).replace("{threadId}", threadId).replace("{vmIsolation}", vmIsolation).replace("{errorMessage}", errorMessage2);
2737
3043
  }
2738
3044
  };
2739
3045
  var sandboxService = new SandboxService();
@@ -2859,14 +3165,14 @@ function registerSandboxProxyRoutes(app2) {
2859
3165
  // src/controllers/workspace.ts
2860
3166
  import * as fs from "fs/promises";
2861
3167
  import * as path from "path";
2862
- import { getStoreLattice as getStoreLattice5 } from "@axiom-lattice/core";
3168
+ import { getStoreLattice as getStoreLattice7 } from "@axiom-lattice/core";
2863
3169
  import { SandboxFilesystem, FilesystemBackend } from "@axiom-lattice/core";
2864
3170
  import { getSandBoxManager as getSandBoxManager3 } from "@axiom-lattice/core";
2865
3171
  import { v4 as uuidv4 } from "uuid";
2866
3172
  var WorkspaceController = class {
2867
3173
  constructor() {
2868
- this.workspaceStore = getStoreLattice5("default", "workspace").store;
2869
- this.projectStore = getStoreLattice5("default", "project").store;
3174
+ this.workspaceStore = getStoreLattice7("default", "workspace").store;
3175
+ this.projectStore = getStoreLattice7("default", "project").store;
2870
3176
  }
2871
3177
  getTenantId(request) {
2872
3178
  const userTenantId = request.user?.tenantId;
@@ -3391,11 +3697,11 @@ function registerWorkspaceRoutes(app2) {
3391
3697
 
3392
3698
  // src/controllers/database-configs.ts
3393
3699
  import {
3394
- getStoreLattice as getStoreLattice6,
3700
+ getStoreLattice as getStoreLattice8,
3395
3701
  sqlDatabaseManager
3396
3702
  } from "@axiom-lattice/core";
3397
- import { randomUUID as randomUUID3 } from "crypto";
3398
- function getTenantId7(request) {
3703
+ import { randomUUID as randomUUID4 } from "crypto";
3704
+ function getTenantId9(request) {
3399
3705
  const userTenantId = request.user?.tenantId;
3400
3706
  if (userTenantId) {
3401
3707
  return userTenantId;
@@ -3403,9 +3709,9 @@ function getTenantId7(request) {
3403
3709
  return request.headers["x-tenant-id"] || "default";
3404
3710
  }
3405
3711
  async function getDatabaseConfigList(request, reply) {
3406
- const tenantId = getTenantId7(request);
3712
+ const tenantId = getTenantId9(request);
3407
3713
  try {
3408
- const storeLattice = getStoreLattice6("default", "database");
3714
+ const storeLattice = getStoreLattice8("default", "database");
3409
3715
  const store = storeLattice.store;
3410
3716
  const configs = await store.getAllConfigs(tenantId);
3411
3717
  console.log("Backend: getAllConfigs returned:", configs);
@@ -3433,10 +3739,10 @@ async function getDatabaseConfigList(request, reply) {
3433
3739
  }
3434
3740
  }
3435
3741
  async function getDatabaseConfig(request, reply) {
3436
- const tenantId = getTenantId7(request);
3742
+ const tenantId = getTenantId9(request);
3437
3743
  const { key } = request.params;
3438
3744
  try {
3439
- const storeLattice = getStoreLattice6("default", "database");
3745
+ const storeLattice = getStoreLattice8("default", "database");
3440
3746
  const store = storeLattice.store;
3441
3747
  const config = await store.getConfigByKey(tenantId, key);
3442
3748
  if (!config) {
@@ -3459,10 +3765,10 @@ async function getDatabaseConfig(request, reply) {
3459
3765
  }
3460
3766
  }
3461
3767
  async function createDatabaseConfig(request, reply) {
3462
- const tenantId = getTenantId7(request);
3768
+ const tenantId = getTenantId9(request);
3463
3769
  const body = request.body;
3464
3770
  try {
3465
- const storeLattice = getStoreLattice6("default", "database");
3771
+ const storeLattice = getStoreLattice8("default", "database");
3466
3772
  const store = storeLattice.store;
3467
3773
  const existing = await store.getConfigByKey(tenantId, body.key);
3468
3774
  if (existing) {
@@ -3472,7 +3778,7 @@ async function createDatabaseConfig(request, reply) {
3472
3778
  message: "Database configuration with this key already exists"
3473
3779
  };
3474
3780
  }
3475
- const id = body.id || randomUUID3();
3781
+ const id = body.id || randomUUID4();
3476
3782
  const config = await store.createConfig(tenantId, id, body);
3477
3783
  try {
3478
3784
  sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
@@ -3494,11 +3800,11 @@ async function createDatabaseConfig(request, reply) {
3494
3800
  }
3495
3801
  }
3496
3802
  async function updateDatabaseConfig(request, reply) {
3497
- const tenantId = getTenantId7(request);
3803
+ const tenantId = getTenantId9(request);
3498
3804
  const { key } = request.params;
3499
3805
  const updates = request.body;
3500
3806
  try {
3501
- const storeLattice = getStoreLattice6("default", "database");
3807
+ const storeLattice = getStoreLattice8("default", "database");
3502
3808
  const store = storeLattice.store;
3503
3809
  const existing = await store.getConfigByKey(tenantId, key);
3504
3810
  if (!existing) {
@@ -3536,10 +3842,10 @@ async function updateDatabaseConfig(request, reply) {
3536
3842
  }
3537
3843
  }
3538
3844
  async function deleteDatabaseConfig(request, reply) {
3539
- const tenantId = getTenantId7(request);
3845
+ const tenantId = getTenantId9(request);
3540
3846
  const { keyOrId } = request.params;
3541
3847
  try {
3542
- const storeLattice = getStoreLattice6("default", "database");
3848
+ const storeLattice = getStoreLattice8("default", "database");
3543
3849
  const store = storeLattice.store;
3544
3850
  console.log("Delete request - keyOrId:", keyOrId);
3545
3851
  let config = await store.getConfigByKey(tenantId, keyOrId);
@@ -3585,10 +3891,10 @@ async function deleteDatabaseConfig(request, reply) {
3585
3891
  }
3586
3892
  }
3587
3893
  async function testDatabaseConnection(request, reply) {
3588
- const tenantId = getTenantId7(request);
3894
+ const tenantId = getTenantId9(request);
3589
3895
  const { key } = request.params;
3590
3896
  try {
3591
- const storeLattice = getStoreLattice6("default", "database");
3897
+ const storeLattice = getStoreLattice8("default", "database");
3592
3898
  const store = storeLattice.store;
3593
3899
  const config = await store.getConfigByKey(tenantId, key);
3594
3900
  if (!config) {
@@ -3673,12 +3979,12 @@ function registerDatabaseConfigRoutes(app2) {
3673
3979
 
3674
3980
  // src/controllers/metrics-configs.ts
3675
3981
  import {
3676
- getStoreLattice as getStoreLattice7,
3982
+ getStoreLattice as getStoreLattice9,
3677
3983
  metricsServerManager as metricsServerManager2,
3678
3984
  SemanticMetricsClient as SemanticMetricsClient2
3679
3985
  } from "@axiom-lattice/core";
3680
- import { randomUUID as randomUUID4 } from "crypto";
3681
- function getTenantId8(request) {
3986
+ import { randomUUID as randomUUID5 } from "crypto";
3987
+ function getTenantId10(request) {
3682
3988
  const userTenantId = request.user?.tenantId;
3683
3989
  if (userTenantId) {
3684
3990
  return userTenantId;
@@ -3686,9 +3992,9 @@ function getTenantId8(request) {
3686
3992
  return request.headers["x-tenant-id"] || "default";
3687
3993
  }
3688
3994
  async function getMetricsServerConfigList(request, reply) {
3689
- const tenantId = getTenantId8(request);
3995
+ const tenantId = getTenantId10(request);
3690
3996
  try {
3691
- const storeLattice = getStoreLattice7("default", "metrics");
3997
+ const storeLattice = getStoreLattice9("default", "metrics");
3692
3998
  const store = storeLattice.store;
3693
3999
  const configs = await store.getAllConfigs(tenantId);
3694
4000
  return {
@@ -3712,10 +4018,10 @@ async function getMetricsServerConfigList(request, reply) {
3712
4018
  }
3713
4019
  }
3714
4020
  async function getMetricsServerConfig(request, reply) {
3715
- const tenantId = getTenantId8(request);
4021
+ const tenantId = getTenantId10(request);
3716
4022
  const { key } = request.params;
3717
4023
  try {
3718
- const storeLattice = getStoreLattice7("default", "metrics");
4024
+ const storeLattice = getStoreLattice9("default", "metrics");
3719
4025
  const store = storeLattice.store;
3720
4026
  const config = await store.getConfigByKey(tenantId, key);
3721
4027
  if (!config) {
@@ -3738,10 +4044,10 @@ async function getMetricsServerConfig(request, reply) {
3738
4044
  }
3739
4045
  }
3740
4046
  async function createMetricsServerConfig(request, reply) {
3741
- const tenantId = getTenantId8(request);
4047
+ const tenantId = getTenantId10(request);
3742
4048
  const body = request.body;
3743
4049
  try {
3744
- const storeLattice = getStoreLattice7("default", "metrics");
4050
+ const storeLattice = getStoreLattice9("default", "metrics");
3745
4051
  const store = storeLattice.store;
3746
4052
  const existing = await store.getConfigByKey(tenantId, body.key);
3747
4053
  if (existing) {
@@ -3758,7 +4064,7 @@ async function createMetricsServerConfig(request, reply) {
3758
4064
  message: "selectedDataSources is required for semantic metrics servers"
3759
4065
  };
3760
4066
  }
3761
- const id = body.id || randomUUID4();
4067
+ const id = body.id || randomUUID5();
3762
4068
  const configData = {
3763
4069
  key: body.key,
3764
4070
  name: body.name,
@@ -3789,11 +4095,11 @@ async function createMetricsServerConfig(request, reply) {
3789
4095
  }
3790
4096
  }
3791
4097
  async function updateMetricsServerConfig(request, reply) {
3792
- const tenantId = getTenantId8(request);
4098
+ const tenantId = getTenantId10(request);
3793
4099
  const { key } = request.params;
3794
4100
  const updates = request.body;
3795
4101
  try {
3796
- const storeLattice = getStoreLattice7("default", "metrics");
4102
+ const storeLattice = getStoreLattice9("default", "metrics");
3797
4103
  const store = storeLattice.store;
3798
4104
  const existing = await store.getConfigByKey(tenantId, key);
3799
4105
  if (!existing) {
@@ -3840,10 +4146,10 @@ async function updateMetricsServerConfig(request, reply) {
3840
4146
  }
3841
4147
  }
3842
4148
  async function deleteMetricsServerConfig(request, reply) {
3843
- const tenantId = getTenantId8(request);
4149
+ const tenantId = getTenantId10(request);
3844
4150
  const { keyOrId } = request.params;
3845
4151
  try {
3846
- const storeLattice = getStoreLattice7("default", "metrics");
4152
+ const storeLattice = getStoreLattice9("default", "metrics");
3847
4153
  const store = storeLattice.store;
3848
4154
  let config = await store.getConfigByKey(tenantId, keyOrId);
3849
4155
  let configKey = keyOrId;
@@ -3887,10 +4193,10 @@ async function deleteMetricsServerConfig(request, reply) {
3887
4193
  }
3888
4194
  }
3889
4195
  async function testMetricsServerConnection(request, reply) {
3890
- const tenantId = getTenantId8(request);
4196
+ const tenantId = getTenantId10(request);
3891
4197
  const { key } = request.params;
3892
4198
  try {
3893
- const storeLattice = getStoreLattice7("default", "metrics");
4199
+ const storeLattice = getStoreLattice9("default", "metrics");
3894
4200
  const store = storeLattice.store;
3895
4201
  const config = await store.getConfigByKey(tenantId, key);
3896
4202
  if (!config) {
@@ -3938,10 +4244,10 @@ async function testMetricsServerConnection(request, reply) {
3938
4244
  }
3939
4245
  }
3940
4246
  async function listAvailableMetrics(request, reply) {
3941
- const tenantId = getTenantId8(request);
4247
+ const tenantId = getTenantId10(request);
3942
4248
  const { key } = request.params;
3943
4249
  try {
3944
- const storeLattice = getStoreLattice7("default", "metrics");
4250
+ const storeLattice = getStoreLattice9("default", "metrics");
3945
4251
  const store = storeLattice.store;
3946
4252
  const config = await store.getConfigByKey(tenantId, key);
3947
4253
  if (!config) {
@@ -3976,11 +4282,11 @@ async function listAvailableMetrics(request, reply) {
3976
4282
  }
3977
4283
  }
3978
4284
  async function queryMetricsData(request, reply) {
3979
- const tenantId = getTenantId8(request);
4285
+ const tenantId = getTenantId10(request);
3980
4286
  const { key } = request.params;
3981
4287
  const { metricName, startTime, endTime, step, labels } = request.body;
3982
4288
  try {
3983
- const storeLattice = getStoreLattice7("default", "metrics");
4289
+ const storeLattice = getStoreLattice9("default", "metrics");
3984
4290
  const store = storeLattice.store;
3985
4291
  const config = await store.getConfigByKey(tenantId, key);
3986
4292
  if (!config) {
@@ -4024,10 +4330,10 @@ async function queryMetricsData(request, reply) {
4024
4330
  }
4025
4331
  }
4026
4332
  async function getDataSources(request, reply) {
4027
- const tenantId = getTenantId8(request);
4333
+ const tenantId = getTenantId10(request);
4028
4334
  const { key } = request.params;
4029
4335
  try {
4030
- const storeLattice = getStoreLattice7("default", "metrics");
4336
+ const storeLattice = getStoreLattice9("default", "metrics");
4031
4337
  const store = storeLattice.store;
4032
4338
  const config = await store.getConfigByKey(tenantId, key);
4033
4339
  if (!config) {
@@ -4065,10 +4371,10 @@ async function getDataSources(request, reply) {
4065
4371
  }
4066
4372
  }
4067
4373
  async function getDatasourceMetrics(request, reply) {
4068
- const tenantId = getTenantId8(request);
4374
+ const tenantId = getTenantId10(request);
4069
4375
  const { key, datasourceId } = request.params;
4070
4376
  try {
4071
- const storeLattice = getStoreLattice7("default", "metrics");
4377
+ const storeLattice = getStoreLattice9("default", "metrics");
4072
4378
  const store = storeLattice.store;
4073
4379
  const config = await store.getConfigByKey(tenantId, key);
4074
4380
  if (!config) {
@@ -4102,11 +4408,11 @@ async function getDatasourceMetrics(request, reply) {
4102
4408
  }
4103
4409
  }
4104
4410
  async function querySemanticMetrics(request, reply) {
4105
- const tenantId = getTenantId8(request);
4411
+ const tenantId = getTenantId10(request);
4106
4412
  const { key } = request.params;
4107
4413
  const body = request.body;
4108
4414
  try {
4109
- const storeLattice = getStoreLattice7("default", "metrics");
4415
+ const storeLattice = getStoreLattice9("default", "metrics");
4110
4416
  const store = storeLattice.store;
4111
4417
  const config = await store.getConfigByKey(tenantId, key);
4112
4418
  if (!config) {
@@ -4260,12 +4566,12 @@ function registerMetricsServerConfigRoutes(app2) {
4260
4566
 
4261
4567
  // src/controllers/mcp-configs.ts
4262
4568
  import {
4263
- getStoreLattice as getStoreLattice8,
4569
+ getStoreLattice as getStoreLattice10,
4264
4570
  mcpManager,
4265
4571
  toolLatticeManager as toolLatticeManager2
4266
4572
  } from "@axiom-lattice/core";
4267
- import { randomUUID as randomUUID5 } from "crypto";
4268
- function getTenantId9(request) {
4573
+ import { randomUUID as randomUUID6 } from "crypto";
4574
+ function getTenantId11(request) {
4269
4575
  const userTenantId = request.user?.tenantId;
4270
4576
  if (userTenantId) {
4271
4577
  return userTenantId;
@@ -4273,9 +4579,9 @@ function getTenantId9(request) {
4273
4579
  return request.headers["x-tenant-id"] || "default";
4274
4580
  }
4275
4581
  async function getMcpServerConfigList(request, reply) {
4276
- const tenantId = getTenantId9(request);
4582
+ const tenantId = getTenantId11(request);
4277
4583
  try {
4278
- const storeLattice = getStoreLattice8("default", "mcp");
4584
+ const storeLattice = getStoreLattice10("default", "mcp");
4279
4585
  const store = storeLattice.store;
4280
4586
  const configs = await store.getAllConfigs(tenantId);
4281
4587
  return {
@@ -4299,10 +4605,10 @@ async function getMcpServerConfigList(request, reply) {
4299
4605
  }
4300
4606
  }
4301
4607
  async function getMcpServerConfig(request, reply) {
4302
- const tenantId = getTenantId9(request);
4608
+ const tenantId = getTenantId11(request);
4303
4609
  const { key } = request.params;
4304
4610
  try {
4305
- const storeLattice = getStoreLattice8("default", "mcp");
4611
+ const storeLattice = getStoreLattice10("default", "mcp");
4306
4612
  const store = storeLattice.store;
4307
4613
  const config = await store.getConfigByKey(tenantId, key);
4308
4614
  if (!config) {
@@ -4325,10 +4631,10 @@ async function getMcpServerConfig(request, reply) {
4325
4631
  }
4326
4632
  }
4327
4633
  async function createMcpServerConfig(request, reply) {
4328
- const tenantId = getTenantId9(request);
4634
+ const tenantId = getTenantId11(request);
4329
4635
  const body = request.body;
4330
4636
  try {
4331
- const storeLattice = getStoreLattice8("default", "mcp");
4637
+ const storeLattice = getStoreLattice10("default", "mcp");
4332
4638
  const store = storeLattice.store;
4333
4639
  const existing = await store.getConfigByKey(tenantId, body.key);
4334
4640
  if (existing) {
@@ -4338,7 +4644,7 @@ async function createMcpServerConfig(request, reply) {
4338
4644
  message: "MCP server configuration with this key already exists"
4339
4645
  };
4340
4646
  }
4341
- const id = body.id || randomUUID5();
4647
+ const id = body.id || randomUUID6();
4342
4648
  const config = await store.createConfig(tenantId, id, body);
4343
4649
  try {
4344
4650
  await connectAndRegisterTools(config);
@@ -4364,11 +4670,11 @@ async function createMcpServerConfig(request, reply) {
4364
4670
  }
4365
4671
  }
4366
4672
  async function updateMcpServerConfig(request, reply) {
4367
- const tenantId = getTenantId9(request);
4673
+ const tenantId = getTenantId11(request);
4368
4674
  const { key } = request.params;
4369
4675
  const updates = request.body;
4370
4676
  try {
4371
- const storeLattice = getStoreLattice8("default", "mcp");
4677
+ const storeLattice = getStoreLattice10("default", "mcp");
4372
4678
  const store = storeLattice.store;
4373
4679
  const existing = await store.getConfigByKey(tenantId, key);
4374
4680
  if (!existing) {
@@ -4414,10 +4720,10 @@ async function updateMcpServerConfig(request, reply) {
4414
4720
  }
4415
4721
  }
4416
4722
  async function deleteMcpServerConfig(request, reply) {
4417
- const tenantId = getTenantId9(request);
4723
+ const tenantId = getTenantId11(request);
4418
4724
  const { keyOrId } = request.params;
4419
4725
  try {
4420
- const storeLattice = getStoreLattice8("default", "mcp");
4726
+ const storeLattice = getStoreLattice10("default", "mcp");
4421
4727
  const store = storeLattice.store;
4422
4728
  let config = await store.getConfigByKey(tenantId, keyOrId);
4423
4729
  let configKey = keyOrId;
@@ -4461,10 +4767,10 @@ async function deleteMcpServerConfig(request, reply) {
4461
4767
  }
4462
4768
  }
4463
4769
  async function testMcpServerConnection(request, reply) {
4464
- const tenantId = getTenantId9(request);
4770
+ const tenantId = getTenantId11(request);
4465
4771
  const { key } = request.params;
4466
4772
  try {
4467
- const storeLattice = getStoreLattice8("default", "mcp");
4773
+ const storeLattice = getStoreLattice10("default", "mcp");
4468
4774
  const store = storeLattice.store;
4469
4775
  const config = await store.getConfigByKey(tenantId, key);
4470
4776
  if (!config) {
@@ -4514,10 +4820,10 @@ async function testMcpServerConnection(request, reply) {
4514
4820
  }
4515
4821
  }
4516
4822
  async function listMcpServerTools(request, reply) {
4517
- const tenantId = getTenantId9(request);
4823
+ const tenantId = getTenantId11(request);
4518
4824
  const { key } = request.params;
4519
4825
  try {
4520
- const storeLattice = getStoreLattice8("default", "mcp");
4826
+ const storeLattice = getStoreLattice10("default", "mcp");
4521
4827
  const store = storeLattice.store;
4522
4828
  const config = await store.getConfigByKey(tenantId, key);
4523
4829
  if (!config) {
@@ -4547,10 +4853,10 @@ async function listMcpServerTools(request, reply) {
4547
4853
  }
4548
4854
  }
4549
4855
  async function connectMcpServer(request, reply) {
4550
- const tenantId = getTenantId9(request);
4856
+ const tenantId = getTenantId11(request);
4551
4857
  const { key } = request.params;
4552
4858
  try {
4553
- const storeLattice = getStoreLattice8("default", "mcp");
4859
+ const storeLattice = getStoreLattice10("default", "mcp");
4554
4860
  const store = storeLattice.store;
4555
4861
  const config = await store.getConfigByKey(tenantId, key);
4556
4862
  if (!config) {
@@ -4571,7 +4877,7 @@ async function connectMcpServer(request, reply) {
4571
4877
  };
4572
4878
  } catch (error) {
4573
4879
  console.error("Failed to connect MCP server:", error);
4574
- const storeLattice = getStoreLattice8("default", "mcp");
4880
+ const storeLattice = getStoreLattice10("default", "mcp");
4575
4881
  const store = storeLattice.store;
4576
4882
  const config = await store.getConfigByKey(tenantId, key);
4577
4883
  if (config) {
@@ -4584,10 +4890,10 @@ async function connectMcpServer(request, reply) {
4584
4890
  }
4585
4891
  }
4586
4892
  async function disconnectMcpServer(request, reply) {
4587
- const tenantId = getTenantId9(request);
4893
+ const tenantId = getTenantId11(request);
4588
4894
  const { key } = request.params;
4589
4895
  try {
4590
- const storeLattice = getStoreLattice8("default", "mcp");
4896
+ const storeLattice = getStoreLattice10("default", "mcp");
4591
4897
  const store = storeLattice.store;
4592
4898
  const config = await store.getConfigByKey(tenantId, key);
4593
4899
  if (!config) {
@@ -4692,12 +4998,12 @@ function registerMcpServerConfigRoutes(app2) {
4692
4998
  }
4693
4999
 
4694
5000
  // src/controllers/eval.ts
4695
- import { getStoreLattice as getStoreLattice10 } from "@axiom-lattice/core";
5001
+ import { getStoreLattice as getStoreLattice12 } from "@axiom-lattice/core";
4696
5002
  import { v4 as uuidv43 } from "uuid";
4697
5003
 
4698
5004
  // src/services/eval-runner.ts
4699
5005
  import { EventEmitter } from "events";
4700
- import { getStoreLattice as getStoreLattice9, modelLatticeManager as modelLatticeManager2 } from "@axiom-lattice/core";
5006
+ import { getStoreLattice as getStoreLattice11, modelLatticeManager as modelLatticeManager2 } from "@axiom-lattice/core";
4701
5007
  import { LatticeEvalProject } from "@axiom-lattice/agent-eval";
4702
5008
  import { v4 as uuidv42 } from "uuid";
4703
5009
  function mapLogs(logs) {
@@ -4870,13 +5176,13 @@ var EvalRunner = class {
4870
5176
  return this.runs.has(runId);
4871
5177
  }
4872
5178
  getEvalStore() {
4873
- return getStoreLattice9("default", "eval").store;
5179
+ return getStoreLattice11("default", "eval").store;
4874
5180
  }
4875
5181
  };
4876
5182
  var evalRunner = new EvalRunner();
4877
5183
 
4878
5184
  // src/controllers/eval.ts
4879
- function getTenantId10(request) {
5185
+ function getTenantId12(request) {
4880
5186
  const userTenantId = request.user?.tenantId;
4881
5187
  if (userTenantId) {
4882
5188
  return userTenantId;
@@ -4884,11 +5190,11 @@ function getTenantId10(request) {
4884
5190
  return request.headers["x-tenant-id"] || "default";
4885
5191
  }
4886
5192
  function getEvalStore() {
4887
- return getStoreLattice10("default", "eval").store;
5193
+ return getStoreLattice12("default", "eval").store;
4888
5194
  }
4889
5195
  async function createProject(request, reply) {
4890
5196
  try {
4891
- const tenantId = getTenantId10(request);
5197
+ const tenantId = getTenantId12(request);
4892
5198
  const store = getEvalStore();
4893
5199
  const id = uuidv43();
4894
5200
  const data = request.body;
@@ -4913,7 +5219,7 @@ async function createProject(request, reply) {
4913
5219
  }
4914
5220
  async function listProjects(request, reply) {
4915
5221
  try {
4916
- const tenantId = getTenantId10(request);
5222
+ const tenantId = getTenantId12(request);
4917
5223
  const store = getEvalStore();
4918
5224
  let projects = await store.getProjectsByTenant(tenantId);
4919
5225
  if (projects.length === 0) {
@@ -4947,7 +5253,7 @@ async function listProjects(request, reply) {
4947
5253
  }
4948
5254
  async function getProject(request, reply) {
4949
5255
  try {
4950
- const tenantId = getTenantId10(request);
5256
+ const tenantId = getTenantId12(request);
4951
5257
  const store = getEvalStore();
4952
5258
  const { pid } = request.params;
4953
5259
  const project = await store.getProjectById(tenantId, pid);
@@ -4967,7 +5273,7 @@ async function getProject(request, reply) {
4967
5273
  }
4968
5274
  async function updateProject(request, reply) {
4969
5275
  try {
4970
- const tenantId = getTenantId10(request);
5276
+ const tenantId = getTenantId12(request);
4971
5277
  const store = getEvalStore();
4972
5278
  const { pid } = request.params;
4973
5279
  const existing = await store.getProjectById(tenantId, pid);
@@ -4987,7 +5293,7 @@ async function updateProject(request, reply) {
4987
5293
  }
4988
5294
  async function deleteProject(request, reply) {
4989
5295
  try {
4990
- const tenantId = getTenantId10(request);
5296
+ const tenantId = getTenantId12(request);
4991
5297
  const store = getEvalStore();
4992
5298
  const { pid } = request.params;
4993
5299
  const existing = await store.getProjectById(tenantId, pid);
@@ -5006,7 +5312,7 @@ async function deleteProject(request, reply) {
5006
5312
  }
5007
5313
  async function createSuite(request, reply) {
5008
5314
  try {
5009
- const tenantId = getTenantId10(request);
5315
+ const tenantId = getTenantId12(request);
5010
5316
  const store = getEvalStore();
5011
5317
  const { pid } = request.params;
5012
5318
  const project = await store.getProjectById(tenantId, pid);
@@ -5028,7 +5334,7 @@ async function createSuite(request, reply) {
5028
5334
  }
5029
5335
  async function updateSuite(request, reply) {
5030
5336
  try {
5031
- const tenantId = getTenantId10(request);
5337
+ const tenantId = getTenantId12(request);
5032
5338
  const store = getEvalStore();
5033
5339
  const { sid } = request.params;
5034
5340
  const existing = await store.getSuiteById(tenantId, sid);
@@ -5048,7 +5354,7 @@ async function updateSuite(request, reply) {
5048
5354
  }
5049
5355
  async function deleteSuite(request, reply) {
5050
5356
  try {
5051
- const tenantId = getTenantId10(request);
5357
+ const tenantId = getTenantId12(request);
5052
5358
  const store = getEvalStore();
5053
5359
  const { sid } = request.params;
5054
5360
  const existing = await store.getSuiteById(tenantId, sid);
@@ -5067,7 +5373,7 @@ async function deleteSuite(request, reply) {
5067
5373
  }
5068
5374
  async function createCase(request, reply) {
5069
5375
  try {
5070
- const tenantId = getTenantId10(request);
5376
+ const tenantId = getTenantId12(request);
5071
5377
  const store = getEvalStore();
5072
5378
  const { sid } = request.params;
5073
5379
  const suite = await store.getSuiteById(tenantId, sid);
@@ -5096,7 +5402,7 @@ async function createCase(request, reply) {
5096
5402
  }
5097
5403
  async function listCasesForSuite(request, reply) {
5098
5404
  try {
5099
- const tenantId = getTenantId10(request);
5405
+ const tenantId = getTenantId12(request);
5100
5406
  const store = getEvalStore();
5101
5407
  const { sid } = request.params;
5102
5408
  const cases = await store.getCasesBySuite(tenantId, sid);
@@ -5112,7 +5418,7 @@ async function listCasesForSuite(request, reply) {
5112
5418
  }
5113
5419
  async function updateCase(request, reply) {
5114
5420
  try {
5115
- const tenantId = getTenantId10(request);
5421
+ const tenantId = getTenantId12(request);
5116
5422
  const store = getEvalStore();
5117
5423
  const { cid } = request.params;
5118
5424
  const existing = await store.getCaseById(tenantId, cid);
@@ -5132,7 +5438,7 @@ async function updateCase(request, reply) {
5132
5438
  }
5133
5439
  async function deleteCase(request, reply) {
5134
5440
  try {
5135
- const tenantId = getTenantId10(request);
5441
+ const tenantId = getTenantId12(request);
5136
5442
  const store = getEvalStore();
5137
5443
  const { cid } = request.params;
5138
5444
  const existing = await store.getCaseById(tenantId, cid);
@@ -5164,7 +5470,7 @@ function registerEvalRoutes(app2) {
5164
5470
  app2.delete("/api/eval/projects/:pid/suites/:sid/cases/:cid", deleteCase);
5165
5471
  app2.post("/api/eval/projects/:pid/runs", async (request, reply) => {
5166
5472
  try {
5167
- const tenantId = getTenantId10(request);
5473
+ const tenantId = getTenantId12(request);
5168
5474
  const { pid } = request.params;
5169
5475
  const runId = await evalRunner.startRun(tenantId, pid);
5170
5476
  reply.status(202).send({ success: true, message: "Run started", data: { run_id: runId } });
@@ -5176,7 +5482,7 @@ function registerEvalRoutes(app2) {
5176
5482
  });
5177
5483
  app2.get("/api/eval/runs", async (request, reply) => {
5178
5484
  try {
5179
- const tenantId = getTenantId10(request);
5485
+ const tenantId = getTenantId12(request);
5180
5486
  const query = request.query;
5181
5487
  const runs = await getEvalStore().getRunsByTenant(tenantId, { projectId: query.project_id, status: query.status });
5182
5488
  reply.send({ success: true, message: "Ok", data: { records: runs, total: runs.length } });
@@ -5186,7 +5492,7 @@ function registerEvalRoutes(app2) {
5186
5492
  });
5187
5493
  app2.get("/api/eval/runs/:rid", async (request, reply) => {
5188
5494
  try {
5189
- const tenantId = getTenantId10(request);
5495
+ const tenantId = getTenantId12(request);
5190
5496
  const { rid } = request.params;
5191
5497
  const run = await getEvalStore().getRunById(tenantId, rid);
5192
5498
  if (!run) return reply.status(404).send({ success: false, message: "Run not found" });
@@ -5208,7 +5514,7 @@ function registerEvalRoutes(app2) {
5208
5514
  const emitter = evalRunner.getEventEmitter();
5209
5515
  const eventKey = `run:${rid}`;
5210
5516
  if (!evalRunner.isRunning(rid)) {
5211
- const tenantId = getTenantId10(request);
5517
+ const tenantId = getTenantId12(request);
5212
5518
  const run = await getEvalStore().getRunById(tenantId, rid);
5213
5519
  if (run) {
5214
5520
  const eventType = run.status === "completed" ? "completed" : "error";
@@ -5247,7 +5553,7 @@ data: ${JSON.stringify(event.data)}
5247
5553
  });
5248
5554
  app2.delete("/api/eval/runs/:rid", async (request, reply) => {
5249
5555
  try {
5250
- const tenantId = getTenantId10(request);
5556
+ const tenantId = getTenantId12(request);
5251
5557
  const { rid } = request.params;
5252
5558
  const deleted = await getEvalStore().deleteRun(tenantId, rid);
5253
5559
  if (!deleted) return reply.status(404).send({ success: false, message: "Run not found" });
@@ -5258,7 +5564,7 @@ data: ${JSON.stringify(event.data)}
5258
5564
  });
5259
5565
  app2.get("/api/eval/reports/projects/:pid", async (request, reply) => {
5260
5566
  try {
5261
- const tenantId = getTenantId10(request);
5567
+ const tenantId = getTenantId12(request);
5262
5568
  const { pid } = request.params;
5263
5569
  const report = await getEvalStore().getProjectReport(tenantId, pid);
5264
5570
  if (!report) return reply.status(404).send({ success: false, message: "Project not found" });
@@ -5270,11 +5576,11 @@ data: ${JSON.stringify(event.data)}
5270
5576
  }
5271
5577
 
5272
5578
  // src/controllers/users.ts
5273
- import { getStoreLattice as getStoreLattice11 } from "@axiom-lattice/core";
5579
+ import { getStoreLattice as getStoreLattice13 } from "@axiom-lattice/core";
5274
5580
  import { v4 as uuidv44 } from "uuid";
5275
5581
  var UsersController = class {
5276
5582
  constructor() {
5277
- this.userStore = getStoreLattice11("default", "user").store;
5583
+ this.userStore = getStoreLattice13("default", "user").store;
5278
5584
  }
5279
5585
  async listUsers(request, reply) {
5280
5586
  const { email } = request.query;
@@ -5352,11 +5658,11 @@ function registerUserRoutes(app2) {
5352
5658
  }
5353
5659
 
5354
5660
  // src/controllers/tenants.ts
5355
- import { getStoreLattice as getStoreLattice12 } from "@axiom-lattice/core";
5661
+ import { getStoreLattice as getStoreLattice14 } from "@axiom-lattice/core";
5356
5662
  import { v4 as uuidv45 } from "uuid";
5357
5663
  var TenantsController = class {
5358
5664
  constructor() {
5359
- this.tenantStore = getStoreLattice12("default", "tenant").store;
5665
+ this.tenantStore = getStoreLattice14("default", "tenant").store;
5360
5666
  }
5361
5667
  // ==================== Tenant CRUD ====================
5362
5668
  async listTenants(request, reply) {
@@ -5420,7 +5726,7 @@ function registerTenantRoutes(app2) {
5420
5726
  }
5421
5727
 
5422
5728
  // src/controllers/auth.ts
5423
- import { getStoreLattice as getStoreLattice13 } from "@axiom-lattice/core";
5729
+ import { getStoreLattice as getStoreLattice15 } from "@axiom-lattice/core";
5424
5730
  import { v4 as uuidv46 } from "uuid";
5425
5731
  var defaultAuthConfig = {
5426
5732
  autoApproveUsers: true,
@@ -5429,9 +5735,9 @@ var defaultAuthConfig = {
5429
5735
  };
5430
5736
  var AuthController = class {
5431
5737
  constructor(config = {}) {
5432
- this.userStore = getStoreLattice13("default", "user").store;
5433
- this.tenantStore = getStoreLattice13("default", "tenant").store;
5434
- this.userTenantLinkStore = getStoreLattice13("default", "userTenantLink").store;
5738
+ this.userStore = getStoreLattice15("default", "user").store;
5739
+ this.tenantStore = getStoreLattice15("default", "tenant").store;
5740
+ this.userTenantLinkStore = getStoreLattice15("default", "userTenantLink").store;
5435
5741
  this.config = { ...defaultAuthConfig, ...config };
5436
5742
  }
5437
5743
  async register(request, reply) {
@@ -5585,6 +5891,8 @@ var AuthController = class {
5585
5891
  });
5586
5892
  }
5587
5893
  const token = await this.generateToken(userId, tenantId);
5894
+ const link = await this.userTenantLinkStore.getLink(userId, tenantId);
5895
+ const linkMeta = link?.metadata || {};
5588
5896
  return {
5589
5897
  success: true,
5590
5898
  data: {
@@ -5593,7 +5901,12 @@ var AuthController = class {
5593
5901
  name: tenant.name,
5594
5902
  status: tenant.status
5595
5903
  },
5596
- token
5904
+ token,
5905
+ personalAssistant: linkMeta.personalAssistantId ? {
5906
+ assistantId: linkMeta.personalAssistantId,
5907
+ projectId: linkMeta.personalProjectId || "default",
5908
+ workspaceId: linkMeta.personalWorkspaceId || "default"
5909
+ } : null
5597
5910
  }
5598
5911
  };
5599
5912
  } catch (error) {
@@ -5839,82 +6152,6 @@ function normalizeChatType(chatType) {
5839
6152
  return chatType === "p2p" ? "direct" : "group";
5840
6153
  }
5841
6154
 
5842
- // src/channels/lark/LarkChannelAdapter.ts
5843
- var larkConfigSchema = z.object({
5844
- appId: z.string(),
5845
- appSecret: z.string(),
5846
- verificationToken: z.string().optional(),
5847
- encryptKey: z.string().optional()
5848
- });
5849
- var larkChannelAdapter = {
5850
- channel: "lark",
5851
- configSchema: larkConfigSchema,
5852
- async receive(rawPayload, installation) {
5853
- const event = parseLarkMessageEvent(rawPayload);
5854
- if (!event) return null;
5855
- return {
5856
- channel: "lark",
5857
- channelInstallationId: installation.id,
5858
- tenantId: installation.tenantId,
5859
- sender: {
5860
- id: event.openId,
5861
- displayName: void 0
5862
- },
5863
- content: {
5864
- text: event.text,
5865
- metadata: {
5866
- chatId: event.chatId,
5867
- chatType: event.chatType,
5868
- messageId: event.messageId
5869
- }
5870
- },
5871
- conversation: {
5872
- id: event.chatId,
5873
- type: event.chatType
5874
- },
5875
- replyTarget: {
5876
- adapterChannel: "lark",
5877
- channelInstallationId: installation.id,
5878
- rawTarget: {
5879
- chatId: event.chatId,
5880
- messageId: event.messageId,
5881
- chatType: event.chatType
5882
- }
5883
- }
5884
- };
5885
- },
5886
- async sendReply(replyTarget, message, installation) {
5887
- const { createLarkSender } = await import("./sender-PX32VSHB.mjs");
5888
- const sender = await createLarkSender(installation.config);
5889
- await sender.sendTextReply({
5890
- chatId: replyTarget.rawTarget.chatId,
5891
- text: message.text
5892
- });
5893
- }
5894
- };
5895
-
5896
- // src/channels/lark/verification.ts
5897
- import crypto2 from "crypto";
5898
- function parseLarkRequestBody(body, encryptKey) {
5899
- const parsed = body || {};
5900
- if (encryptKey && typeof parsed.encrypt === "string") {
5901
- return decryptLarkPayload(encryptKey, parsed.encrypt);
5902
- }
5903
- return parsed;
5904
- }
5905
- function decryptLarkPayload(encryptKey, encryptedPayload) {
5906
- const key = crypto2.createHash("sha256").update(encryptKey).digest();
5907
- const buffer = Buffer.from(encryptedPayload, "base64");
5908
- const iv = buffer.subarray(0, 16);
5909
- const ciphertext = buffer.subarray(16);
5910
- const decipher = crypto2.createDecipheriv("aes-256-cbc", key, iv);
5911
- const plaintext = Buffer.concat([
5912
- decipher.update(ciphertext),
5913
- decipher.final()
5914
- ]).toString("utf8");
5915
- return JSON.parse(plaintext);
5916
- }
5917
-
5918
6155
  // src/logger/Logger.ts
5919
6156
  import pino from "pino";
5920
6157
  import "pino-pretty";
@@ -6053,8 +6290,165 @@ var Logger = class _Logger {
6053
6290
  }
6054
6291
  };
6055
6292
 
6056
- // src/channels/lark/controller.ts
6293
+ // src/channels/lark/LarkChannelAdapter.ts
6294
+ import * as Lark from "@larksuiteoapi/node-sdk";
6057
6295
  var logger = new Logger({ serviceName: "lattice/gateway/lark" });
6296
+ var activeConnections = /* @__PURE__ */ new Map();
6297
+ function parseTextContent(content) {
6298
+ if (!content) return null;
6299
+ try {
6300
+ const parsed = JSON.parse(content);
6301
+ return typeof parsed.text === "string" ? parsed.text : null;
6302
+ } catch {
6303
+ return null;
6304
+ }
6305
+ }
6306
+ function normalizeChatType2(chatType) {
6307
+ return chatType === "p2p" ? "direct" : "group";
6308
+ }
6309
+ function wsEventToInbound(event, installationId, tenantId) {
6310
+ const messageId = event.message?.message_id;
6311
+ const chatId = event.message?.chat_id;
6312
+ const openId = event.sender?.sender_id?.open_id;
6313
+ if (!messageId || !chatId || !openId) return null;
6314
+ if (event.message?.message_type !== "text") return null;
6315
+ const text = parseTextContent(event.message.content);
6316
+ if (!text) return null;
6317
+ const chatType = normalizeChatType2(event.message.chat_type);
6318
+ return {
6319
+ channel: "lark",
6320
+ channelInstallationId: installationId,
6321
+ tenantId,
6322
+ sender: { id: openId, displayName: void 0 },
6323
+ content: { text, metadata: { chatId, chatType, messageId } },
6324
+ conversation: { id: chatId, type: chatType },
6325
+ replyTarget: {
6326
+ adapterChannel: "lark",
6327
+ channelInstallationId: installationId,
6328
+ rawTarget: { chatId, messageId, chatType }
6329
+ }
6330
+ };
6331
+ }
6332
+ var larkConfigSchema = z.object({
6333
+ appId: z.string(),
6334
+ appSecret: z.string(),
6335
+ verificationToken: z.string().optional(),
6336
+ encryptKey: z.string().optional()
6337
+ });
6338
+ var larkChannelAdapter = {
6339
+ channel: "lark",
6340
+ configSchema: larkConfigSchema,
6341
+ async receive(rawPayload, installation) {
6342
+ const event = parseLarkMessageEvent(rawPayload);
6343
+ if (!event) return null;
6344
+ return {
6345
+ channel: "lark",
6346
+ channelInstallationId: installation.id,
6347
+ tenantId: installation.tenantId,
6348
+ sender: { id: event.openId, displayName: void 0 },
6349
+ content: {
6350
+ text: event.text,
6351
+ metadata: { chatId: event.chatId, chatType: event.chatType, messageId: event.messageId }
6352
+ },
6353
+ conversation: { id: event.chatId, type: event.chatType },
6354
+ replyTarget: {
6355
+ adapterChannel: "lark",
6356
+ channelInstallationId: installation.id,
6357
+ rawTarget: { chatId: event.chatId, messageId: event.messageId, chatType: event.chatType }
6358
+ }
6359
+ };
6360
+ },
6361
+ async sendReply(replyTarget, message, installation) {
6362
+ const { createLarkSender } = await import("./sender-PX32VSHB.mjs");
6363
+ const sender = await createLarkSender(installation.config);
6364
+ await sender.sendTextReply({
6365
+ chatId: replyTarget.rawTarget.chatId,
6366
+ text: message.text
6367
+ });
6368
+ },
6369
+ resolveThreadId(message, binding) {
6370
+ const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
6371
+ const chatType = message.conversation?.type === "direct" ? "dm" : "group";
6372
+ const agentId = binding.agentId;
6373
+ if (chatType === "dm") {
6374
+ return `lark:dm:${message.sender.id}:${agentId}:${date}`;
6375
+ }
6376
+ return `lark:group:${message.conversation?.id ?? "unknown"}:${agentId}:${date}`;
6377
+ },
6378
+ async connect(installation, deps) {
6379
+ const { id: installationId, tenantId, config } = installation;
6380
+ if (!config.appId || !config.appSecret) {
6381
+ logger.warn("Lark installation missing credentials, skipping", { installationId });
6382
+ return;
6383
+ }
6384
+ if (activeConnections.has(installationId)) {
6385
+ logger.warn("Lark WS already connected for installation, skipping", { installationId });
6386
+ return;
6387
+ }
6388
+ logger.info("Lark WS client starting", { installationId, tenantId });
6389
+ const router = deps?.router;
6390
+ const eventDispatcher = new Lark.EventDispatcher({}).register({
6391
+ "im.message.receive_v1": async (data) => {
6392
+ try {
6393
+ const inbound = wsEventToInbound(data, installationId, tenantId);
6394
+ if (!inbound) return;
6395
+ logger.info("Lark WS message received", {
6396
+ installationId,
6397
+ senderId: inbound.sender.id,
6398
+ chatId: data.message?.chat_id
6399
+ });
6400
+ if (router) {
6401
+ const result = await router.dispatch(inbound);
6402
+ if (!result.success) {
6403
+ logger.warn("Lark WS dispatch failed", {
6404
+ installationId,
6405
+ error: result.error?.message
6406
+ });
6407
+ }
6408
+ }
6409
+ } catch (err) {
6410
+ logger.error("Lark WS event handler error", {
6411
+ installationId,
6412
+ error: err instanceof Error ? err.message : String(err)
6413
+ });
6414
+ }
6415
+ }
6416
+ });
6417
+ const client = new Lark.WSClient({
6418
+ appId: config.appId,
6419
+ appSecret: config.appSecret,
6420
+ loggerLevel: Lark.LoggerLevel.info
6421
+ });
6422
+ await client.start({ eventDispatcher });
6423
+ activeConnections.set(installationId, client);
6424
+ logger.info("Lark WS client connected", { installationId });
6425
+ }
6426
+ };
6427
+
6428
+ // src/channels/lark/verification.ts
6429
+ import crypto2 from "crypto";
6430
+ function parseLarkRequestBody(body, encryptKey) {
6431
+ const parsed = body || {};
6432
+ if (encryptKey && typeof parsed.encrypt === "string") {
6433
+ return decryptLarkPayload(encryptKey, parsed.encrypt);
6434
+ }
6435
+ return parsed;
6436
+ }
6437
+ function decryptLarkPayload(encryptKey, encryptedPayload) {
6438
+ const key = crypto2.createHash("sha256").update(encryptKey).digest();
6439
+ const buffer = Buffer.from(encryptedPayload, "base64");
6440
+ const iv = buffer.subarray(0, 16);
6441
+ const ciphertext = buffer.subarray(16);
6442
+ const decipher = crypto2.createDecipheriv("aes-256-cbc", key, iv);
6443
+ const plaintext = Buffer.concat([
6444
+ decipher.update(ciphertext),
6445
+ decipher.final()
6446
+ ]).toString("utf8");
6447
+ return JSON.parse(plaintext);
6448
+ }
6449
+
6450
+ // src/channels/lark/controller.ts
6451
+ var logger2 = new Logger({ serviceName: "lattice/gateway/lark" });
6058
6452
  function createLarkEventHandler(deps) {
6059
6453
  return async function handleLarkEvent(request, reply) {
6060
6454
  const { installationId } = request.params;
@@ -6075,7 +6469,7 @@ function createLarkEventHandler(deps) {
6075
6469
  return;
6076
6470
  }
6077
6471
  deps.router.dispatch(inboundMessage).catch((error) => {
6078
- logger.error("Lark message dispatch error", {
6472
+ logger2.error("Lark message dispatch error", {
6079
6473
  error: error instanceof Error ? error.message : String(error)
6080
6474
  });
6081
6475
  });
@@ -6107,8 +6501,8 @@ function registerChannelRoutes(app2, dependencies) {
6107
6501
  }
6108
6502
 
6109
6503
  // src/controllers/channel-installations.ts
6110
- import { randomUUID as randomUUID6 } from "crypto";
6111
- function getTenantId11(request) {
6504
+ import { randomUUID as randomUUID7 } from "crypto";
6505
+ function getTenantId13(request) {
6112
6506
  const userTenantId = request.user?.tenantId;
6113
6507
  if (userTenantId) {
6114
6508
  return userTenantId;
@@ -6116,8 +6510,8 @@ function getTenantId11(request) {
6116
6510
  return request.headers["x-tenant-id"] || "default";
6117
6511
  }
6118
6512
  async function getInstallationStore() {
6119
- const { getStoreLattice: getStoreLattice16 } = await import("@axiom-lattice/core");
6120
- const store = getStoreLattice16("default", "channelInstallation").store;
6513
+ const { getStoreLattice: getStoreLattice18 } = await import("@axiom-lattice/core");
6514
+ const store = getStoreLattice18("default", "channelInstallation").store;
6121
6515
  if (store) return store;
6122
6516
  const { PostgreSQLChannelInstallationStore } = await import("@axiom-lattice/pg-stores");
6123
6517
  const databaseUrl = process.env.DATABASE_URL;
@@ -6129,7 +6523,7 @@ async function getInstallationStore() {
6129
6523
  });
6130
6524
  }
6131
6525
  async function getChannelInstallationList(request, reply) {
6132
- const tenantId = getTenantId11(request);
6526
+ const tenantId = getTenantId13(request);
6133
6527
  const { channel } = request.query;
6134
6528
  try {
6135
6529
  const store = await getInstallationStore();
@@ -6155,7 +6549,7 @@ async function getChannelInstallationList(request, reply) {
6155
6549
  }
6156
6550
  }
6157
6551
  async function getChannelInstallation(request, reply) {
6158
- const tenantId = getTenantId11(request);
6552
+ const tenantId = getTenantId13(request);
6159
6553
  const { installationId } = request.params;
6160
6554
  try {
6161
6555
  const store = await getInstallationStore();
@@ -6188,7 +6582,7 @@ async function getChannelInstallation(request, reply) {
6188
6582
  }
6189
6583
  }
6190
6584
  async function createChannelInstallation(request, reply) {
6191
- const tenantId = getTenantId11(request);
6585
+ const tenantId = getTenantId13(request);
6192
6586
  const body = request.body;
6193
6587
  try {
6194
6588
  if (!body.channel) {
@@ -6223,7 +6617,7 @@ async function createChannelInstallation(request, reply) {
6223
6617
  }
6224
6618
  }
6225
6619
  const store = await getInstallationStore();
6226
- const installationId = body.id || randomUUID6();
6620
+ const installationId = body.id || randomUUID7();
6227
6621
  const installation = await store.createInstallation(
6228
6622
  tenantId,
6229
6623
  installationId,
@@ -6251,7 +6645,7 @@ async function createChannelInstallation(request, reply) {
6251
6645
  }
6252
6646
  }
6253
6647
  async function updateChannelInstallation(request, reply) {
6254
- const tenantId = getTenantId11(request);
6648
+ const tenantId = getTenantId13(request);
6255
6649
  const { installationId } = request.params;
6256
6650
  const body = request.body;
6257
6651
  try {
@@ -6297,7 +6691,7 @@ async function updateChannelInstallation(request, reply) {
6297
6691
  }
6298
6692
  }
6299
6693
  async function deleteChannelInstallation(request, reply) {
6300
- const tenantId = getTenantId11(request);
6694
+ const tenantId = getTenantId13(request);
6301
6695
  const { installationId } = request.params;
6302
6696
  try {
6303
6697
  const store = await getInstallationStore();
@@ -6348,13 +6742,13 @@ function registerChannelInstallationRoutes(app2) {
6348
6742
 
6349
6743
  // src/controllers/channel-bindings.ts
6350
6744
  import { getBindingRegistry } from "@axiom-lattice/core";
6351
- function getTenantId12(request) {
6745
+ function getTenantId14(request) {
6352
6746
  const userTenantId = request.user?.tenantId;
6353
6747
  if (userTenantId) return userTenantId;
6354
6748
  return request.headers["x-tenant-id"] || "default";
6355
6749
  }
6356
6750
  async function getBindingList(request, _reply) {
6357
- const tenantId = getTenantId12(request);
6751
+ const tenantId = getTenantId14(request);
6358
6752
  const { channel, agentId, channelInstallationId, limit, offset } = request.query;
6359
6753
  try {
6360
6754
  const registry = getBindingRegistry();
@@ -6366,7 +6760,7 @@ async function getBindingList(request, _reply) {
6366
6760
  }
6367
6761
  }
6368
6762
  async function getBinding(request, reply) {
6369
- const tenantId = getTenantId12(request);
6763
+ const tenantId = getTenantId14(request);
6370
6764
  try {
6371
6765
  const registry = getBindingRegistry();
6372
6766
  const bindings = await registry.list({ tenantId });
@@ -6382,7 +6776,7 @@ async function getBinding(request, reply) {
6382
6776
  }
6383
6777
  }
6384
6778
  async function createBinding(request, reply) {
6385
- const tenantId = getTenantId12(request);
6779
+ const tenantId = getTenantId14(request);
6386
6780
  try {
6387
6781
  const registry = getBindingRegistry();
6388
6782
  const binding = await registry.create({ ...request.body, tenantId });
@@ -6396,7 +6790,7 @@ async function createBinding(request, reply) {
6396
6790
  }
6397
6791
  async function updateBinding(request, reply) {
6398
6792
  try {
6399
- const tenantId = getTenantId12(request);
6793
+ const tenantId = getTenantId14(request);
6400
6794
  const registry = getBindingRegistry();
6401
6795
  const bindings = await registry.list({ tenantId });
6402
6796
  const existing = bindings.find((b) => b.id === request.params.id);
@@ -6414,7 +6808,7 @@ async function updateBinding(request, reply) {
6414
6808
  }
6415
6809
  async function deleteBinding(request, reply) {
6416
6810
  try {
6417
- const tenantId = getTenantId12(request);
6811
+ const tenantId = getTenantId14(request);
6418
6812
  const registry = getBindingRegistry();
6419
6813
  const bindings = await registry.list({ tenantId });
6420
6814
  const existing = bindings.find((b) => b.id === request.params.id);
@@ -6431,7 +6825,7 @@ async function deleteBinding(request, reply) {
6431
6825
  }
6432
6826
  }
6433
6827
  async function resolveBinding(request, _reply) {
6434
- const tenantId = getTenantId12(request);
6828
+ const tenantId = getTenantId14(request);
6435
6829
  const { channel, senderId, channelInstallationId } = request.query;
6436
6830
  try {
6437
6831
  const registry = getBindingRegistry();
@@ -6456,6 +6850,105 @@ function registerChannelBindingRoutes(app2) {
6456
6850
  app2.delete("/api/channel-bindings/:id", deleteBinding);
6457
6851
  }
6458
6852
 
6853
+ // src/controllers/menu-items.ts
6854
+ import { getMenuRegistry } from "@axiom-lattice/core";
6855
+ function getTenantId15(request) {
6856
+ const userTenantId = request.user?.tenantId;
6857
+ if (userTenantId) return userTenantId;
6858
+ return request.headers["x-tenant-id"] || "default";
6859
+ }
6860
+ function errorMessage(err) {
6861
+ return err instanceof Error ? err.message : "Unexpected error";
6862
+ }
6863
+ async function getMenuItemList(request, _reply) {
6864
+ const tenantId = getTenantId15(request);
6865
+ try {
6866
+ const registry = getMenuRegistry();
6867
+ const items = await registry.list({ tenantId, menuTarget: request.query.menuTarget });
6868
+ return { success: true, message: "Menu items retrieved", data: { records: items, total: items.length } };
6869
+ } catch (error) {
6870
+ const msg = errorMessage(error);
6871
+ console.error("Failed to get menu items:", msg);
6872
+ return { success: false, message: msg, data: { records: [], total: 0 } };
6873
+ }
6874
+ }
6875
+ async function getMenuItem(request, reply) {
6876
+ const tenantId = getTenantId15(request);
6877
+ try {
6878
+ const registry = getMenuRegistry();
6879
+ const item = await registry.getById(request.params.id);
6880
+ if (!item || item.tenantId !== tenantId) {
6881
+ reply.status(404);
6882
+ return { success: false, message: "Menu item not found" };
6883
+ }
6884
+ return { success: true, message: "Menu item retrieved", data: item };
6885
+ } catch (error) {
6886
+ const msg = errorMessage(error);
6887
+ console.error("Failed to get menu item:", msg);
6888
+ reply.status(500);
6889
+ return { success: false, message: msg };
6890
+ }
6891
+ }
6892
+ async function createMenuItem(request, reply) {
6893
+ const tenantId = getTenantId15(request);
6894
+ try {
6895
+ const registry = getMenuRegistry();
6896
+ const item = await registry.create({ ...request.body, tenantId });
6897
+ reply.status(201);
6898
+ return { success: true, message: "Menu item created", data: item };
6899
+ } catch (error) {
6900
+ const msg = errorMessage(error);
6901
+ console.error("Failed to create menu item:", msg);
6902
+ reply.status(500);
6903
+ return { success: false, message: msg };
6904
+ }
6905
+ }
6906
+ async function updateMenuItem(request, reply) {
6907
+ try {
6908
+ const tenantId = getTenantId15(request);
6909
+ const registry = getMenuRegistry();
6910
+ const existing = await registry.getById(request.params.id);
6911
+ if (!existing || existing.tenantId !== tenantId) {
6912
+ reply.status(404);
6913
+ return { success: false, message: "Menu item not found" };
6914
+ }
6915
+ const item = await registry.update(request.params.id, request.body);
6916
+ return { success: true, message: "Menu item updated", data: item };
6917
+ } catch (error) {
6918
+ const msg = errorMessage(error);
6919
+ console.error("Failed to update menu item:", msg);
6920
+ reply.status(500);
6921
+ return { success: false, message: msg };
6922
+ }
6923
+ }
6924
+ async function deleteMenuItem(request, reply) {
6925
+ try {
6926
+ const tenantId = getTenantId15(request);
6927
+ const registry = getMenuRegistry();
6928
+ const existing = await registry.getById(request.params.id);
6929
+ if (!existing || existing.tenantId !== tenantId) {
6930
+ reply.status(404);
6931
+ return { success: false, message: "Menu item not found" };
6932
+ }
6933
+ await registry.delete(request.params.id);
6934
+ return { success: true, message: "Menu item deleted" };
6935
+ } catch (error) {
6936
+ const msg = errorMessage(error);
6937
+ console.error("Failed to delete menu item:", msg);
6938
+ reply.status(500);
6939
+ return { success: false, message: msg };
6940
+ }
6941
+ }
6942
+
6943
+ // src/routes/menu-items.ts
6944
+ function registerMenuItemRoutes(app2) {
6945
+ app2.get("/api/menu-items", getMenuItemList);
6946
+ app2.post("/api/menu-items", createMenuItem);
6947
+ app2.get("/api/menu-items/:id", getMenuItem);
6948
+ app2.put("/api/menu-items/:id", updateMenuItem);
6949
+ app2.delete("/api/menu-items/:id", deleteMenuItem);
6950
+ }
6951
+
6459
6952
  // src/routes/a2a-bridge.ts
6460
6953
  import { v4 as v42 } from "uuid";
6461
6954
  var log = {
@@ -6636,6 +7129,7 @@ var registerLatticeRoutes = (app2, channelDeps) => {
6636
7129
  app2.post("/api/runs", createRun);
6637
7130
  app2.post("/api/resume_stream", resumeStream);
6638
7131
  app2.post("/api/assistants/:assistantId/threads/:threadId/abort", abortRun);
7132
+ app2.post("/api/assistants/:assistantId/threads/:threadId/recover", recoverRun);
6639
7133
  app2.get(
6640
7134
  "/api/assistants/:assistantId/:thread_id/memory",
6641
7135
  { schema: getAllMemoryItemsSchema },
@@ -6671,6 +7165,15 @@ var registerLatticeRoutes = (app2, channelDeps) => {
6671
7165
  app2.post("/api/assistants", createAssistant);
6672
7166
  app2.put("/api/assistants/:id", updateAssistant);
6673
7167
  app2.delete("/api/assistants/:id", deleteAssistant);
7168
+ app2.post("/api/personal-assistant", createPersonalAssistant);
7169
+ app2.get("/api/personal-assistant", getPersonalAssistant);
7170
+ app2.delete("/api/personal-assistant", deletePersonalAssistant);
7171
+ app2.get("/api/tasks", listTasks);
7172
+ app2.get("/api/tasks/:id", getTask);
7173
+ app2.post("/api/tasks", createTask);
7174
+ app2.put("/api/tasks/:id", updateTask);
7175
+ app2.delete("/api/tasks/:id", deleteTask);
7176
+ app2.patch("/api/tasks/:id/complete", completeTask);
6674
7177
  app2.get(
6675
7178
  "/api/assistants/:assistantId/graph",
6676
7179
  { schema: getAgentGraphSchema },
@@ -6769,6 +7272,7 @@ var registerLatticeRoutes = (app2, channelDeps) => {
6769
7272
  });
6770
7273
  registerChannelRoutes(app2, channelDeps);
6771
7274
  registerChannelInstallationRoutes(app2);
7275
+ registerMenuItemRoutes(app2);
6772
7276
  if (channelDeps) {
6773
7277
  registerChannelBindingRoutes(app2);
6774
7278
  }
@@ -6847,10 +7351,10 @@ var registerLatticeRoutes = (app2, channelDeps) => {
6847
7351
 
6848
7352
  // src/router/MessageRouter.ts
6849
7353
  import {
6850
- getStoreLattice as getStoreLattice14,
7354
+ getStoreLattice as getStoreLattice16,
6851
7355
  agentInstanceManager as agentInstanceManager6
6852
7356
  } from "@axiom-lattice/core";
6853
- import { randomUUID as randomUUID7 } from "crypto";
7357
+ import { randomUUID as randomUUID8 } from "crypto";
6854
7358
  var BindingNotFoundError = class extends Error {
6855
7359
  constructor(message) {
6856
7360
  super(message);
@@ -6897,6 +7401,9 @@ var MessageRouter = class {
6897
7401
  inboundMessage: message,
6898
7402
  metadata: {}
6899
7403
  };
7404
+ let binding = null;
7405
+ let threadId;
7406
+ let agentId;
6900
7407
  try {
6901
7408
  await this.runMiddlewares(ctx, async () => {
6902
7409
  const tenantId = message.tenantId || (await this.installationStore.getInstallationById(message.channelInstallationId))?.tenantId;
@@ -6913,16 +7420,18 @@ var MessageRouter = class {
6913
7420
  );
6914
7421
  }
6915
7422
  console.log({ event: "dispatch:start", channel: message.channel, senderId: message.sender.id, tenantId }, "Message dispatch started");
6916
- let binding = await this.bindingRegistry.resolve({
7423
+ const adapter = this.adapterRegistry.get(message.channel);
7424
+ const hasAdapterThreadStrategy = !!adapter?.resolveThreadId;
7425
+ binding = await this.bindingRegistry.resolve({
6917
7426
  channel: message.channel,
6918
7427
  senderId: message.sender.id,
6919
7428
  channelInstallationId: message.channelInstallationId,
6920
7429
  tenantId
6921
7430
  });
7431
+ const installation = await this.installationStore.getInstallationById(
7432
+ message.channelInstallationId
7433
+ );
6922
7434
  if (!binding) {
6923
- const installation = await this.installationStore.getInstallationById(
6924
- message.channelInstallationId
6925
- );
6926
7435
  if (installation?.rejectWhenNoBinding) {
6927
7436
  console.warn({
6928
7437
  event: "dispatch:no_binding",
@@ -6955,7 +7464,7 @@ var MessageRouter = class {
6955
7464
  createdAt: /* @__PURE__ */ new Date(),
6956
7465
  updatedAt: /* @__PURE__ */ new Date()
6957
7466
  };
6958
- } else {
7467
+ } else if (!hasAdapterThreadStrategy) {
6959
7468
  console.error({
6960
7469
  event: "dispatch:no_fallback",
6961
7470
  channel: message.channel,
@@ -6967,47 +7476,99 @@ var MessageRouter = class {
6967
7476
  );
6968
7477
  }
6969
7478
  }
6970
- ctx.binding = binding;
6971
- console.log({
6972
- event: "dispatch:binding",
6973
- bindingId: binding.id,
6974
- agentId: binding.agentId,
6975
- threadId: binding.threadId,
6976
- threadMode: binding.threadMode,
6977
- workspaceId: binding.workspaceId,
6978
- projectId: binding.projectId
6979
- }, "Binding resolved");
6980
- if (!binding.enabled) {
6981
- console.warn({
6982
- event: "dispatch:binding_disabled",
7479
+ ctx.binding = binding ?? void 0;
7480
+ if (binding) {
7481
+ console.log({
7482
+ event: "dispatch:binding",
6983
7483
  bindingId: binding.id,
6984
7484
  agentId: binding.agentId,
6985
- senderId: message.sender.id
6986
- }, "Binding is disabled, rejecting message");
7485
+ threadId: binding.threadId,
7486
+ threadMode: binding.threadMode,
7487
+ workspaceId: binding.workspaceId,
7488
+ projectId: binding.projectId
7489
+ }, "Binding resolved");
7490
+ if (!binding.enabled) {
7491
+ console.warn({
7492
+ event: "dispatch:binding_disabled",
7493
+ bindingId: binding.id,
7494
+ agentId: binding.agentId,
7495
+ senderId: message.sender.id
7496
+ }, "Binding is disabled, rejecting message");
7497
+ throw new BindingNotFoundError(
7498
+ `Binding for sender "${message.sender.id}" is disabled`
7499
+ );
7500
+ }
7501
+ }
7502
+ agentId = binding?.agentId ?? installation?.fallbackAgentId;
7503
+ if (!agentId) {
6987
7504
  throw new BindingNotFoundError(
6988
- `Binding for sender "${message.sender.id}" is disabled`
7505
+ `No agent configured for sender "${message.sender.id}"`
6989
7506
  );
6990
7507
  }
6991
- let threadId = ctx.binding.threadMode === "per_conversation" ? void 0 : ctx.binding.threadId;
7508
+ if (hasAdapterThreadStrategy) {
7509
+ const resolvedThreadId = await adapter.resolveThreadId(message, binding);
7510
+ threadId = resolvedThreadId;
7511
+ console.log({
7512
+ event: "dispatch:thread:adapter",
7513
+ threadId,
7514
+ channel: message.channel,
7515
+ adapterChannel: adapter.channel
7516
+ }, "Thread resolved by adapter strategy");
7517
+ const threadStore = getStoreLattice16("default", "thread").store;
7518
+ try {
7519
+ await threadStore.createThread(
7520
+ tenantId,
7521
+ agentId,
7522
+ threadId,
7523
+ {
7524
+ metadata: {
7525
+ channel: message.channel,
7526
+ channelInstallationId: message.channelInstallationId,
7527
+ senderId: message.sender.id,
7528
+ bindingId: binding?.id,
7529
+ ...message.conversation ? {
7530
+ conversationId: message.conversation.id,
7531
+ conversationType: message.conversation.type
7532
+ } : {}
7533
+ }
7534
+ }
7535
+ );
7536
+ console.log({
7537
+ event: "dispatch:thread:adapter:created",
7538
+ threadId
7539
+ }, "Thread created by adapter strategy");
7540
+ } catch {
7541
+ console.log({
7542
+ event: "dispatch:thread:adapter:reuse",
7543
+ threadId
7544
+ }, "Thread already exists, reusing");
7545
+ }
7546
+ } else if (binding) {
7547
+ if (binding.threadMode === "per_conversation") {
7548
+ threadId = void 0;
7549
+ } else {
7550
+ threadId = binding.threadId;
7551
+ }
7552
+ }
6992
7553
  if (!threadId) {
6993
- const threadStore = getStoreLattice14("default", "thread").store;
6994
- const newThreadId = randomUUID7();
7554
+ const threadStore = getStoreLattice16("default", "thread").store;
7555
+ const newThreadId = randomUUID8();
6995
7556
  console.log({
6996
7557
  event: "dispatch:thread:create",
6997
- agentId: ctx.binding.agentId,
7558
+ agentId,
6998
7559
  newThreadId,
6999
7560
  tenantId
7000
7561
  }, "Creating new thread for binding");
7001
7562
  const newThread = await threadStore.createThread(
7002
7563
  tenantId,
7003
- ctx.binding.agentId,
7564
+ agentId,
7004
7565
  newThreadId,
7005
7566
  {
7006
7567
  metadata: {
7007
7568
  channel: message.channel,
7008
7569
  channelInstallationId: message.channelInstallationId,
7009
7570
  senderId: message.sender.id,
7010
- bindingId: ctx.binding.id,
7571
+ bindingId: binding?.id,
7011
7572
  ...message.conversation ? {
7012
7573
  conversationId: message.conversation.id,
7013
7574
  conversationType: message.conversation.type
@@ -7016,36 +7577,35 @@ var MessageRouter = class {
7016
7577
  }
7017
7578
  );
7018
7579
  threadId = newThread.id;
7019
- if (ctx.binding.id !== "fallback") {
7020
- await this.bindingRegistry.update(ctx.binding.id, { threadId });
7021
- ctx.binding.threadId = threadId;
7022
- } else {
7023
- ctx.binding.threadId = threadId;
7580
+ if (binding && binding.id !== "fallback") {
7581
+ await this.bindingRegistry.update(binding.id, { threadId });
7582
+ binding.threadId = threadId;
7583
+ } else if (binding) {
7584
+ binding.threadId = threadId;
7024
7585
  }
7025
7586
  }
7026
7587
  console.log({
7027
7588
  event: "dispatch:agent",
7028
- agentId: ctx.binding.agentId,
7589
+ agentId,
7029
7590
  threadId,
7030
- threadMode: ctx.binding.threadMode,
7031
7591
  senderId: message.sender.id,
7032
7592
  contentLength: message.content.text.length
7033
7593
  }, "Dispatching to agent");
7034
7594
  const agent = agentInstanceManager6.getAgent({
7035
7595
  tenant_id: tenantId,
7036
- assistant_id: ctx.binding.agentId,
7596
+ assistant_id: agentId,
7037
7597
  thread_id: threadId,
7038
- workspace_id: ctx.binding.workspaceId || "",
7039
- project_id: ctx.binding.projectId || ""
7598
+ workspace_id: binding?.workspaceId || "",
7599
+ project_id: binding?.projectId || ""
7040
7600
  });
7041
7601
  if (message.replyTarget) {
7042
7602
  const replySubKey = `${threadId}:${message.replyTarget.adapterChannel}:reply`;
7043
- const adapter = this.adapterRegistry.get(message.replyTarget.adapterChannel);
7044
- if (adapter) {
7045
- const installation = await this.installationStore.getInstallationById(
7603
+ const adapter2 = this.adapterRegistry.get(message.replyTarget.adapterChannel);
7604
+ if (adapter2) {
7605
+ const installation2 = await this.installationStore.getInstallationById(
7046
7606
  message.channelInstallationId
7047
7607
  );
7048
- if (installation) {
7608
+ if (installation2) {
7049
7609
  const existing = this._replySubs.get(replySubKey);
7050
7610
  if (!existing || existing.count === 0) {
7051
7611
  const timer = setTimeout(() => {
@@ -7085,7 +7645,7 @@ var MessageRouter = class {
7085
7645
  channel: message.replyTarget.adapterChannel,
7086
7646
  replyLength: replyText.length
7087
7647
  }, "Sending channel reply");
7088
- adapter.sendReply(message.replyTarget, { text: replyText }, installation).then(() => {
7648
+ adapter2.sendReply(message.replyTarget, { text: replyText }, installation2).then(() => {
7089
7649
  console.log({
7090
7650
  event: "dispatch:reply:sent",
7091
7651
  threadId,
@@ -7123,7 +7683,7 @@ var MessageRouter = class {
7123
7683
  });
7124
7684
  console.log({
7125
7685
  event: "dispatch:complete",
7126
- agentId: ctx.binding.agentId,
7686
+ agentId,
7127
7687
  threadId,
7128
7688
  messageId: addResult?.messageId,
7129
7689
  result: JSON.stringify(addResult)
@@ -7132,7 +7692,7 @@ var MessageRouter = class {
7132
7692
  return {
7133
7693
  success: true,
7134
7694
  bindingId: ctx.binding?.id,
7135
- threadId: ctx.binding?.threadId,
7695
+ threadId,
7136
7696
  result: ctx.result
7137
7697
  };
7138
7698
  } catch (error) {
@@ -7243,13 +7803,13 @@ function createRateLimitMiddleware(maxRequests = 10, windowMs = 60 * 1e3, maxEnt
7243
7803
  }
7244
7804
 
7245
7805
  // src/router/middlewares/auditLogger.ts
7246
- var logger2 = new Logger({ serviceName: "lattice/gateway/audit" });
7806
+ var logger3 = new Logger({ serviceName: "lattice/gateway/audit" });
7247
7807
  function createAuditLoggerMiddleware() {
7248
7808
  return async (ctx, next) => {
7249
7809
  const start2 = Date.now();
7250
7810
  try {
7251
7811
  await next();
7252
- logger2.info("message routed", {
7812
+ logger3.info("message routed", {
7253
7813
  event: "message:routed",
7254
7814
  channel: ctx.inboundMessage.channel,
7255
7815
  senderId: ctx.inboundMessage.sender.id,
@@ -7259,7 +7819,7 @@ function createAuditLoggerMiddleware() {
7259
7819
  status: "success"
7260
7820
  });
7261
7821
  } catch (error) {
7262
- logger2.error(
7822
+ logger3.error(
7263
7823
  error instanceof Error ? error.message : String(error),
7264
7824
  {
7265
7825
  event: "message:error",
@@ -7275,7 +7835,7 @@ function createAuditLoggerMiddleware() {
7275
7835
  }
7276
7836
 
7277
7837
  // src/index.ts
7278
- import { setBindingRegistry } from "@axiom-lattice/core";
7838
+ import { setBindingRegistry, setMenuRegistry } from "@axiom-lattice/core";
7279
7839
 
7280
7840
  // src/swagger.ts
7281
7841
  import swagger from "@fastify/swagger";
@@ -7364,15 +7924,16 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
7364
7924
  agent.subscribeOnce("message:completed", (evt) => {
7365
7925
  eventBus2.publish(callback_event, {
7366
7926
  success: true,
7367
- state: evt.state,
7368
- config: { assistant_id, thread_id, tenant_id }
7927
+ state: evt.state
7369
7928
  });
7370
7929
  if (main_thread_id && main_tenant_id) {
7371
7930
  try {
7372
7931
  const mainAgent = agentInstanceManager7.getAgent({
7373
7932
  assistant_id: main_assistant_id ?? assistant_id,
7374
7933
  thread_id: main_thread_id,
7375
- tenant_id: main_tenant_id
7934
+ tenant_id: main_tenant_id,
7935
+ workspace_id: runConfig?.workspaceId,
7936
+ project_id: runConfig?.projectId
7376
7937
  });
7377
7938
  if (mainAgent) {
7378
7939
  const messages = evt.state?.values?.messages;
@@ -7399,8 +7960,7 @@ ${summary}`
7399
7960
  agent.subscribeOnce("message:interrupted", (evt) => {
7400
7961
  eventBus2.publish(callback_event, {
7401
7962
  success: true,
7402
- state: evt.state,
7403
- config: { assistant_id, thread_id, tenant_id }
7963
+ state: evt.state
7404
7964
  });
7405
7965
  });
7406
7966
  }
@@ -7423,8 +7983,7 @@ ${summary}`
7423
7983
  if (callback_event) {
7424
7984
  eventBus2.publish(callback_event, {
7425
7985
  success: false,
7426
- error: error instanceof Error ? error.message : String(error),
7427
- config: { assistant_id, thread_id, tenant_id }
7986
+ error: error instanceof Error ? error.message : String(error)
7428
7987
  });
7429
7988
  }
7430
7989
  console.error(
@@ -7580,12 +8139,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
7580
8139
  if (taskRequest.callback_event) {
7581
8140
  eventBus2.publish(taskRequest.callback_event, {
7582
8141
  success: false,
7583
- error: error instanceof Error ? error.message : String(error),
7584
- config: {
7585
- assistant_id: taskRequest.assistant_id,
7586
- thread_id: taskRequest.thread_id,
7587
- tenant_id: taskRequest["x-tenant-id"]
7588
- }
8142
+ error: error instanceof Error ? error.message : String(error)
7589
8143
  });
7590
8144
  }
7591
8145
  });
@@ -7603,6 +8157,7 @@ import {
7603
8157
  getLoggerLattice,
7604
8158
  loggerLatticeManager,
7605
8159
  sandboxLatticeManager as sandboxLatticeManager2,
8160
+ getStoreLattice as getStoreLattice17,
7606
8161
  agentInstanceManager as agentInstanceManager8,
7607
8162
  createSandboxProvider
7608
8163
  } from "@axiom-lattice/core";
@@ -7620,7 +8175,7 @@ var DEFAULT_LOGGER_CONFIG = {
7620
8175
  loggerName: "lattice/gateway"
7621
8176
  };
7622
8177
  var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
7623
- var logger3 = loggerLattice.client;
8178
+ var logger4 = loggerLattice.client;
7624
8179
  function initializeLogger(config) {
7625
8180
  if (loggerLatticeManager.hasLattice("default")) {
7626
8181
  loggerLatticeManager.removeLattice("default");
@@ -7719,7 +8274,7 @@ app.setErrorHandler((error, request, reply) => {
7719
8274
  "x-request-id": getHeaderValue(request.headers["x-request-id"]),
7720
8275
  "x-user-id": getHeaderValue(request.headers["x-user-id"])
7721
8276
  };
7722
- logger3.error(
8277
+ logger4.error(
7723
8278
  `\u8BF7\u6C42\u9519\u8BEF: ${request.method} ${request.url} error:${error.message}`,
7724
8279
  {
7725
8280
  ...context,
@@ -7759,17 +8314,19 @@ var start = async (config) => {
7759
8314
  file: config.loggerConfig.file || DEFAULT_LOGGER_CONFIG.file
7760
8315
  };
7761
8316
  loggerLattice = initializeLogger(loggerConfig);
7762
- logger3 = loggerLattice.client;
8317
+ logger4 = loggerLattice.client;
7763
8318
  }
7764
8319
  app.decorate("loggerLattice", loggerLattice);
7765
8320
  let channelDeps;
8321
+ const adapterRegistry = new ChannelAdapterRegistry();
8322
+ adapterRegistry.register(larkChannelAdapter);
7766
8323
  try {
7767
- const { getStoreLattice: getStoreLattice16 } = await import("@axiom-lattice/core");
7768
- const bindingStore = getStoreLattice16("default", "channelBinding").store;
7769
- const installationStore = getStoreLattice16("default", "channelInstallation").store;
8324
+ const { getStoreLattice: getStore2 } = await import("@axiom-lattice/core");
8325
+ let bindingStore;
8326
+ let installationStore;
8327
+ bindingStore = getStore2("default", "channelBinding").store;
8328
+ installationStore = getStore2("default", "channelInstallation").store;
7770
8329
  setBindingRegistry(bindingStore);
7771
- const adapterRegistry = new ChannelAdapterRegistry();
7772
- adapterRegistry.register(larkChannelAdapter);
7773
8330
  const router = new MessageRouter({
7774
8331
  middlewares: [
7775
8332
  createDeduplicationMiddleware(),
@@ -7782,27 +8339,49 @@ var start = async (config) => {
7782
8339
  });
7783
8340
  channelDeps = { router, installationStore };
7784
8341
  try {
7785
- const a2aKeyStore = getStoreLattice16("default", "a2aApiKey").store;
8342
+ const a2aKeyStore = getStore2("default", "a2aApiKey").store;
7786
8343
  const a2a = await import("./a2a-ERG5RMUW.mjs");
7787
8344
  a2a.setA2AKeyStore(a2aKeyStore);
7788
8345
  await a2a.refreshStoreKeyMap();
7789
- logger3.info("A2A key store initialized");
8346
+ logger4.info("A2A key store initialized");
7790
8347
  } catch {
7791
8348
  }
8349
+ } catch (err) {
8350
+ logger4.warn("Channel infrastructure unavailable", {
8351
+ error: err instanceof Error ? err.message : String(err)
8352
+ });
8353
+ }
8354
+ try {
8355
+ const menuStore = getStoreLattice17("default", "menu").store;
8356
+ setMenuRegistry(menuStore);
8357
+ logger4.info("Menu registry initialized");
7792
8358
  } catch {
7793
8359
  }
7794
8360
  registerLatticeRoutes(app, channelDeps);
7795
8361
  if (!sandboxLatticeManager2.hasLattice("default")) {
7796
8362
  sandboxLatticeManager2.registerLattice("default", getConfiguredSandboxProvider());
7797
- logger3.info("Registered sandbox manager from env configuration");
8363
+ logger4.info("Registered sandbox manager from env configuration");
8364
+ }
8365
+ if (channelDeps && process.env.CHANNELS_ENABLED !== "false") {
8366
+ const { connectAllChannels } = await import("@axiom-lattice/core");
8367
+ try {
8368
+ await connectAllChannels(
8369
+ (channel) => adapterRegistry.get(channel),
8370
+ { deps: { router: channelDeps.router } }
8371
+ );
8372
+ } catch (err) {
8373
+ logger4.error("Failed to start channel connections", {
8374
+ error: err instanceof Error ? err.message : String(err)
8375
+ });
8376
+ }
7798
8377
  }
7799
8378
  const target_port = config?.port || Number(process.env.PORT) || 4001;
7800
8379
  await app.listen({ port: target_port, host: "0.0.0.0" });
7801
- logger3.info(`Lattice Gateway is running on port: ${target_port}`);
8380
+ logger4.info(`Lattice Gateway is running on port: ${target_port}`);
7802
8381
  try {
7803
- logger3.info("AgentLifecycleManager initialized");
8382
+ logger4.info("AgentLifecycleManager initialized");
7804
8383
  } catch (error) {
7805
- logger3.warn("Failed to initialize AgentLifecycleManager", { error });
8384
+ logger4.warn("Failed to initialize AgentLifecycleManager", { error });
7806
8385
  }
7807
8386
  const queueServiceConfig = config?.queueServiceConfig;
7808
8387
  if (queueServiceConfig) {
@@ -7812,15 +8391,13 @@ var start = async (config) => {
7812
8391
  agentTaskConsumer.startPollingQueue();
7813
8392
  }
7814
8393
  }
7815
- try {
7816
- logger3.info("Starting agent instance recovery...");
7817
- const restoreStats = await agentInstanceManager8.restore();
7818
- logger3.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
7819
- } catch (error) {
7820
- logger3.error("Agent recovery failed", { error });
7821
- }
8394
+ agentInstanceManager8.restore().then((stats) => {
8395
+ logger4.info(`Agent recovery complete: ${stats.restored} threads restored, ${stats.errors} errors`);
8396
+ }).catch((error) => {
8397
+ logger4.error("Agent recovery failed", { error });
8398
+ });
7822
8399
  } catch (err) {
7823
- logger3.error("Server start failed", { error: err });
8400
+ logger4.error("Server start failed", { error: err });
7824
8401
  process.exit(1);
7825
8402
  }
7826
8403
  };