@axiom-lattice/gateway 2.1.49 → 2.1.51

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
@@ -240,10 +240,12 @@ var createRun = async (request, reply) => {
240
240
  const {
241
241
  assistant_id,
242
242
  thread_id,
243
+ message_id,
243
244
  command,
244
245
  streaming,
245
246
  background,
246
247
  custom_run_config,
248
+ mode,
247
249
  ...input
248
250
  } = request.body;
249
251
  const tenant_id = request.headers["x-tenant-id"];
@@ -274,11 +276,12 @@ var createRun = async (request, reply) => {
274
276
  "Access-Control-Allow-Origin": "*"
275
277
  });
276
278
  try {
279
+ const messageInput = message_id ? { ...input, id: message_id } : input;
277
280
  const result = await agent.addMessage({
278
- input,
281
+ input: messageInput,
279
282
  command,
280
283
  custom_run_config
281
- });
284
+ }, mode);
282
285
  const stream = agent.chunkStream(result.messageId, [import_protocols.MessageChunkTypes.MESSAGE_COMPLETED]);
283
286
  for await (const chunk of stream) {
284
287
  const success = reply.raw.write(`data: ${JSON.stringify(chunk)}
@@ -594,9 +597,20 @@ function getTenantId2(request) {
594
597
  async function getThreadList(request, reply) {
595
598
  const tenantId = getTenantId2(request);
596
599
  const { assistantId } = request.params;
600
+ const metadataFilter = {};
601
+ if (request.query.workspaceId) {
602
+ metadataFilter.workspaceId = request.query.workspaceId;
603
+ }
604
+ if (request.query.projectId) {
605
+ metadataFilter.projectId = request.query.projectId;
606
+ }
597
607
  const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
598
608
  const threadStore = storeLattice.store;
599
- const threads = await threadStore.getThreadsByAssistantId(tenantId, assistantId);
609
+ const threads = await threadStore.getThreadsByAssistantId(
610
+ tenantId,
611
+ assistantId,
612
+ Object.keys(metadataFilter).length > 0 ? metadataFilter : void 0
613
+ );
600
614
  return {
601
615
  success: true,
602
616
  message: "Successfully retrieved thread list",
@@ -629,9 +643,23 @@ async function createThread(request, reply) {
629
643
  const { assistantId } = request.params;
630
644
  const data = request.body;
631
645
  const threadId = (0, import_crypto2.randomUUID)();
646
+ const workspaceId = request.headers["x-workspace-id"];
647
+ const projectId = request.headers["x-project-id"];
648
+ const enrichedMetadata = {
649
+ ...data.metadata,
650
+ tenantId
651
+ };
652
+ if (workspaceId) {
653
+ enrichedMetadata.workspaceId = workspaceId;
654
+ }
655
+ if (projectId) {
656
+ enrichedMetadata.projectId = projectId;
657
+ }
632
658
  const storeLattice = (0, import_core6.getStoreLattice)("default", "thread");
633
659
  const threadStore = storeLattice.store;
634
- const newThread = await threadStore.createThread(tenantId, assistantId, threadId, data);
660
+ const newThread = await threadStore.createThread(tenantId, assistantId, threadId, {
661
+ metadata: enrichedMetadata
662
+ });
635
663
  return reply.status(201).send({
636
664
  success: true,
637
665
  message: "Successfully created thread",
@@ -2093,11 +2121,58 @@ var getHealthSchema = {
2093
2121
  }
2094
2122
  };
2095
2123
 
2124
+ // src/controllers/thread_status.ts
2125
+ var import_core14 = require("@axiom-lattice/core");
2126
+ async function removePendingMessageHandler(request, reply) {
2127
+ try {
2128
+ const { assistant_id, thread_id, message_id } = request.params;
2129
+ const tenant_id = request.headers["x-tenant-id"];
2130
+ const workspace_id = request.headers["x-workspace-id"];
2131
+ const project_id = request.headers["x-project-id"];
2132
+ if (!tenant_id) {
2133
+ return reply.code(400).send({ error: "Missing x-tenant-id header" });
2134
+ }
2135
+ if (!assistant_id) {
2136
+ return reply.code(400).send({ error: "Missing assistant_id parameter" });
2137
+ }
2138
+ const agent = import_core14.agentInstanceManager.getAgent({
2139
+ assistant_id,
2140
+ thread_id,
2141
+ tenant_id,
2142
+ workspace_id,
2143
+ project_id
2144
+ });
2145
+ if (!agent) {
2146
+ return reply.code(404).send({
2147
+ error: "Thread not found",
2148
+ threadId: thread_id
2149
+ });
2150
+ }
2151
+ const success = await agent.removePendingMessage(message_id);
2152
+ if (!success) {
2153
+ return reply.code(404).send({
2154
+ error: "Message not found",
2155
+ messageId: message_id
2156
+ });
2157
+ }
2158
+ return reply.send({
2159
+ success: true,
2160
+ messageId: message_id
2161
+ });
2162
+ } catch (error) {
2163
+ console.error("Error removing pending message:", error);
2164
+ return reply.code(500).send({
2165
+ error: "Internal server error",
2166
+ message: error instanceof Error ? error.message : String(error)
2167
+ });
2168
+ }
2169
+ }
2170
+
2096
2171
  // src/controllers/sandbox.ts
2097
2172
  var import_stream = require("stream");
2098
2173
 
2099
2174
  // src/services/sandbox_service.ts
2100
- var import_core14 = require("@axiom-lattice/core");
2175
+ var import_core15 = require("@axiom-lattice/core");
2101
2176
  var ERROR_HTML = `<!DOCTYPE html>
2102
2177
  <html lang="zh-CN">
2103
2178
  <head>
@@ -2209,7 +2284,7 @@ var ERROR_HTML = `<!DOCTYPE html>
2209
2284
  </html>`;
2210
2285
  var SandboxService = class {
2211
2286
  getFilesystemIsolatedLevel(tenantId, assistantId) {
2212
- const agentLattice = import_core14.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
2287
+ const agentLattice = import_core15.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
2213
2288
  if (!agentLattice) {
2214
2289
  return null;
2215
2290
  }
@@ -2234,10 +2309,10 @@ var SandboxService = class {
2234
2309
  sandboxName = "global";
2235
2310
  break;
2236
2311
  }
2237
- return (0, import_core14.normalizeSandboxName)(sandboxName);
2312
+ return (0, import_core15.normalizeSandboxName)(sandboxName);
2238
2313
  }
2239
2314
  getTargetUrl(sandboxName) {
2240
- const sandboxManager = (0, import_core14.getSandBoxManager)();
2315
+ const sandboxManager = (0, import_core15.getSandBoxManager)();
2241
2316
  return `${sandboxManager.getBaseURL()}/sandbox/${sandboxName}`;
2242
2317
  }
2243
2318
  async getVncHtml(sandboxName) {
@@ -2282,7 +2357,7 @@ var SandboxService = class {
2282
2357
  var sandboxService = new SandboxService();
2283
2358
 
2284
2359
  // src/controllers/sandbox.ts
2285
- var import_core15 = require("@axiom-lattice/core");
2360
+ var import_core16 = require("@axiom-lattice/core");
2286
2361
  function getFilenameFromPath(path3) {
2287
2362
  const segments = path3.replace(/\/+$/, "").split("/");
2288
2363
  return segments[segments.length - 1] || "download";
@@ -2324,7 +2399,7 @@ function registerSandboxProxyRoutes(app2) {
2324
2399
  threadId,
2325
2400
  isolatedLevel
2326
2401
  );
2327
- const sandboxManager = (0, import_core15.getSandBoxManager)();
2402
+ const sandboxManager = (0, import_core16.getSandBoxManager)();
2328
2403
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2329
2404
  try {
2330
2405
  const data = await request.file();
@@ -2371,7 +2446,7 @@ function registerSandboxProxyRoutes(app2) {
2371
2446
  threadId,
2372
2447
  isolatedLevel
2373
2448
  );
2374
- const sandboxManager = (0, import_core15.getSandBoxManager)();
2449
+ const sandboxManager = (0, import_core16.getSandBoxManager)();
2375
2450
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2376
2451
  try {
2377
2452
  const resolvedPath = filePath.startsWith("/home/gem") ? filePath : `/home/gem/${filePath.replace(/^\//, "")}`;
@@ -2427,14 +2502,14 @@ function registerSandboxProxyRoutes(app2) {
2427
2502
  var fs = __toESM(require("fs/promises"));
2428
2503
  var path = __toESM(require("path"));
2429
2504
  var import_stream2 = require("stream");
2430
- var import_core16 = require("@axiom-lattice/core");
2431
2505
  var import_core17 = require("@axiom-lattice/core");
2432
2506
  var import_core18 = require("@axiom-lattice/core");
2507
+ var import_core19 = require("@axiom-lattice/core");
2433
2508
  var import_uuid2 = require("uuid");
2434
2509
  var WorkspaceController = class {
2435
2510
  constructor() {
2436
- this.workspaceStore = (0, import_core16.getStoreLattice)("default", "workspace").store;
2437
- this.projectStore = (0, import_core16.getStoreLattice)("default", "project").store;
2511
+ this.workspaceStore = (0, import_core17.getStoreLattice)("default", "workspace").store;
2512
+ this.projectStore = (0, import_core17.getStoreLattice)("default", "project").store;
2438
2513
  }
2439
2514
  getTenantId(request) {
2440
2515
  const userTenantId = request.user?.tenantId;
@@ -2567,11 +2642,11 @@ var WorkspaceController = class {
2567
2642
  throw new Error("Workspace not found");
2568
2643
  }
2569
2644
  if (workspace.storageType === "sandbox") {
2570
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2645
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2571
2646
  const sandboxName = "global";
2572
2647
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2573
2648
  return {
2574
- backend: new import_core17.SandboxFilesystem({
2649
+ backend: new import_core18.SandboxFilesystem({
2575
2650
  sandboxInstance: sandbox,
2576
2651
  workingDirectory: `/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`
2577
2652
  }),
@@ -2579,7 +2654,7 @@ var WorkspaceController = class {
2579
2654
  };
2580
2655
  } else {
2581
2656
  return {
2582
- backend: new import_core17.FilesystemBackend({
2657
+ backend: new import_core18.FilesystemBackend({
2583
2658
  rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
2584
2659
  virtualMode: true
2585
2660
  }),
@@ -2624,7 +2699,7 @@ var WorkspaceController = class {
2624
2699
  const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
2625
2700
  const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
2626
2701
  if (workspace.storageType === "sandbox") {
2627
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2702
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2628
2703
  const sandbox = await sandboxManager.createSandbox("global");
2629
2704
  const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
2630
2705
  const filename2 = this.getFilenameFromPath(resolvedPath);
@@ -2693,7 +2768,7 @@ var WorkspaceController = class {
2693
2768
  const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
2694
2769
  const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
2695
2770
  if (workspace.storageType === "sandbox") {
2696
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2771
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2697
2772
  const sandbox = await sandboxManager.createSandbox("global");
2698
2773
  const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
2699
2774
  const filename2 = this.getFilenameFromPath(resolvedPath);
@@ -2863,7 +2938,7 @@ var WorkspaceController = class {
2863
2938
  return reply.status(400).send({ success: false, error: "Invalid path parameter" });
2864
2939
  }
2865
2940
  if (workspace.storageType === "sandbox") {
2866
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2941
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2867
2942
  const sandboxName = "global";
2868
2943
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2869
2944
  const baseDir = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId);
@@ -2969,7 +3044,7 @@ function registerWorkspaceRoutes(app2) {
2969
3044
  }
2970
3045
 
2971
3046
  // src/controllers/database-configs.ts
2972
- var import_core19 = require("@axiom-lattice/core");
3047
+ var import_core20 = require("@axiom-lattice/core");
2973
3048
  var import_crypto3 = require("crypto");
2974
3049
  function getTenantId6(request) {
2975
3050
  const userTenantId = request.user?.tenantId;
@@ -2981,7 +3056,7 @@ function getTenantId6(request) {
2981
3056
  async function getDatabaseConfigList(request, reply) {
2982
3057
  const tenantId = getTenantId6(request);
2983
3058
  try {
2984
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3059
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
2985
3060
  const store = storeLattice.store;
2986
3061
  const configs = await store.getAllConfigs(tenantId);
2987
3062
  console.log("Backend: getAllConfigs returned:", configs);
@@ -3012,7 +3087,7 @@ async function getDatabaseConfig(request, reply) {
3012
3087
  const tenantId = getTenantId6(request);
3013
3088
  const { key } = request.params;
3014
3089
  try {
3015
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3090
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3016
3091
  const store = storeLattice.store;
3017
3092
  const config = await store.getConfigByKey(tenantId, key);
3018
3093
  if (!config) {
@@ -3038,7 +3113,7 @@ async function createDatabaseConfig(request, reply) {
3038
3113
  const tenantId = getTenantId6(request);
3039
3114
  const body = request.body;
3040
3115
  try {
3041
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3116
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3042
3117
  const store = storeLattice.store;
3043
3118
  const existing = await store.getConfigByKey(tenantId, body.key);
3044
3119
  if (existing) {
@@ -3051,7 +3126,7 @@ async function createDatabaseConfig(request, reply) {
3051
3126
  const id = body.id || (0, import_crypto3.randomUUID)();
3052
3127
  const config = await store.createConfig(tenantId, id, body);
3053
3128
  try {
3054
- import_core19.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
3129
+ import_core20.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
3055
3130
  } catch (error) {
3056
3131
  console.warn("Failed to auto-register database:", error);
3057
3132
  }
@@ -3074,7 +3149,7 @@ async function updateDatabaseConfig(request, reply) {
3074
3149
  const { key } = request.params;
3075
3150
  const updates = request.body;
3076
3151
  try {
3077
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3152
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3078
3153
  const store = storeLattice.store;
3079
3154
  const existing = await store.getConfigByKey(tenantId, key);
3080
3155
  if (!existing) {
@@ -3093,7 +3168,7 @@ async function updateDatabaseConfig(request, reply) {
3093
3168
  }
3094
3169
  if (updates.config) {
3095
3170
  try {
3096
- import_core19.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
3171
+ import_core20.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
3097
3172
  } catch (error) {
3098
3173
  console.warn("Failed to re-register database:", error);
3099
3174
  }
@@ -3115,7 +3190,7 @@ async function deleteDatabaseConfig(request, reply) {
3115
3190
  const tenantId = getTenantId6(request);
3116
3191
  const { keyOrId } = request.params;
3117
3192
  try {
3118
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3193
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3119
3194
  const store = storeLattice.store;
3120
3195
  console.log("Delete request - keyOrId:", keyOrId);
3121
3196
  let config = await store.getConfigByKey(tenantId, keyOrId);
@@ -3142,8 +3217,8 @@ async function deleteDatabaseConfig(request, reply) {
3142
3217
  };
3143
3218
  }
3144
3219
  try {
3145
- if (import_core19.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
3146
- await import_core19.sqlDatabaseManager.removeDatabase(tenantId, configKey);
3220
+ if (import_core20.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
3221
+ await import_core20.sqlDatabaseManager.removeDatabase(tenantId, configKey);
3147
3222
  }
3148
3223
  } catch (error) {
3149
3224
  console.warn("Failed to remove from SqlDatabaseManager:", error);
@@ -3164,7 +3239,7 @@ async function testDatabaseConnection(request, reply) {
3164
3239
  const tenantId = getTenantId6(request);
3165
3240
  const { key } = request.params;
3166
3241
  try {
3167
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3242
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3168
3243
  const store = storeLattice.store;
3169
3244
  const config = await store.getConfigByKey(tenantId, key);
3170
3245
  if (!config) {
@@ -3175,16 +3250,16 @@ async function testDatabaseConnection(request, reply) {
3175
3250
  };
3176
3251
  }
3177
3252
  const testKey = `__test_${key}_${Date.now()}`;
3178
- import_core19.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
3253
+ import_core20.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
3179
3254
  const startTime = Date.now();
3180
- const db = await import_core19.sqlDatabaseManager.getDatabase(tenantId, testKey);
3255
+ const db = await import_core20.sqlDatabaseManager.getDatabase(tenantId, testKey);
3181
3256
  try {
3182
3257
  await db.connect();
3183
3258
  await db.listTables();
3184
3259
  const latency = Date.now() - startTime;
3185
3260
  await new Promise((resolve) => setTimeout(resolve, 100));
3186
3261
  await db.disconnect();
3187
- await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3262
+ await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3188
3263
  return {
3189
3264
  success: true,
3190
3265
  message: "Connection test successful",
@@ -3196,7 +3271,7 @@ async function testDatabaseConnection(request, reply) {
3196
3271
  } catch (error) {
3197
3272
  try {
3198
3273
  await db.disconnect();
3199
- await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3274
+ await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3200
3275
  } catch {
3201
3276
  }
3202
3277
  return {
@@ -3248,7 +3323,7 @@ function registerDatabaseConfigRoutes(app2) {
3248
3323
  }
3249
3324
 
3250
3325
  // src/controllers/metrics-configs.ts
3251
- var import_core20 = require("@axiom-lattice/core");
3326
+ var import_core21 = require("@axiom-lattice/core");
3252
3327
  var import_crypto4 = require("crypto");
3253
3328
  function getTenantId7(request) {
3254
3329
  const userTenantId = request.user?.tenantId;
@@ -3260,7 +3335,7 @@ function getTenantId7(request) {
3260
3335
  async function getMetricsServerConfigList(request, reply) {
3261
3336
  const tenantId = getTenantId7(request);
3262
3337
  try {
3263
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3338
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3264
3339
  const store = storeLattice.store;
3265
3340
  const configs = await store.getAllConfigs(tenantId);
3266
3341
  return {
@@ -3287,7 +3362,7 @@ async function getMetricsServerConfig(request, reply) {
3287
3362
  const tenantId = getTenantId7(request);
3288
3363
  const { key } = request.params;
3289
3364
  try {
3290
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3365
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3291
3366
  const store = storeLattice.store;
3292
3367
  const config = await store.getConfigByKey(tenantId, key);
3293
3368
  if (!config) {
@@ -3313,7 +3388,7 @@ async function createMetricsServerConfig(request, reply) {
3313
3388
  const tenantId = getTenantId7(request);
3314
3389
  const body = request.body;
3315
3390
  try {
3316
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3391
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3317
3392
  const store = storeLattice.store;
3318
3393
  const existing = await store.getConfigByKey(tenantId, body.key);
3319
3394
  if (existing) {
@@ -3342,7 +3417,7 @@ async function createMetricsServerConfig(request, reply) {
3342
3417
  };
3343
3418
  const config = await store.createConfig(tenantId, id, configData);
3344
3419
  try {
3345
- import_core20.metricsServerManager.registerServer(tenantId, config.key, config.config);
3420
+ import_core21.metricsServerManager.registerServer(tenantId, config.key, config.config);
3346
3421
  } catch (error) {
3347
3422
  console.warn("Failed to auto-register metrics server:", error);
3348
3423
  }
@@ -3365,7 +3440,7 @@ async function updateMetricsServerConfig(request, reply) {
3365
3440
  const { key } = request.params;
3366
3441
  const updates = request.body;
3367
3442
  try {
3368
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3443
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3369
3444
  const store = storeLattice.store;
3370
3445
  const existing = await store.getConfigByKey(tenantId, key);
3371
3446
  if (!existing) {
@@ -3393,7 +3468,7 @@ async function updateMetricsServerConfig(request, reply) {
3393
3468
  }
3394
3469
  if (updates.config) {
3395
3470
  try {
3396
- import_core20.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
3471
+ import_core21.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
3397
3472
  } catch (error) {
3398
3473
  console.warn("Failed to re-register metrics server:", error);
3399
3474
  }
@@ -3415,7 +3490,7 @@ async function deleteMetricsServerConfig(request, reply) {
3415
3490
  const tenantId = getTenantId7(request);
3416
3491
  const { keyOrId } = request.params;
3417
3492
  try {
3418
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3493
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3419
3494
  const store = storeLattice.store;
3420
3495
  let config = await store.getConfigByKey(tenantId, keyOrId);
3421
3496
  let configKey = keyOrId;
@@ -3440,8 +3515,8 @@ async function deleteMetricsServerConfig(request, reply) {
3440
3515
  };
3441
3516
  }
3442
3517
  try {
3443
- if (import_core20.metricsServerManager.hasServer(tenantId, configKey)) {
3444
- import_core20.metricsServerManager.removeServer(tenantId, configKey);
3518
+ if (import_core21.metricsServerManager.hasServer(tenantId, configKey)) {
3519
+ import_core21.metricsServerManager.removeServer(tenantId, configKey);
3445
3520
  }
3446
3521
  } catch (error) {
3447
3522
  console.warn("Failed to remove from MetricsServerManager:", error);
@@ -3462,7 +3537,7 @@ async function testMetricsServerConnection(request, reply) {
3462
3537
  const tenantId = getTenantId7(request);
3463
3538
  const { key } = request.params;
3464
3539
  try {
3465
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3540
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3466
3541
  const store = storeLattice.store;
3467
3542
  const config = await store.getConfigByKey(tenantId, key);
3468
3543
  if (!config) {
@@ -3473,11 +3548,11 @@ async function testMetricsServerConnection(request, reply) {
3473
3548
  };
3474
3549
  }
3475
3550
  const testKey = `__test_${key}_${Date.now()}`;
3476
- import_core20.metricsServerManager.registerServer(tenantId, testKey, config.config);
3551
+ import_core21.metricsServerManager.registerServer(tenantId, testKey, config.config);
3477
3552
  try {
3478
- const client = import_core20.metricsServerManager.getClient(tenantId, testKey);
3553
+ const client = import_core21.metricsServerManager.getClient(tenantId, testKey);
3479
3554
  const result = await client.testConnection();
3480
- import_core20.metricsServerManager.removeServer(tenantId, testKey);
3555
+ import_core21.metricsServerManager.removeServer(tenantId, testKey);
3481
3556
  return {
3482
3557
  success: true,
3483
3558
  message: result.connected ? "Connection test successful" : "Connection test failed",
@@ -3485,7 +3560,7 @@ async function testMetricsServerConnection(request, reply) {
3485
3560
  };
3486
3561
  } catch (error) {
3487
3562
  try {
3488
- import_core20.metricsServerManager.removeServer(tenantId, testKey);
3563
+ import_core21.metricsServerManager.removeServer(tenantId, testKey);
3489
3564
  } catch {
3490
3565
  }
3491
3566
  return {
@@ -3513,7 +3588,7 @@ async function listAvailableMetrics(request, reply) {
3513
3588
  const tenantId = getTenantId7(request);
3514
3589
  const { key } = request.params;
3515
3590
  try {
3516
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3591
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3517
3592
  const store = storeLattice.store;
3518
3593
  const config = await store.getConfigByKey(tenantId, key);
3519
3594
  if (!config) {
@@ -3523,10 +3598,10 @@ async function listAvailableMetrics(request, reply) {
3523
3598
  message: "Metrics server configuration not found"
3524
3599
  };
3525
3600
  }
3526
- if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
3527
- import_core20.metricsServerManager.registerServer(tenantId, key, config.config);
3601
+ if (!import_core21.metricsServerManager.hasServer(tenantId, key)) {
3602
+ import_core21.metricsServerManager.registerServer(tenantId, key, config.config);
3528
3603
  }
3529
- const client = import_core20.metricsServerManager.getClient(tenantId, key);
3604
+ const client = import_core21.metricsServerManager.getClient(tenantId, key);
3530
3605
  const metrics = await client.listMetrics();
3531
3606
  return {
3532
3607
  success: true,
@@ -3552,7 +3627,7 @@ async function queryMetricsData(request, reply) {
3552
3627
  const { key } = request.params;
3553
3628
  const { metricName, startTime, endTime, step, labels } = request.body;
3554
3629
  try {
3555
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3630
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3556
3631
  const store = storeLattice.store;
3557
3632
  const config = await store.getConfigByKey(tenantId, key);
3558
3633
  if (!config) {
@@ -3569,10 +3644,10 @@ async function queryMetricsData(request, reply) {
3569
3644
  message: "metricName is required"
3570
3645
  };
3571
3646
  }
3572
- if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
3573
- import_core20.metricsServerManager.registerServer(tenantId, key, config.config);
3647
+ if (!import_core21.metricsServerManager.hasServer(tenantId, key)) {
3648
+ import_core21.metricsServerManager.registerServer(tenantId, key, config.config);
3574
3649
  }
3575
- const client = import_core20.metricsServerManager.getClient(tenantId, key);
3650
+ const client = import_core21.metricsServerManager.getClient(tenantId, key);
3576
3651
  const result = await client.queryMetricData(metricName, {
3577
3652
  startTime,
3578
3653
  endTime,
@@ -3599,7 +3674,7 @@ async function getDataSources(request, reply) {
3599
3674
  const tenantId = getTenantId7(request);
3600
3675
  const { key } = request.params;
3601
3676
  try {
3602
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3677
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3603
3678
  const store = storeLattice.store;
3604
3679
  const config = await store.getConfigByKey(tenantId, key);
3605
3680
  if (!config) {
@@ -3617,7 +3692,7 @@ async function getDataSources(request, reply) {
3617
3692
  };
3618
3693
  }
3619
3694
  const semanticConfig = config.config;
3620
- const client = new import_core20.SemanticMetricsClient(semanticConfig);
3695
+ const client = new import_core21.SemanticMetricsClient(semanticConfig);
3621
3696
  const allDatasources = await client.getDataSources();
3622
3697
  const selectedIds = semanticConfig.selectedDataSources || [];
3623
3698
  const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
@@ -3640,7 +3715,7 @@ async function getDatasourceMetrics(request, reply) {
3640
3715
  const tenantId = getTenantId7(request);
3641
3716
  const { key, datasourceId } = request.params;
3642
3717
  try {
3643
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3718
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3644
3719
  const store = storeLattice.store;
3645
3720
  const config = await store.getConfigByKey(tenantId, key);
3646
3721
  if (!config) {
@@ -3658,7 +3733,7 @@ async function getDatasourceMetrics(request, reply) {
3658
3733
  };
3659
3734
  }
3660
3735
  const semanticConfig = config.config;
3661
- const client = new import_core20.SemanticMetricsClient(semanticConfig);
3736
+ const client = new import_core21.SemanticMetricsClient(semanticConfig);
3662
3737
  const metrics = await client.getDatasourceMetrics(datasourceId);
3663
3738
  return {
3664
3739
  success: true,
@@ -3678,7 +3753,7 @@ async function querySemanticMetrics(request, reply) {
3678
3753
  const { key } = request.params;
3679
3754
  const body = request.body;
3680
3755
  try {
3681
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3756
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3682
3757
  const store = storeLattice.store;
3683
3758
  const config = await store.getConfigByKey(tenantId, key);
3684
3759
  if (!config) {
@@ -3703,7 +3778,7 @@ async function querySemanticMetrics(request, reply) {
3703
3778
  };
3704
3779
  }
3705
3780
  const semanticConfig = config.config;
3706
- const client = new import_core20.SemanticMetricsClient(semanticConfig);
3781
+ const client = new import_core21.SemanticMetricsClient(semanticConfig);
3707
3782
  const result = await client.semanticQuery(body);
3708
3783
  const columnNames = result.columns.map((col) => col.name);
3709
3784
  const allDataPoints = [];
@@ -3763,7 +3838,7 @@ async function testSemanticDataSources(request, reply) {
3763
3838
  password: body.password,
3764
3839
  headers: body.headers
3765
3840
  };
3766
- const client = new import_core20.SemanticMetricsClient(testConfig);
3841
+ const client = new import_core21.SemanticMetricsClient(testConfig);
3767
3842
  const datasources = await client.getDataSources();
3768
3843
  return {
3769
3844
  success: true,
@@ -3799,7 +3874,7 @@ async function testDatasourceMetrics(request, reply) {
3799
3874
  password: body.password,
3800
3875
  headers: body.headers
3801
3876
  };
3802
- const client = new import_core20.SemanticMetricsClient(testConfig);
3877
+ const client = new import_core21.SemanticMetricsClient(testConfig);
3803
3878
  const metrics = await client.getDatasourceMetrics(datasourceId);
3804
3879
  return {
3805
3880
  success: true,
@@ -3831,7 +3906,7 @@ function registerMetricsServerConfigRoutes(app2) {
3831
3906
  }
3832
3907
 
3833
3908
  // src/controllers/mcp-configs.ts
3834
- var import_core21 = require("@axiom-lattice/core");
3909
+ var import_core22 = require("@axiom-lattice/core");
3835
3910
  var import_crypto5 = require("crypto");
3836
3911
  function getTenantId8(request) {
3837
3912
  const userTenantId = request.user?.tenantId;
@@ -3843,7 +3918,7 @@ function getTenantId8(request) {
3843
3918
  async function getMcpServerConfigList(request, reply) {
3844
3919
  const tenantId = getTenantId8(request);
3845
3920
  try {
3846
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3921
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3847
3922
  const store = storeLattice.store;
3848
3923
  const configs = await store.getAllConfigs(tenantId);
3849
3924
  return {
@@ -3870,7 +3945,7 @@ async function getMcpServerConfig(request, reply) {
3870
3945
  const tenantId = getTenantId8(request);
3871
3946
  const { key } = request.params;
3872
3947
  try {
3873
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3948
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3874
3949
  const store = storeLattice.store;
3875
3950
  const config = await store.getConfigByKey(tenantId, key);
3876
3951
  if (!config) {
@@ -3896,7 +3971,7 @@ async function createMcpServerConfig(request, reply) {
3896
3971
  const tenantId = getTenantId8(request);
3897
3972
  const body = request.body;
3898
3973
  try {
3899
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3974
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3900
3975
  const store = storeLattice.store;
3901
3976
  const existing = await store.getConfigByKey(tenantId, body.key);
3902
3977
  if (existing) {
@@ -3936,7 +4011,7 @@ async function updateMcpServerConfig(request, reply) {
3936
4011
  const { key } = request.params;
3937
4012
  const updates = request.body;
3938
4013
  try {
3939
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4014
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3940
4015
  const store = storeLattice.store;
3941
4016
  const existing = await store.getConfigByKey(tenantId, key);
3942
4017
  if (!existing) {
@@ -3956,8 +4031,8 @@ async function updateMcpServerConfig(request, reply) {
3956
4031
  }
3957
4032
  if (shouldReconnect) {
3958
4033
  try {
3959
- if (import_core21.mcpManager.hasServer(key)) {
3960
- await import_core21.mcpManager.removeServer(key);
4034
+ if (import_core22.mcpManager.hasServer(key)) {
4035
+ await import_core22.mcpManager.removeServer(key);
3961
4036
  }
3962
4037
  await connectAndRegisterTools(updated);
3963
4038
  await store.updateConfig(tenantId, existing.id, { status: "connected" });
@@ -3985,7 +4060,7 @@ async function deleteMcpServerConfig(request, reply) {
3985
4060
  const tenantId = getTenantId8(request);
3986
4061
  const { keyOrId } = request.params;
3987
4062
  try {
3988
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4063
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3989
4064
  const store = storeLattice.store;
3990
4065
  let config = await store.getConfigByKey(tenantId, keyOrId);
3991
4066
  let configKey = keyOrId;
@@ -4003,8 +4078,8 @@ async function deleteMcpServerConfig(request, reply) {
4003
4078
  };
4004
4079
  }
4005
4080
  try {
4006
- if (import_core21.mcpManager.hasServer(configKey)) {
4007
- await import_core21.mcpManager.removeServer(configKey);
4081
+ if (import_core22.mcpManager.hasServer(configKey)) {
4082
+ await import_core22.mcpManager.removeServer(configKey);
4008
4083
  }
4009
4084
  } catch (error) {
4010
4085
  console.warn("Failed to remove from MCP manager:", error);
@@ -4032,7 +4107,7 @@ async function testMcpServerConnection(request, reply) {
4032
4107
  const tenantId = getTenantId8(request);
4033
4108
  const { key } = request.params;
4034
4109
  try {
4035
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4110
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4036
4111
  const store = storeLattice.store;
4037
4112
  const config = await store.getConfigByKey(tenantId, key);
4038
4113
  if (!config) {
@@ -4046,11 +4121,11 @@ async function testMcpServerConnection(request, reply) {
4046
4121
  try {
4047
4122
  const testKey = `__test_${key}_${Date.now()}`;
4048
4123
  const connection = convertToConnection(config.config);
4049
- import_core21.mcpManager.addServer(testKey, connection);
4050
- await import_core21.mcpManager.connect();
4051
- const tools = await import_core21.mcpManager.getAllTools();
4124
+ import_core22.mcpManager.addServer(testKey, connection);
4125
+ await import_core22.mcpManager.connect();
4126
+ const tools = await import_core22.mcpManager.getAllTools();
4052
4127
  const latency = Date.now() - startTime;
4053
- await import_core21.mcpManager.removeServer(testKey);
4128
+ await import_core22.mcpManager.removeServer(testKey);
4054
4129
  return {
4055
4130
  success: true,
4056
4131
  message: "Connection test successful",
@@ -4085,7 +4160,7 @@ async function listMcpServerTools(request, reply) {
4085
4160
  const tenantId = getTenantId8(request);
4086
4161
  const { key } = request.params;
4087
4162
  try {
4088
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4163
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4089
4164
  const store = storeLattice.store;
4090
4165
  const config = await store.getConfigByKey(tenantId, key);
4091
4166
  if (!config) {
@@ -4095,10 +4170,10 @@ async function listMcpServerTools(request, reply) {
4095
4170
  message: "MCP server configuration not found"
4096
4171
  };
4097
4172
  }
4098
- if (!import_core21.mcpManager.hasServer(key)) {
4173
+ if (!import_core22.mcpManager.hasServer(key)) {
4099
4174
  await connectAndRegisterTools(config);
4100
4175
  }
4101
- const tools = await import_core21.mcpManager.getAllTools();
4176
+ const tools = await import_core22.mcpManager.getAllTools();
4102
4177
  return {
4103
4178
  success: true,
4104
4179
  message: "Tools retrieved successfully",
@@ -4118,7 +4193,7 @@ async function connectMcpServer(request, reply) {
4118
4193
  const tenantId = getTenantId8(request);
4119
4194
  const { key } = request.params;
4120
4195
  try {
4121
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4196
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4122
4197
  const store = storeLattice.store;
4123
4198
  const config = await store.getConfigByKey(tenantId, key);
4124
4199
  if (!config) {
@@ -4139,7 +4214,7 @@ async function connectMcpServer(request, reply) {
4139
4214
  };
4140
4215
  } catch (error) {
4141
4216
  console.error("Failed to connect MCP server:", error);
4142
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4217
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4143
4218
  const store = storeLattice.store;
4144
4219
  const config = await store.getConfigByKey(tenantId, key);
4145
4220
  if (config) {
@@ -4155,7 +4230,7 @@ async function disconnectMcpServer(request, reply) {
4155
4230
  const tenantId = getTenantId8(request);
4156
4231
  const { key } = request.params;
4157
4232
  try {
4158
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4233
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4159
4234
  const store = storeLattice.store;
4160
4235
  const config = await store.getConfigByKey(tenantId, key);
4161
4236
  if (!config) {
@@ -4165,8 +4240,8 @@ async function disconnectMcpServer(request, reply) {
4165
4240
  message: "MCP server configuration not found"
4166
4241
  };
4167
4242
  }
4168
- if (import_core21.mcpManager.hasServer(key)) {
4169
- await import_core21.mcpManager.removeServer(key);
4243
+ if (import_core22.mcpManager.hasServer(key)) {
4244
+ await import_core22.mcpManager.removeServer(key);
4170
4245
  }
4171
4246
  const updated = await store.updateConfig(tenantId, config.id, {
4172
4247
  status: "disconnected"
@@ -4196,10 +4271,10 @@ async function testMcpServerTools(request, reply) {
4196
4271
  }
4197
4272
  const testKey = `__test_${Date.now()}`;
4198
4273
  const connection = convertToConnection(body.config);
4199
- import_core21.mcpManager.addServer(testKey, connection);
4200
- await import_core21.mcpManager.connect();
4201
- const tools = await import_core21.mcpManager.getAllTools();
4202
- await import_core21.mcpManager.removeServer(testKey);
4274
+ import_core22.mcpManager.addServer(testKey, connection);
4275
+ await import_core22.mcpManager.connect();
4276
+ const tools = await import_core22.mcpManager.getAllTools();
4277
+ await import_core22.mcpManager.removeServer(testKey);
4203
4278
  return {
4204
4279
  success: true,
4205
4280
  message: "Tools retrieved successfully",
@@ -4236,14 +4311,14 @@ function convertToConnection(config) {
4236
4311
  }
4237
4312
  async function connectAndRegisterTools(config) {
4238
4313
  const connection = convertToConnection(config.config);
4239
- import_core21.mcpManager.addServer(config.key, connection);
4240
- await import_core21.mcpManager.connect();
4241
- const allTools = await import_core21.mcpManager.getAllTools();
4314
+ import_core22.mcpManager.addServer(config.key, connection);
4315
+ await import_core22.mcpManager.connect();
4316
+ const allTools = await import_core22.mcpManager.getAllTools();
4242
4317
  const selectedTools = allTools.filter(
4243
4318
  (tool) => config.selectedTools.includes(tool.name)
4244
4319
  );
4245
4320
  for (const tool of selectedTools) {
4246
- import_core21.toolLatticeManager.registerExistingTool(tool.name, tool);
4321
+ import_core22.toolLatticeManager.registerExistingTool(tool.name, tool);
4247
4322
  }
4248
4323
  }
4249
4324
  function registerMcpServerConfigRoutes(app2) {
@@ -4260,11 +4335,11 @@ function registerMcpServerConfigRoutes(app2) {
4260
4335
  }
4261
4336
 
4262
4337
  // src/controllers/users.ts
4263
- var import_core22 = require("@axiom-lattice/core");
4338
+ var import_core23 = require("@axiom-lattice/core");
4264
4339
  var import_uuid3 = require("uuid");
4265
4340
  var UsersController = class {
4266
4341
  constructor() {
4267
- this.userStore = (0, import_core22.getStoreLattice)("default", "user").store;
4342
+ this.userStore = (0, import_core23.getStoreLattice)("default", "user").store;
4268
4343
  }
4269
4344
  async listUsers(request, reply) {
4270
4345
  const { email } = request.query;
@@ -4342,11 +4417,11 @@ function registerUserRoutes(app2) {
4342
4417
  }
4343
4418
 
4344
4419
  // src/controllers/tenants.ts
4345
- var import_core23 = require("@axiom-lattice/core");
4420
+ var import_core24 = require("@axiom-lattice/core");
4346
4421
  var import_uuid4 = require("uuid");
4347
4422
  var TenantsController = class {
4348
4423
  constructor() {
4349
- this.tenantStore = (0, import_core23.getStoreLattice)("default", "tenant").store;
4424
+ this.tenantStore = (0, import_core24.getStoreLattice)("default", "tenant").store;
4350
4425
  }
4351
4426
  // ==================== Tenant CRUD ====================
4352
4427
  async listTenants(request, reply) {
@@ -4410,7 +4485,7 @@ function registerTenantRoutes(app2) {
4410
4485
  }
4411
4486
 
4412
4487
  // src/controllers/auth.ts
4413
- var import_core24 = require("@axiom-lattice/core");
4488
+ var import_core25 = require("@axiom-lattice/core");
4414
4489
  var import_uuid5 = require("uuid");
4415
4490
  var defaultAuthConfig = {
4416
4491
  autoApproveUsers: true,
@@ -4419,9 +4494,9 @@ var defaultAuthConfig = {
4419
4494
  };
4420
4495
  var AuthController = class {
4421
4496
  constructor(config = {}) {
4422
- this.userStore = (0, import_core24.getStoreLattice)("default", "user").store;
4423
- this.tenantStore = (0, import_core24.getStoreLattice)("default", "tenant").store;
4424
- this.userTenantLinkStore = (0, import_core24.getStoreLattice)("default", "userTenantLink").store;
4497
+ this.userStore = (0, import_core25.getStoreLattice)("default", "user").store;
4498
+ this.tenantStore = (0, import_core25.getStoreLattice)("default", "tenant").store;
4499
+ this.userTenantLinkStore = (0, import_core25.getStoreLattice)("default", "userTenantLink").store;
4425
4500
  this.config = { ...defaultAuthConfig, ...config };
4426
4501
  }
4427
4502
  async register(request, reply) {
@@ -4696,6 +4771,57 @@ var AuthController = class {
4696
4771
  }
4697
4772
  return btoa(JSON.stringify(payload));
4698
4773
  }
4774
+ async changePassword(request, reply) {
4775
+ const userId = request.user?.id;
4776
+ const { currentPassword, newPassword } = request.body;
4777
+ if (!userId) {
4778
+ return reply.status(401).send({
4779
+ success: false,
4780
+ error: "Unauthorized"
4781
+ });
4782
+ }
4783
+ try {
4784
+ const user = await this.userStore.getUserById(userId);
4785
+ if (!user) {
4786
+ return reply.status(404).send({
4787
+ success: false,
4788
+ error: "User not found"
4789
+ });
4790
+ }
4791
+ const isValidPassword = await this.verifyPassword(
4792
+ currentPassword,
4793
+ user.metadata?.passwordHash || ""
4794
+ );
4795
+ if (!isValidPassword) {
4796
+ return reply.status(401).send({
4797
+ success: false,
4798
+ error: "Current password is incorrect"
4799
+ });
4800
+ }
4801
+ if (newPassword.length < 6) {
4802
+ return reply.status(400).send({
4803
+ success: false,
4804
+ error: "New password must be at least 6 characters"
4805
+ });
4806
+ }
4807
+ await this.userStore.updateUser(userId, {
4808
+ metadata: {
4809
+ ...user.metadata,
4810
+ passwordHash: await this.hashPassword(newPassword)
4811
+ }
4812
+ });
4813
+ return reply.send({
4814
+ success: true,
4815
+ message: "Password changed successfully"
4816
+ });
4817
+ } catch (error) {
4818
+ console.error("Change password error:", error);
4819
+ return reply.status(500).send({
4820
+ success: false,
4821
+ error: "Failed to change password"
4822
+ });
4823
+ }
4824
+ }
4699
4825
  };
4700
4826
  function registerAuthRoutes(app2, config) {
4701
4827
  const controller = new AuthController(config);
@@ -4734,6 +4860,11 @@ function registerAuthRoutes(app2, config) {
4734
4860
  app2.post("/api/auth/approve", { preHandler: authHook }, (req, res) => controller.approveUser(req, res));
4735
4861
  app2.get("/api/auth/pending", { preHandler: authHook }, (req, res) => controller.listPendingUsers(req, res));
4736
4862
  app2.post("/api/auth/assign-tenant", { preHandler: authHook }, (req, res) => controller.assignTenant(req, res));
4863
+ app2.post(
4864
+ "/api/auth/change-password",
4865
+ { preHandler: authHook },
4866
+ (req, res) => controller.changePassword(req, res)
4867
+ );
4737
4868
  }
4738
4869
 
4739
4870
  // src/routes/index.ts
@@ -4870,6 +5001,10 @@ var registerLatticeRoutes = (app2) => {
4870
5001
  autoApproveUsers: process.env.AUTO_APPROVE_USERS !== "false",
4871
5002
  allowTenantRegistration: process.env.ALLOW_TENANT_REGISTRATION !== "false"
4872
5003
  });
5004
+ app2.delete(
5005
+ "/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
5006
+ removePendingMessageHandler
5007
+ );
4873
5008
  };
4874
5009
 
4875
5010
  // src/swagger.ts
@@ -4935,7 +5070,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
4935
5070
  };
4936
5071
 
4937
5072
  // src/services/agent_task_consumer.ts
4938
- var import_core25 = require("@axiom-lattice/core");
5073
+ var import_core26 = require("@axiom-lattice/core");
4939
5074
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
4940
5075
  const {
4941
5076
  assistant_id,
@@ -4950,18 +5085,18 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4950
5085
  console.log(
4951
5086
  `\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
4952
5087
  );
4953
- const agent = import_core25.agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
4954
- await agent.addMessage({ input, command }, import_core25.QueueMode.STEER);
5088
+ const agent = import_core26.agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
5089
+ await agent.addMessage({ input, command, custom_run_config: runConfig }, import_core26.QueueMode.STEER);
4955
5090
  if (callback_event) {
4956
5091
  agent.subscribeOnce("message:completed", (evt) => {
4957
- import_core25.eventBus.publish(callback_event, {
5092
+ import_core26.eventBus.publish(callback_event, {
4958
5093
  success: true,
4959
5094
  state: evt.state,
4960
5095
  config: { assistant_id, thread_id, tenant_id }
4961
5096
  });
4962
5097
  });
4963
5098
  agent.subscribeOnce("message:interrupted", (evt) => {
4964
- import_core25.eventBus.publish(callback_event, {
5099
+ import_core26.eventBus.publish(callback_event, {
4965
5100
  success: true,
4966
5101
  state: evt.state,
4967
5102
  config: { assistant_id, thread_id, tenant_id }
@@ -4985,7 +5120,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4985
5120
  return handleAgentTask(taskRequest, nextRetryCount);
4986
5121
  }
4987
5122
  if (callback_event) {
4988
- import_core25.eventBus.publish(callback_event, {
5123
+ import_core26.eventBus.publish(callback_event, {
4989
5124
  success: false,
4990
5125
  error: error instanceof Error ? error.message : String(error),
4991
5126
  config: { assistant_id, thread_id, tenant_id }
@@ -5023,7 +5158,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
5023
5158
  * 初始化事件监听和队列轮询
5024
5159
  */
5025
5160
  initialize() {
5026
- import_core25.eventBus.subscribe(import_core25.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
5161
+ import_core26.eventBus.subscribe(import_core26.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
5027
5162
  this.startPollingQueue();
5028
5163
  console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
5029
5164
  }
@@ -5142,7 +5277,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
5142
5277
  handleAgentTask(taskRequest).catch((error) => {
5143
5278
  console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
5144
5279
  if (taskRequest.callback_event) {
5145
- import_core25.eventBus.publish(taskRequest.callback_event, {
5280
+ import_core26.eventBus.publish(taskRequest.callback_event, {
5146
5281
  success: false,
5147
5282
  error: error instanceof Error ? error.message : String(error),
5148
5283
  config: {
@@ -5162,7 +5297,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
5162
5297
  var AgentTaskConsumer = _AgentTaskConsumer;
5163
5298
 
5164
5299
  // src/index.ts
5165
- var import_core26 = require("@axiom-lattice/core");
5300
+ var import_core27 = require("@axiom-lattice/core");
5166
5301
  var import_protocols3 = require("@axiom-lattice/protocols");
5167
5302
  process.on("unhandledRejection", (reason, promise) => {
5168
5303
  console.error("\u672A\u5904\u7406\u7684Promise\u62D2\u7EDD:", reason);
@@ -5177,11 +5312,11 @@ var DEFAULT_LOGGER_CONFIG = {
5177
5312
  var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
5178
5313
  var logger = loggerLattice.client;
5179
5314
  function initializeLogger(config) {
5180
- if (import_core26.loggerLatticeManager.hasLattice("default")) {
5181
- import_core26.loggerLatticeManager.removeLattice("default");
5315
+ if (import_core27.loggerLatticeManager.hasLattice("default")) {
5316
+ import_core27.loggerLatticeManager.removeLattice("default");
5182
5317
  }
5183
- (0, import_core26.registerLoggerLattice)("default", config);
5184
- return (0, import_core26.getLoggerLattice)("default");
5318
+ (0, import_core27.registerLoggerLattice)("default", config);
5319
+ return (0, import_core27.getLoggerLattice)("default");
5185
5320
  }
5186
5321
  var app = (0, import_fastify.default)({
5187
5322
  logger: false,
@@ -5189,6 +5324,18 @@ var app = (0, import_fastify.default)({
5189
5324
  bodyLimit: Number(process.env.BODY_LIMIT) || 50 * 1024 * 1024
5190
5325
  // Default 50MB, configurable via BODY_LIMIT env var
5191
5326
  });
5327
+ app.addContentTypeParser("application/json", { parseAs: "string" }, function(request, body, done) {
5328
+ if (request.method === "DELETE" || !body || body.length === 0) {
5329
+ done(null, {});
5330
+ return;
5331
+ }
5332
+ try {
5333
+ const json = JSON.parse(body);
5334
+ done(null, json);
5335
+ } catch (err) {
5336
+ done(err, void 0);
5337
+ }
5338
+ });
5192
5339
  app.addHook("onRequest", (request, reply, done) => {
5193
5340
  const getHeaderValue = (header) => {
5194
5341
  if (Array.isArray(header)) {
@@ -5205,11 +5352,6 @@ app.addHook("onRequest", (request, reply, done) => {
5205
5352
  }
5206
5353
  done();
5207
5354
  });
5208
- app.addHook("onRequest", async (request, reply) => {
5209
- if (request.method === "DELETE" && request.headers["content-type"]) {
5210
- delete request.headers["content-type"];
5211
- }
5212
- });
5213
5355
  app.addHook("onResponse", (request, reply, done) => {
5214
5356
  const getHeaderValue = (header) => {
5215
5357
  if (Array.isArray(header)) {
@@ -5281,16 +5423,16 @@ var start = async (config) => {
5281
5423
  app.decorate("loggerLattice", loggerLattice);
5282
5424
  registerLatticeRoutes(app);
5283
5425
  try {
5284
- const storeLattice = (0, import_core26.getStoreLattice)("default", "database");
5426
+ const storeLattice = (0, import_core27.getStoreLattice)("default", "database");
5285
5427
  const store = storeLattice.store;
5286
- import_core26.sqlDatabaseManager.setConfigStore(store);
5428
+ import_core27.sqlDatabaseManager.setConfigStore(store);
5287
5429
  logger.info("Database config store set for SqlDatabaseManager");
5288
5430
  } catch (error) {
5289
5431
  logger.warn("Failed to set database config store: " + (error instanceof Error ? error.message : String(error)));
5290
5432
  }
5291
- if (!import_core26.sandboxLatticeManager.hasLattice("default")) {
5433
+ if (!import_core27.sandboxLatticeManager.hasLattice("default")) {
5292
5434
  const sandboxBaseURL = process.env.SANDBOX_BASE_URL || "http://localhost:8080";
5293
- import_core26.sandboxLatticeManager.registerLattice("default", {
5435
+ import_core27.sandboxLatticeManager.registerLattice("default", {
5294
5436
  baseURL: sandboxBaseURL
5295
5437
  });
5296
5438
  logger.info(`Registered sandbox manager with baseURL: ${sandboxBaseURL}`);
@@ -5313,7 +5455,7 @@ var start = async (config) => {
5313
5455
  }
5314
5456
  try {
5315
5457
  logger.info("Starting agent instance recovery...");
5316
- const restoreStats = await import_core26.agentInstanceManager.restore();
5458
+ const restoreStats = await import_core27.agentInstanceManager.restore();
5317
5459
  logger.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
5318
5460
  } catch (error) {
5319
5461
  logger.error("Agent recovery failed", { error });