@axiom-lattice/gateway 2.1.48 → 2.1.50

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)}
@@ -349,7 +352,6 @@ var resumeStream = async (request, reply) => {
349
352
  workspace_id,
350
353
  project_id
351
354
  });
352
- console.log("[UI]message_id", message_id);
353
355
  const stream = agent.chunkStream(message_id, [import_protocols.MessageChunkTypes.THREAD_IDLE]);
354
356
  for await (const chunk of stream) {
355
357
  reply.raw.write(`data: ${JSON.stringify(chunk)}
@@ -2094,11 +2096,58 @@ var getHealthSchema = {
2094
2096
  }
2095
2097
  };
2096
2098
 
2099
+ // src/controllers/thread_status.ts
2100
+ var import_core14 = require("@axiom-lattice/core");
2101
+ async function removePendingMessageHandler(request, reply) {
2102
+ try {
2103
+ const { assistant_id, thread_id, message_id } = request.params;
2104
+ const tenant_id = request.headers["x-tenant-id"];
2105
+ const workspace_id = request.headers["x-workspace-id"];
2106
+ const project_id = request.headers["x-project-id"];
2107
+ if (!tenant_id) {
2108
+ return reply.code(400).send({ error: "Missing x-tenant-id header" });
2109
+ }
2110
+ if (!assistant_id) {
2111
+ return reply.code(400).send({ error: "Missing assistant_id parameter" });
2112
+ }
2113
+ const agent = import_core14.agentInstanceManager.getAgent({
2114
+ assistant_id,
2115
+ thread_id,
2116
+ tenant_id,
2117
+ workspace_id,
2118
+ project_id
2119
+ });
2120
+ if (!agent) {
2121
+ return reply.code(404).send({
2122
+ error: "Thread not found",
2123
+ threadId: thread_id
2124
+ });
2125
+ }
2126
+ const success = await agent.removePendingMessage(message_id);
2127
+ if (!success) {
2128
+ return reply.code(404).send({
2129
+ error: "Message not found",
2130
+ messageId: message_id
2131
+ });
2132
+ }
2133
+ return reply.send({
2134
+ success: true,
2135
+ messageId: message_id
2136
+ });
2137
+ } catch (error) {
2138
+ console.error("Error removing pending message:", error);
2139
+ return reply.code(500).send({
2140
+ error: "Internal server error",
2141
+ message: error instanceof Error ? error.message : String(error)
2142
+ });
2143
+ }
2144
+ }
2145
+
2097
2146
  // src/controllers/sandbox.ts
2098
2147
  var import_stream = require("stream");
2099
2148
 
2100
2149
  // src/services/sandbox_service.ts
2101
- var import_core14 = require("@axiom-lattice/core");
2150
+ var import_core15 = require("@axiom-lattice/core");
2102
2151
  var ERROR_HTML = `<!DOCTYPE html>
2103
2152
  <html lang="zh-CN">
2104
2153
  <head>
@@ -2210,7 +2259,7 @@ var ERROR_HTML = `<!DOCTYPE html>
2210
2259
  </html>`;
2211
2260
  var SandboxService = class {
2212
2261
  getFilesystemIsolatedLevel(tenantId, assistantId) {
2213
- const agentLattice = import_core14.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
2262
+ const agentLattice = import_core15.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
2214
2263
  if (!agentLattice) {
2215
2264
  return null;
2216
2265
  }
@@ -2235,10 +2284,10 @@ var SandboxService = class {
2235
2284
  sandboxName = "global";
2236
2285
  break;
2237
2286
  }
2238
- return (0, import_core14.normalizeSandboxName)(sandboxName);
2287
+ return (0, import_core15.normalizeSandboxName)(sandboxName);
2239
2288
  }
2240
2289
  getTargetUrl(sandboxName) {
2241
- const sandboxManager = (0, import_core14.getSandBoxManager)();
2290
+ const sandboxManager = (0, import_core15.getSandBoxManager)();
2242
2291
  return `${sandboxManager.getBaseURL()}/sandbox/${sandboxName}`;
2243
2292
  }
2244
2293
  async getVncHtml(sandboxName) {
@@ -2283,7 +2332,7 @@ var SandboxService = class {
2283
2332
  var sandboxService = new SandboxService();
2284
2333
 
2285
2334
  // src/controllers/sandbox.ts
2286
- var import_core15 = require("@axiom-lattice/core");
2335
+ var import_core16 = require("@axiom-lattice/core");
2287
2336
  function getFilenameFromPath(path3) {
2288
2337
  const segments = path3.replace(/\/+$/, "").split("/");
2289
2338
  return segments[segments.length - 1] || "download";
@@ -2325,7 +2374,7 @@ function registerSandboxProxyRoutes(app2) {
2325
2374
  threadId,
2326
2375
  isolatedLevel
2327
2376
  );
2328
- const sandboxManager = (0, import_core15.getSandBoxManager)();
2377
+ const sandboxManager = (0, import_core16.getSandBoxManager)();
2329
2378
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2330
2379
  try {
2331
2380
  const data = await request.file();
@@ -2372,7 +2421,7 @@ function registerSandboxProxyRoutes(app2) {
2372
2421
  threadId,
2373
2422
  isolatedLevel
2374
2423
  );
2375
- const sandboxManager = (0, import_core15.getSandBoxManager)();
2424
+ const sandboxManager = (0, import_core16.getSandBoxManager)();
2376
2425
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2377
2426
  try {
2378
2427
  const resolvedPath = filePath.startsWith("/home/gem") ? filePath : `/home/gem/${filePath.replace(/^\//, "")}`;
@@ -2428,14 +2477,14 @@ function registerSandboxProxyRoutes(app2) {
2428
2477
  var fs = __toESM(require("fs/promises"));
2429
2478
  var path = __toESM(require("path"));
2430
2479
  var import_stream2 = require("stream");
2431
- var import_core16 = require("@axiom-lattice/core");
2432
2480
  var import_core17 = require("@axiom-lattice/core");
2433
2481
  var import_core18 = require("@axiom-lattice/core");
2482
+ var import_core19 = require("@axiom-lattice/core");
2434
2483
  var import_uuid2 = require("uuid");
2435
2484
  var WorkspaceController = class {
2436
2485
  constructor() {
2437
- this.workspaceStore = (0, import_core16.getStoreLattice)("default", "workspace").store;
2438
- this.projectStore = (0, import_core16.getStoreLattice)("default", "project").store;
2486
+ this.workspaceStore = (0, import_core17.getStoreLattice)("default", "workspace").store;
2487
+ this.projectStore = (0, import_core17.getStoreLattice)("default", "project").store;
2439
2488
  }
2440
2489
  getTenantId(request) {
2441
2490
  const userTenantId = request.user?.tenantId;
@@ -2568,11 +2617,11 @@ var WorkspaceController = class {
2568
2617
  throw new Error("Workspace not found");
2569
2618
  }
2570
2619
  if (workspace.storageType === "sandbox") {
2571
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2620
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2572
2621
  const sandboxName = "global";
2573
2622
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2574
2623
  return {
2575
- backend: new import_core17.SandboxFilesystem({
2624
+ backend: new import_core18.SandboxFilesystem({
2576
2625
  sandboxInstance: sandbox,
2577
2626
  workingDirectory: `/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`
2578
2627
  }),
@@ -2580,7 +2629,7 @@ var WorkspaceController = class {
2580
2629
  };
2581
2630
  } else {
2582
2631
  return {
2583
- backend: new import_core17.FilesystemBackend({
2632
+ backend: new import_core18.FilesystemBackend({
2584
2633
  rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
2585
2634
  virtualMode: true
2586
2635
  }),
@@ -2625,7 +2674,7 @@ var WorkspaceController = class {
2625
2674
  const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
2626
2675
  const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
2627
2676
  if (workspace.storageType === "sandbox") {
2628
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2677
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2629
2678
  const sandbox = await sandboxManager.createSandbox("global");
2630
2679
  const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
2631
2680
  const filename2 = this.getFilenameFromPath(resolvedPath);
@@ -2694,7 +2743,7 @@ var WorkspaceController = class {
2694
2743
  const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
2695
2744
  const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
2696
2745
  if (workspace.storageType === "sandbox") {
2697
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2746
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2698
2747
  const sandbox = await sandboxManager.createSandbox("global");
2699
2748
  const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
2700
2749
  const filename2 = this.getFilenameFromPath(resolvedPath);
@@ -2864,7 +2913,7 @@ var WorkspaceController = class {
2864
2913
  return reply.status(400).send({ success: false, error: "Invalid path parameter" });
2865
2914
  }
2866
2915
  if (workspace.storageType === "sandbox") {
2867
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2916
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2868
2917
  const sandboxName = "global";
2869
2918
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2870
2919
  const baseDir = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId);
@@ -2970,7 +3019,7 @@ function registerWorkspaceRoutes(app2) {
2970
3019
  }
2971
3020
 
2972
3021
  // src/controllers/database-configs.ts
2973
- var import_core19 = require("@axiom-lattice/core");
3022
+ var import_core20 = require("@axiom-lattice/core");
2974
3023
  var import_crypto3 = require("crypto");
2975
3024
  function getTenantId6(request) {
2976
3025
  const userTenantId = request.user?.tenantId;
@@ -2982,7 +3031,7 @@ function getTenantId6(request) {
2982
3031
  async function getDatabaseConfigList(request, reply) {
2983
3032
  const tenantId = getTenantId6(request);
2984
3033
  try {
2985
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3034
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
2986
3035
  const store = storeLattice.store;
2987
3036
  const configs = await store.getAllConfigs(tenantId);
2988
3037
  console.log("Backend: getAllConfigs returned:", configs);
@@ -3013,7 +3062,7 @@ async function getDatabaseConfig(request, reply) {
3013
3062
  const tenantId = getTenantId6(request);
3014
3063
  const { key } = request.params;
3015
3064
  try {
3016
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3065
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3017
3066
  const store = storeLattice.store;
3018
3067
  const config = await store.getConfigByKey(tenantId, key);
3019
3068
  if (!config) {
@@ -3039,7 +3088,7 @@ async function createDatabaseConfig(request, reply) {
3039
3088
  const tenantId = getTenantId6(request);
3040
3089
  const body = request.body;
3041
3090
  try {
3042
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3091
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3043
3092
  const store = storeLattice.store;
3044
3093
  const existing = await store.getConfigByKey(tenantId, body.key);
3045
3094
  if (existing) {
@@ -3052,7 +3101,7 @@ async function createDatabaseConfig(request, reply) {
3052
3101
  const id = body.id || (0, import_crypto3.randomUUID)();
3053
3102
  const config = await store.createConfig(tenantId, id, body);
3054
3103
  try {
3055
- import_core19.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
3104
+ import_core20.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
3056
3105
  } catch (error) {
3057
3106
  console.warn("Failed to auto-register database:", error);
3058
3107
  }
@@ -3075,7 +3124,7 @@ async function updateDatabaseConfig(request, reply) {
3075
3124
  const { key } = request.params;
3076
3125
  const updates = request.body;
3077
3126
  try {
3078
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3127
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3079
3128
  const store = storeLattice.store;
3080
3129
  const existing = await store.getConfigByKey(tenantId, key);
3081
3130
  if (!existing) {
@@ -3094,7 +3143,7 @@ async function updateDatabaseConfig(request, reply) {
3094
3143
  }
3095
3144
  if (updates.config) {
3096
3145
  try {
3097
- import_core19.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
3146
+ import_core20.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
3098
3147
  } catch (error) {
3099
3148
  console.warn("Failed to re-register database:", error);
3100
3149
  }
@@ -3116,7 +3165,7 @@ async function deleteDatabaseConfig(request, reply) {
3116
3165
  const tenantId = getTenantId6(request);
3117
3166
  const { keyOrId } = request.params;
3118
3167
  try {
3119
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3168
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3120
3169
  const store = storeLattice.store;
3121
3170
  console.log("Delete request - keyOrId:", keyOrId);
3122
3171
  let config = await store.getConfigByKey(tenantId, keyOrId);
@@ -3143,8 +3192,8 @@ async function deleteDatabaseConfig(request, reply) {
3143
3192
  };
3144
3193
  }
3145
3194
  try {
3146
- if (import_core19.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
3147
- await import_core19.sqlDatabaseManager.removeDatabase(tenantId, configKey);
3195
+ if (import_core20.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
3196
+ await import_core20.sqlDatabaseManager.removeDatabase(tenantId, configKey);
3148
3197
  }
3149
3198
  } catch (error) {
3150
3199
  console.warn("Failed to remove from SqlDatabaseManager:", error);
@@ -3165,7 +3214,7 @@ async function testDatabaseConnection(request, reply) {
3165
3214
  const tenantId = getTenantId6(request);
3166
3215
  const { key } = request.params;
3167
3216
  try {
3168
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3217
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3169
3218
  const store = storeLattice.store;
3170
3219
  const config = await store.getConfigByKey(tenantId, key);
3171
3220
  if (!config) {
@@ -3176,16 +3225,16 @@ async function testDatabaseConnection(request, reply) {
3176
3225
  };
3177
3226
  }
3178
3227
  const testKey = `__test_${key}_${Date.now()}`;
3179
- import_core19.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
3228
+ import_core20.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
3180
3229
  const startTime = Date.now();
3181
- const db = await import_core19.sqlDatabaseManager.getDatabase(tenantId, testKey);
3230
+ const db = await import_core20.sqlDatabaseManager.getDatabase(tenantId, testKey);
3182
3231
  try {
3183
3232
  await db.connect();
3184
3233
  await db.listTables();
3185
3234
  const latency = Date.now() - startTime;
3186
3235
  await new Promise((resolve) => setTimeout(resolve, 100));
3187
3236
  await db.disconnect();
3188
- await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3237
+ await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3189
3238
  return {
3190
3239
  success: true,
3191
3240
  message: "Connection test successful",
@@ -3197,7 +3246,7 @@ async function testDatabaseConnection(request, reply) {
3197
3246
  } catch (error) {
3198
3247
  try {
3199
3248
  await db.disconnect();
3200
- await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3249
+ await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3201
3250
  } catch {
3202
3251
  }
3203
3252
  return {
@@ -3249,7 +3298,7 @@ function registerDatabaseConfigRoutes(app2) {
3249
3298
  }
3250
3299
 
3251
3300
  // src/controllers/metrics-configs.ts
3252
- var import_core20 = require("@axiom-lattice/core");
3301
+ var import_core21 = require("@axiom-lattice/core");
3253
3302
  var import_crypto4 = require("crypto");
3254
3303
  function getTenantId7(request) {
3255
3304
  const userTenantId = request.user?.tenantId;
@@ -3261,7 +3310,7 @@ function getTenantId7(request) {
3261
3310
  async function getMetricsServerConfigList(request, reply) {
3262
3311
  const tenantId = getTenantId7(request);
3263
3312
  try {
3264
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3313
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3265
3314
  const store = storeLattice.store;
3266
3315
  const configs = await store.getAllConfigs(tenantId);
3267
3316
  return {
@@ -3288,7 +3337,7 @@ async function getMetricsServerConfig(request, reply) {
3288
3337
  const tenantId = getTenantId7(request);
3289
3338
  const { key } = request.params;
3290
3339
  try {
3291
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3340
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3292
3341
  const store = storeLattice.store;
3293
3342
  const config = await store.getConfigByKey(tenantId, key);
3294
3343
  if (!config) {
@@ -3314,7 +3363,7 @@ async function createMetricsServerConfig(request, reply) {
3314
3363
  const tenantId = getTenantId7(request);
3315
3364
  const body = request.body;
3316
3365
  try {
3317
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3366
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3318
3367
  const store = storeLattice.store;
3319
3368
  const existing = await store.getConfigByKey(tenantId, body.key);
3320
3369
  if (existing) {
@@ -3343,7 +3392,7 @@ async function createMetricsServerConfig(request, reply) {
3343
3392
  };
3344
3393
  const config = await store.createConfig(tenantId, id, configData);
3345
3394
  try {
3346
- import_core20.metricsServerManager.registerServer(tenantId, config.key, config.config);
3395
+ import_core21.metricsServerManager.registerServer(tenantId, config.key, config.config);
3347
3396
  } catch (error) {
3348
3397
  console.warn("Failed to auto-register metrics server:", error);
3349
3398
  }
@@ -3366,7 +3415,7 @@ async function updateMetricsServerConfig(request, reply) {
3366
3415
  const { key } = request.params;
3367
3416
  const updates = request.body;
3368
3417
  try {
3369
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3418
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3370
3419
  const store = storeLattice.store;
3371
3420
  const existing = await store.getConfigByKey(tenantId, key);
3372
3421
  if (!existing) {
@@ -3394,7 +3443,7 @@ async function updateMetricsServerConfig(request, reply) {
3394
3443
  }
3395
3444
  if (updates.config) {
3396
3445
  try {
3397
- import_core20.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
3446
+ import_core21.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
3398
3447
  } catch (error) {
3399
3448
  console.warn("Failed to re-register metrics server:", error);
3400
3449
  }
@@ -3416,7 +3465,7 @@ async function deleteMetricsServerConfig(request, reply) {
3416
3465
  const tenantId = getTenantId7(request);
3417
3466
  const { keyOrId } = request.params;
3418
3467
  try {
3419
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3468
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3420
3469
  const store = storeLattice.store;
3421
3470
  let config = await store.getConfigByKey(tenantId, keyOrId);
3422
3471
  let configKey = keyOrId;
@@ -3441,8 +3490,8 @@ async function deleteMetricsServerConfig(request, reply) {
3441
3490
  };
3442
3491
  }
3443
3492
  try {
3444
- if (import_core20.metricsServerManager.hasServer(tenantId, configKey)) {
3445
- import_core20.metricsServerManager.removeServer(tenantId, configKey);
3493
+ if (import_core21.metricsServerManager.hasServer(tenantId, configKey)) {
3494
+ import_core21.metricsServerManager.removeServer(tenantId, configKey);
3446
3495
  }
3447
3496
  } catch (error) {
3448
3497
  console.warn("Failed to remove from MetricsServerManager:", error);
@@ -3463,7 +3512,7 @@ async function testMetricsServerConnection(request, reply) {
3463
3512
  const tenantId = getTenantId7(request);
3464
3513
  const { key } = request.params;
3465
3514
  try {
3466
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3515
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3467
3516
  const store = storeLattice.store;
3468
3517
  const config = await store.getConfigByKey(tenantId, key);
3469
3518
  if (!config) {
@@ -3474,11 +3523,11 @@ async function testMetricsServerConnection(request, reply) {
3474
3523
  };
3475
3524
  }
3476
3525
  const testKey = `__test_${key}_${Date.now()}`;
3477
- import_core20.metricsServerManager.registerServer(tenantId, testKey, config.config);
3526
+ import_core21.metricsServerManager.registerServer(tenantId, testKey, config.config);
3478
3527
  try {
3479
- const client = import_core20.metricsServerManager.getClient(tenantId, testKey);
3528
+ const client = import_core21.metricsServerManager.getClient(tenantId, testKey);
3480
3529
  const result = await client.testConnection();
3481
- import_core20.metricsServerManager.removeServer(tenantId, testKey);
3530
+ import_core21.metricsServerManager.removeServer(tenantId, testKey);
3482
3531
  return {
3483
3532
  success: true,
3484
3533
  message: result.connected ? "Connection test successful" : "Connection test failed",
@@ -3486,7 +3535,7 @@ async function testMetricsServerConnection(request, reply) {
3486
3535
  };
3487
3536
  } catch (error) {
3488
3537
  try {
3489
- import_core20.metricsServerManager.removeServer(tenantId, testKey);
3538
+ import_core21.metricsServerManager.removeServer(tenantId, testKey);
3490
3539
  } catch {
3491
3540
  }
3492
3541
  return {
@@ -3514,7 +3563,7 @@ async function listAvailableMetrics(request, reply) {
3514
3563
  const tenantId = getTenantId7(request);
3515
3564
  const { key } = request.params;
3516
3565
  try {
3517
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3566
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3518
3567
  const store = storeLattice.store;
3519
3568
  const config = await store.getConfigByKey(tenantId, key);
3520
3569
  if (!config) {
@@ -3524,10 +3573,10 @@ async function listAvailableMetrics(request, reply) {
3524
3573
  message: "Metrics server configuration not found"
3525
3574
  };
3526
3575
  }
3527
- if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
3528
- import_core20.metricsServerManager.registerServer(tenantId, key, config.config);
3576
+ if (!import_core21.metricsServerManager.hasServer(tenantId, key)) {
3577
+ import_core21.metricsServerManager.registerServer(tenantId, key, config.config);
3529
3578
  }
3530
- const client = import_core20.metricsServerManager.getClient(tenantId, key);
3579
+ const client = import_core21.metricsServerManager.getClient(tenantId, key);
3531
3580
  const metrics = await client.listMetrics();
3532
3581
  return {
3533
3582
  success: true,
@@ -3553,7 +3602,7 @@ async function queryMetricsData(request, reply) {
3553
3602
  const { key } = request.params;
3554
3603
  const { metricName, startTime, endTime, step, labels } = request.body;
3555
3604
  try {
3556
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3605
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3557
3606
  const store = storeLattice.store;
3558
3607
  const config = await store.getConfigByKey(tenantId, key);
3559
3608
  if (!config) {
@@ -3570,10 +3619,10 @@ async function queryMetricsData(request, reply) {
3570
3619
  message: "metricName is required"
3571
3620
  };
3572
3621
  }
3573
- if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
3574
- import_core20.metricsServerManager.registerServer(tenantId, key, config.config);
3622
+ if (!import_core21.metricsServerManager.hasServer(tenantId, key)) {
3623
+ import_core21.metricsServerManager.registerServer(tenantId, key, config.config);
3575
3624
  }
3576
- const client = import_core20.metricsServerManager.getClient(tenantId, key);
3625
+ const client = import_core21.metricsServerManager.getClient(tenantId, key);
3577
3626
  const result = await client.queryMetricData(metricName, {
3578
3627
  startTime,
3579
3628
  endTime,
@@ -3600,7 +3649,7 @@ async function getDataSources(request, reply) {
3600
3649
  const tenantId = getTenantId7(request);
3601
3650
  const { key } = request.params;
3602
3651
  try {
3603
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3652
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3604
3653
  const store = storeLattice.store;
3605
3654
  const config = await store.getConfigByKey(tenantId, key);
3606
3655
  if (!config) {
@@ -3618,7 +3667,7 @@ async function getDataSources(request, reply) {
3618
3667
  };
3619
3668
  }
3620
3669
  const semanticConfig = config.config;
3621
- const client = new import_core20.SemanticMetricsClient(semanticConfig);
3670
+ const client = new import_core21.SemanticMetricsClient(semanticConfig);
3622
3671
  const allDatasources = await client.getDataSources();
3623
3672
  const selectedIds = semanticConfig.selectedDataSources || [];
3624
3673
  const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
@@ -3641,7 +3690,7 @@ async function getDatasourceMetrics(request, reply) {
3641
3690
  const tenantId = getTenantId7(request);
3642
3691
  const { key, datasourceId } = request.params;
3643
3692
  try {
3644
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3693
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3645
3694
  const store = storeLattice.store;
3646
3695
  const config = await store.getConfigByKey(tenantId, key);
3647
3696
  if (!config) {
@@ -3659,7 +3708,7 @@ async function getDatasourceMetrics(request, reply) {
3659
3708
  };
3660
3709
  }
3661
3710
  const semanticConfig = config.config;
3662
- const client = new import_core20.SemanticMetricsClient(semanticConfig);
3711
+ const client = new import_core21.SemanticMetricsClient(semanticConfig);
3663
3712
  const metrics = await client.getDatasourceMetrics(datasourceId);
3664
3713
  return {
3665
3714
  success: true,
@@ -3679,7 +3728,7 @@ async function querySemanticMetrics(request, reply) {
3679
3728
  const { key } = request.params;
3680
3729
  const body = request.body;
3681
3730
  try {
3682
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3731
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3683
3732
  const store = storeLattice.store;
3684
3733
  const config = await store.getConfigByKey(tenantId, key);
3685
3734
  if (!config) {
@@ -3704,7 +3753,7 @@ async function querySemanticMetrics(request, reply) {
3704
3753
  };
3705
3754
  }
3706
3755
  const semanticConfig = config.config;
3707
- const client = new import_core20.SemanticMetricsClient(semanticConfig);
3756
+ const client = new import_core21.SemanticMetricsClient(semanticConfig);
3708
3757
  const result = await client.semanticQuery(body);
3709
3758
  const columnNames = result.columns.map((col) => col.name);
3710
3759
  const allDataPoints = [];
@@ -3764,7 +3813,7 @@ async function testSemanticDataSources(request, reply) {
3764
3813
  password: body.password,
3765
3814
  headers: body.headers
3766
3815
  };
3767
- const client = new import_core20.SemanticMetricsClient(testConfig);
3816
+ const client = new import_core21.SemanticMetricsClient(testConfig);
3768
3817
  const datasources = await client.getDataSources();
3769
3818
  return {
3770
3819
  success: true,
@@ -3800,7 +3849,7 @@ async function testDatasourceMetrics(request, reply) {
3800
3849
  password: body.password,
3801
3850
  headers: body.headers
3802
3851
  };
3803
- const client = new import_core20.SemanticMetricsClient(testConfig);
3852
+ const client = new import_core21.SemanticMetricsClient(testConfig);
3804
3853
  const metrics = await client.getDatasourceMetrics(datasourceId);
3805
3854
  return {
3806
3855
  success: true,
@@ -3832,7 +3881,7 @@ function registerMetricsServerConfigRoutes(app2) {
3832
3881
  }
3833
3882
 
3834
3883
  // src/controllers/mcp-configs.ts
3835
- var import_core21 = require("@axiom-lattice/core");
3884
+ var import_core22 = require("@axiom-lattice/core");
3836
3885
  var import_crypto5 = require("crypto");
3837
3886
  function getTenantId8(request) {
3838
3887
  const userTenantId = request.user?.tenantId;
@@ -3844,7 +3893,7 @@ function getTenantId8(request) {
3844
3893
  async function getMcpServerConfigList(request, reply) {
3845
3894
  const tenantId = getTenantId8(request);
3846
3895
  try {
3847
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3896
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3848
3897
  const store = storeLattice.store;
3849
3898
  const configs = await store.getAllConfigs(tenantId);
3850
3899
  return {
@@ -3871,7 +3920,7 @@ async function getMcpServerConfig(request, reply) {
3871
3920
  const tenantId = getTenantId8(request);
3872
3921
  const { key } = request.params;
3873
3922
  try {
3874
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3923
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3875
3924
  const store = storeLattice.store;
3876
3925
  const config = await store.getConfigByKey(tenantId, key);
3877
3926
  if (!config) {
@@ -3897,7 +3946,7 @@ async function createMcpServerConfig(request, reply) {
3897
3946
  const tenantId = getTenantId8(request);
3898
3947
  const body = request.body;
3899
3948
  try {
3900
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3949
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3901
3950
  const store = storeLattice.store;
3902
3951
  const existing = await store.getConfigByKey(tenantId, body.key);
3903
3952
  if (existing) {
@@ -3937,7 +3986,7 @@ async function updateMcpServerConfig(request, reply) {
3937
3986
  const { key } = request.params;
3938
3987
  const updates = request.body;
3939
3988
  try {
3940
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3989
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3941
3990
  const store = storeLattice.store;
3942
3991
  const existing = await store.getConfigByKey(tenantId, key);
3943
3992
  if (!existing) {
@@ -3957,8 +4006,8 @@ async function updateMcpServerConfig(request, reply) {
3957
4006
  }
3958
4007
  if (shouldReconnect) {
3959
4008
  try {
3960
- if (import_core21.mcpManager.hasServer(key)) {
3961
- await import_core21.mcpManager.removeServer(key);
4009
+ if (import_core22.mcpManager.hasServer(key)) {
4010
+ await import_core22.mcpManager.removeServer(key);
3962
4011
  }
3963
4012
  await connectAndRegisterTools(updated);
3964
4013
  await store.updateConfig(tenantId, existing.id, { status: "connected" });
@@ -3986,7 +4035,7 @@ async function deleteMcpServerConfig(request, reply) {
3986
4035
  const tenantId = getTenantId8(request);
3987
4036
  const { keyOrId } = request.params;
3988
4037
  try {
3989
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4038
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3990
4039
  const store = storeLattice.store;
3991
4040
  let config = await store.getConfigByKey(tenantId, keyOrId);
3992
4041
  let configKey = keyOrId;
@@ -4004,8 +4053,8 @@ async function deleteMcpServerConfig(request, reply) {
4004
4053
  };
4005
4054
  }
4006
4055
  try {
4007
- if (import_core21.mcpManager.hasServer(configKey)) {
4008
- await import_core21.mcpManager.removeServer(configKey);
4056
+ if (import_core22.mcpManager.hasServer(configKey)) {
4057
+ await import_core22.mcpManager.removeServer(configKey);
4009
4058
  }
4010
4059
  } catch (error) {
4011
4060
  console.warn("Failed to remove from MCP manager:", error);
@@ -4033,7 +4082,7 @@ async function testMcpServerConnection(request, reply) {
4033
4082
  const tenantId = getTenantId8(request);
4034
4083
  const { key } = request.params;
4035
4084
  try {
4036
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4085
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4037
4086
  const store = storeLattice.store;
4038
4087
  const config = await store.getConfigByKey(tenantId, key);
4039
4088
  if (!config) {
@@ -4047,11 +4096,11 @@ async function testMcpServerConnection(request, reply) {
4047
4096
  try {
4048
4097
  const testKey = `__test_${key}_${Date.now()}`;
4049
4098
  const connection = convertToConnection(config.config);
4050
- import_core21.mcpManager.addServer(testKey, connection);
4051
- await import_core21.mcpManager.connect();
4052
- const tools = await import_core21.mcpManager.getAllTools();
4099
+ import_core22.mcpManager.addServer(testKey, connection);
4100
+ await import_core22.mcpManager.connect();
4101
+ const tools = await import_core22.mcpManager.getAllTools();
4053
4102
  const latency = Date.now() - startTime;
4054
- await import_core21.mcpManager.removeServer(testKey);
4103
+ await import_core22.mcpManager.removeServer(testKey);
4055
4104
  return {
4056
4105
  success: true,
4057
4106
  message: "Connection test successful",
@@ -4086,7 +4135,7 @@ async function listMcpServerTools(request, reply) {
4086
4135
  const tenantId = getTenantId8(request);
4087
4136
  const { key } = request.params;
4088
4137
  try {
4089
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4138
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4090
4139
  const store = storeLattice.store;
4091
4140
  const config = await store.getConfigByKey(tenantId, key);
4092
4141
  if (!config) {
@@ -4096,10 +4145,10 @@ async function listMcpServerTools(request, reply) {
4096
4145
  message: "MCP server configuration not found"
4097
4146
  };
4098
4147
  }
4099
- if (!import_core21.mcpManager.hasServer(key)) {
4148
+ if (!import_core22.mcpManager.hasServer(key)) {
4100
4149
  await connectAndRegisterTools(config);
4101
4150
  }
4102
- const tools = await import_core21.mcpManager.getAllTools();
4151
+ const tools = await import_core22.mcpManager.getAllTools();
4103
4152
  return {
4104
4153
  success: true,
4105
4154
  message: "Tools retrieved successfully",
@@ -4119,7 +4168,7 @@ async function connectMcpServer(request, reply) {
4119
4168
  const tenantId = getTenantId8(request);
4120
4169
  const { key } = request.params;
4121
4170
  try {
4122
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4171
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4123
4172
  const store = storeLattice.store;
4124
4173
  const config = await store.getConfigByKey(tenantId, key);
4125
4174
  if (!config) {
@@ -4140,7 +4189,7 @@ async function connectMcpServer(request, reply) {
4140
4189
  };
4141
4190
  } catch (error) {
4142
4191
  console.error("Failed to connect MCP server:", error);
4143
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4192
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4144
4193
  const store = storeLattice.store;
4145
4194
  const config = await store.getConfigByKey(tenantId, key);
4146
4195
  if (config) {
@@ -4156,7 +4205,7 @@ async function disconnectMcpServer(request, reply) {
4156
4205
  const tenantId = getTenantId8(request);
4157
4206
  const { key } = request.params;
4158
4207
  try {
4159
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4208
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4160
4209
  const store = storeLattice.store;
4161
4210
  const config = await store.getConfigByKey(tenantId, key);
4162
4211
  if (!config) {
@@ -4166,8 +4215,8 @@ async function disconnectMcpServer(request, reply) {
4166
4215
  message: "MCP server configuration not found"
4167
4216
  };
4168
4217
  }
4169
- if (import_core21.mcpManager.hasServer(key)) {
4170
- await import_core21.mcpManager.removeServer(key);
4218
+ if (import_core22.mcpManager.hasServer(key)) {
4219
+ await import_core22.mcpManager.removeServer(key);
4171
4220
  }
4172
4221
  const updated = await store.updateConfig(tenantId, config.id, {
4173
4222
  status: "disconnected"
@@ -4197,10 +4246,10 @@ async function testMcpServerTools(request, reply) {
4197
4246
  }
4198
4247
  const testKey = `__test_${Date.now()}`;
4199
4248
  const connection = convertToConnection(body.config);
4200
- import_core21.mcpManager.addServer(testKey, connection);
4201
- await import_core21.mcpManager.connect();
4202
- const tools = await import_core21.mcpManager.getAllTools();
4203
- await import_core21.mcpManager.removeServer(testKey);
4249
+ import_core22.mcpManager.addServer(testKey, connection);
4250
+ await import_core22.mcpManager.connect();
4251
+ const tools = await import_core22.mcpManager.getAllTools();
4252
+ await import_core22.mcpManager.removeServer(testKey);
4204
4253
  return {
4205
4254
  success: true,
4206
4255
  message: "Tools retrieved successfully",
@@ -4237,14 +4286,14 @@ function convertToConnection(config) {
4237
4286
  }
4238
4287
  async function connectAndRegisterTools(config) {
4239
4288
  const connection = convertToConnection(config.config);
4240
- import_core21.mcpManager.addServer(config.key, connection);
4241
- await import_core21.mcpManager.connect();
4242
- const allTools = await import_core21.mcpManager.getAllTools();
4289
+ import_core22.mcpManager.addServer(config.key, connection);
4290
+ await import_core22.mcpManager.connect();
4291
+ const allTools = await import_core22.mcpManager.getAllTools();
4243
4292
  const selectedTools = allTools.filter(
4244
4293
  (tool) => config.selectedTools.includes(tool.name)
4245
4294
  );
4246
4295
  for (const tool of selectedTools) {
4247
- import_core21.toolLatticeManager.registerExistingTool(tool.name, tool);
4296
+ import_core22.toolLatticeManager.registerExistingTool(tool.name, tool);
4248
4297
  }
4249
4298
  }
4250
4299
  function registerMcpServerConfigRoutes(app2) {
@@ -4261,11 +4310,11 @@ function registerMcpServerConfigRoutes(app2) {
4261
4310
  }
4262
4311
 
4263
4312
  // src/controllers/users.ts
4264
- var import_core22 = require("@axiom-lattice/core");
4313
+ var import_core23 = require("@axiom-lattice/core");
4265
4314
  var import_uuid3 = require("uuid");
4266
4315
  var UsersController = class {
4267
4316
  constructor() {
4268
- this.userStore = (0, import_core22.getStoreLattice)("default", "user").store;
4317
+ this.userStore = (0, import_core23.getStoreLattice)("default", "user").store;
4269
4318
  }
4270
4319
  async listUsers(request, reply) {
4271
4320
  const { email } = request.query;
@@ -4343,11 +4392,11 @@ function registerUserRoutes(app2) {
4343
4392
  }
4344
4393
 
4345
4394
  // src/controllers/tenants.ts
4346
- var import_core23 = require("@axiom-lattice/core");
4395
+ var import_core24 = require("@axiom-lattice/core");
4347
4396
  var import_uuid4 = require("uuid");
4348
4397
  var TenantsController = class {
4349
4398
  constructor() {
4350
- this.tenantStore = (0, import_core23.getStoreLattice)("default", "tenant").store;
4399
+ this.tenantStore = (0, import_core24.getStoreLattice)("default", "tenant").store;
4351
4400
  }
4352
4401
  // ==================== Tenant CRUD ====================
4353
4402
  async listTenants(request, reply) {
@@ -4411,7 +4460,7 @@ function registerTenantRoutes(app2) {
4411
4460
  }
4412
4461
 
4413
4462
  // src/controllers/auth.ts
4414
- var import_core24 = require("@axiom-lattice/core");
4463
+ var import_core25 = require("@axiom-lattice/core");
4415
4464
  var import_uuid5 = require("uuid");
4416
4465
  var defaultAuthConfig = {
4417
4466
  autoApproveUsers: true,
@@ -4420,9 +4469,9 @@ var defaultAuthConfig = {
4420
4469
  };
4421
4470
  var AuthController = class {
4422
4471
  constructor(config = {}) {
4423
- this.userStore = (0, import_core24.getStoreLattice)("default", "user").store;
4424
- this.tenantStore = (0, import_core24.getStoreLattice)("default", "tenant").store;
4425
- this.userTenantLinkStore = (0, import_core24.getStoreLattice)("default", "userTenantLink").store;
4472
+ this.userStore = (0, import_core25.getStoreLattice)("default", "user").store;
4473
+ this.tenantStore = (0, import_core25.getStoreLattice)("default", "tenant").store;
4474
+ this.userTenantLinkStore = (0, import_core25.getStoreLattice)("default", "userTenantLink").store;
4426
4475
  this.config = { ...defaultAuthConfig, ...config };
4427
4476
  }
4428
4477
  async register(request, reply) {
@@ -4697,6 +4746,57 @@ var AuthController = class {
4697
4746
  }
4698
4747
  return btoa(JSON.stringify(payload));
4699
4748
  }
4749
+ async changePassword(request, reply) {
4750
+ const userId = request.user?.id;
4751
+ const { currentPassword, newPassword } = request.body;
4752
+ if (!userId) {
4753
+ return reply.status(401).send({
4754
+ success: false,
4755
+ error: "Unauthorized"
4756
+ });
4757
+ }
4758
+ try {
4759
+ const user = await this.userStore.getUserById(userId);
4760
+ if (!user) {
4761
+ return reply.status(404).send({
4762
+ success: false,
4763
+ error: "User not found"
4764
+ });
4765
+ }
4766
+ const isValidPassword = await this.verifyPassword(
4767
+ currentPassword,
4768
+ user.metadata?.passwordHash || ""
4769
+ );
4770
+ if (!isValidPassword) {
4771
+ return reply.status(401).send({
4772
+ success: false,
4773
+ error: "Current password is incorrect"
4774
+ });
4775
+ }
4776
+ if (newPassword.length < 6) {
4777
+ return reply.status(400).send({
4778
+ success: false,
4779
+ error: "New password must be at least 6 characters"
4780
+ });
4781
+ }
4782
+ await this.userStore.updateUser(userId, {
4783
+ metadata: {
4784
+ ...user.metadata,
4785
+ passwordHash: await this.hashPassword(newPassword)
4786
+ }
4787
+ });
4788
+ return reply.send({
4789
+ success: true,
4790
+ message: "Password changed successfully"
4791
+ });
4792
+ } catch (error) {
4793
+ console.error("Change password error:", error);
4794
+ return reply.status(500).send({
4795
+ success: false,
4796
+ error: "Failed to change password"
4797
+ });
4798
+ }
4799
+ }
4700
4800
  };
4701
4801
  function registerAuthRoutes(app2, config) {
4702
4802
  const controller = new AuthController(config);
@@ -4735,6 +4835,11 @@ function registerAuthRoutes(app2, config) {
4735
4835
  app2.post("/api/auth/approve", { preHandler: authHook }, (req, res) => controller.approveUser(req, res));
4736
4836
  app2.get("/api/auth/pending", { preHandler: authHook }, (req, res) => controller.listPendingUsers(req, res));
4737
4837
  app2.post("/api/auth/assign-tenant", { preHandler: authHook }, (req, res) => controller.assignTenant(req, res));
4838
+ app2.post(
4839
+ "/api/auth/change-password",
4840
+ { preHandler: authHook },
4841
+ (req, res) => controller.changePassword(req, res)
4842
+ );
4738
4843
  }
4739
4844
 
4740
4845
  // src/routes/index.ts
@@ -4871,6 +4976,10 @@ var registerLatticeRoutes = (app2) => {
4871
4976
  autoApproveUsers: process.env.AUTO_APPROVE_USERS !== "false",
4872
4977
  allowTenantRegistration: process.env.ALLOW_TENANT_REGISTRATION !== "false"
4873
4978
  });
4979
+ app2.delete(
4980
+ "/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
4981
+ removePendingMessageHandler
4982
+ );
4874
4983
  };
4875
4984
 
4876
4985
  // src/swagger.ts
@@ -4936,7 +5045,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
4936
5045
  };
4937
5046
 
4938
5047
  // src/services/agent_task_consumer.ts
4939
- var import_core25 = require("@axiom-lattice/core");
5048
+ var import_core26 = require("@axiom-lattice/core");
4940
5049
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
4941
5050
  const {
4942
5051
  assistant_id,
@@ -4951,13 +5060,18 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4951
5060
  console.log(
4952
5061
  `\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
4953
5062
  );
4954
- const apiUrl = AgentTaskConsumer.agent_run_endpoint;
4955
- console.log(`apiUrl: ${apiUrl}`);
4956
- const agent = import_core25.agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
4957
- await agent.addMessage({ input, command }, import_core25.QueueMode.STEER);
5063
+ const agent = import_core26.agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
5064
+ await agent.addMessage({ input, command }, import_core26.QueueMode.STEER);
4958
5065
  if (callback_event) {
4959
5066
  agent.subscribeOnce("message:completed", (evt) => {
4960
- import_core25.eventBus.publish(callback_event, {
5067
+ import_core26.eventBus.publish(callback_event, {
5068
+ success: true,
5069
+ state: evt.state,
5070
+ config: { assistant_id, thread_id, tenant_id }
5071
+ });
5072
+ });
5073
+ agent.subscribeOnce("message:interrupted", (evt) => {
5074
+ import_core26.eventBus.publish(callback_event, {
4961
5075
  success: true,
4962
5076
  state: evt.state,
4963
5077
  config: { assistant_id, thread_id, tenant_id }
@@ -4981,7 +5095,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4981
5095
  return handleAgentTask(taskRequest, nextRetryCount);
4982
5096
  }
4983
5097
  if (callback_event) {
4984
- import_core25.eventBus.publish(callback_event, {
5098
+ import_core26.eventBus.publish(callback_event, {
4985
5099
  success: false,
4986
5100
  error: error instanceof Error ? error.message : String(error),
4987
5101
  config: { assistant_id, thread_id, tenant_id }
@@ -5019,7 +5133,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
5019
5133
  * 初始化事件监听和队列轮询
5020
5134
  */
5021
5135
  initialize() {
5022
- import_core25.eventBus.subscribe(import_core25.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
5136
+ import_core26.eventBus.subscribe(import_core26.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
5023
5137
  this.startPollingQueue();
5024
5138
  console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
5025
5139
  }
@@ -5138,7 +5252,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
5138
5252
  handleAgentTask(taskRequest).catch((error) => {
5139
5253
  console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
5140
5254
  if (taskRequest.callback_event) {
5141
- import_core25.eventBus.publish(taskRequest.callback_event, {
5255
+ import_core26.eventBus.publish(taskRequest.callback_event, {
5142
5256
  success: false,
5143
5257
  error: error instanceof Error ? error.message : String(error),
5144
5258
  config: {
@@ -5158,7 +5272,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
5158
5272
  var AgentTaskConsumer = _AgentTaskConsumer;
5159
5273
 
5160
5274
  // src/index.ts
5161
- var import_core26 = require("@axiom-lattice/core");
5275
+ var import_core27 = require("@axiom-lattice/core");
5162
5276
  var import_protocols3 = require("@axiom-lattice/protocols");
5163
5277
  process.on("unhandledRejection", (reason, promise) => {
5164
5278
  console.error("\u672A\u5904\u7406\u7684Promise\u62D2\u7EDD:", reason);
@@ -5173,11 +5287,11 @@ var DEFAULT_LOGGER_CONFIG = {
5173
5287
  var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
5174
5288
  var logger = loggerLattice.client;
5175
5289
  function initializeLogger(config) {
5176
- if (import_core26.loggerLatticeManager.hasLattice("default")) {
5177
- import_core26.loggerLatticeManager.removeLattice("default");
5290
+ if (import_core27.loggerLatticeManager.hasLattice("default")) {
5291
+ import_core27.loggerLatticeManager.removeLattice("default");
5178
5292
  }
5179
- (0, import_core26.registerLoggerLattice)("default", config);
5180
- return (0, import_core26.getLoggerLattice)("default");
5293
+ (0, import_core27.registerLoggerLattice)("default", config);
5294
+ return (0, import_core27.getLoggerLattice)("default");
5181
5295
  }
5182
5296
  var app = (0, import_fastify.default)({
5183
5297
  logger: false,
@@ -5185,6 +5299,18 @@ var app = (0, import_fastify.default)({
5185
5299
  bodyLimit: Number(process.env.BODY_LIMIT) || 50 * 1024 * 1024
5186
5300
  // Default 50MB, configurable via BODY_LIMIT env var
5187
5301
  });
5302
+ app.addContentTypeParser("application/json", { parseAs: "string" }, function(request, body, done) {
5303
+ if (request.method === "DELETE" || !body || body.length === 0) {
5304
+ done(null, {});
5305
+ return;
5306
+ }
5307
+ try {
5308
+ const json = JSON.parse(body);
5309
+ done(null, json);
5310
+ } catch (err) {
5311
+ done(err, void 0);
5312
+ }
5313
+ });
5188
5314
  app.addHook("onRequest", (request, reply, done) => {
5189
5315
  const getHeaderValue = (header) => {
5190
5316
  if (Array.isArray(header)) {
@@ -5201,11 +5327,6 @@ app.addHook("onRequest", (request, reply, done) => {
5201
5327
  }
5202
5328
  done();
5203
5329
  });
5204
- app.addHook("onRequest", async (request, reply) => {
5205
- if (request.method === "DELETE" && request.headers["content-type"]) {
5206
- delete request.headers["content-type"];
5207
- }
5208
- });
5209
5330
  app.addHook("onResponse", (request, reply, done) => {
5210
5331
  const getHeaderValue = (header) => {
5211
5332
  if (Array.isArray(header)) {
@@ -5277,16 +5398,16 @@ var start = async (config) => {
5277
5398
  app.decorate("loggerLattice", loggerLattice);
5278
5399
  registerLatticeRoutes(app);
5279
5400
  try {
5280
- const storeLattice = (0, import_core26.getStoreLattice)("default", "database");
5401
+ const storeLattice = (0, import_core27.getStoreLattice)("default", "database");
5281
5402
  const store = storeLattice.store;
5282
- import_core26.sqlDatabaseManager.setConfigStore(store);
5403
+ import_core27.sqlDatabaseManager.setConfigStore(store);
5283
5404
  logger.info("Database config store set for SqlDatabaseManager");
5284
5405
  } catch (error) {
5285
5406
  logger.warn("Failed to set database config store: " + (error instanceof Error ? error.message : String(error)));
5286
5407
  }
5287
- if (!import_core26.sandboxLatticeManager.hasLattice("default")) {
5408
+ if (!import_core27.sandboxLatticeManager.hasLattice("default")) {
5288
5409
  const sandboxBaseURL = process.env.SANDBOX_BASE_URL || "http://localhost:8080";
5289
- import_core26.sandboxLatticeManager.registerLattice("default", {
5410
+ import_core27.sandboxLatticeManager.registerLattice("default", {
5290
5411
  baseURL: sandboxBaseURL
5291
5412
  });
5292
5413
  logger.info(`Registered sandbox manager with baseURL: ${sandboxBaseURL}`);
@@ -5307,6 +5428,13 @@ var start = async (config) => {
5307
5428
  agentTaskConsumer.startPollingQueue();
5308
5429
  }
5309
5430
  }
5431
+ try {
5432
+ logger.info("Starting agent instance recovery...");
5433
+ const restoreStats = await import_core27.agentInstanceManager.restore();
5434
+ logger.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
5435
+ } catch (error) {
5436
+ logger.error("Agent recovery failed", { error });
5437
+ }
5310
5438
  } catch (err) {
5311
5439
  logger.error("Server start failed", { error: err });
5312
5440
  process.exit(1);