@axiom-lattice/gateway 2.1.49 → 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)}
@@ -2093,11 +2096,58 @@ var getHealthSchema = {
2093
2096
  }
2094
2097
  };
2095
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
+
2096
2146
  // src/controllers/sandbox.ts
2097
2147
  var import_stream = require("stream");
2098
2148
 
2099
2149
  // src/services/sandbox_service.ts
2100
- var import_core14 = require("@axiom-lattice/core");
2150
+ var import_core15 = require("@axiom-lattice/core");
2101
2151
  var ERROR_HTML = `<!DOCTYPE html>
2102
2152
  <html lang="zh-CN">
2103
2153
  <head>
@@ -2209,7 +2259,7 @@ var ERROR_HTML = `<!DOCTYPE html>
2209
2259
  </html>`;
2210
2260
  var SandboxService = class {
2211
2261
  getFilesystemIsolatedLevel(tenantId, assistantId) {
2212
- const agentLattice = import_core14.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
2262
+ const agentLattice = import_core15.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
2213
2263
  if (!agentLattice) {
2214
2264
  return null;
2215
2265
  }
@@ -2234,10 +2284,10 @@ var SandboxService = class {
2234
2284
  sandboxName = "global";
2235
2285
  break;
2236
2286
  }
2237
- return (0, import_core14.normalizeSandboxName)(sandboxName);
2287
+ return (0, import_core15.normalizeSandboxName)(sandboxName);
2238
2288
  }
2239
2289
  getTargetUrl(sandboxName) {
2240
- const sandboxManager = (0, import_core14.getSandBoxManager)();
2290
+ const sandboxManager = (0, import_core15.getSandBoxManager)();
2241
2291
  return `${sandboxManager.getBaseURL()}/sandbox/${sandboxName}`;
2242
2292
  }
2243
2293
  async getVncHtml(sandboxName) {
@@ -2282,7 +2332,7 @@ var SandboxService = class {
2282
2332
  var sandboxService = new SandboxService();
2283
2333
 
2284
2334
  // src/controllers/sandbox.ts
2285
- var import_core15 = require("@axiom-lattice/core");
2335
+ var import_core16 = require("@axiom-lattice/core");
2286
2336
  function getFilenameFromPath(path3) {
2287
2337
  const segments = path3.replace(/\/+$/, "").split("/");
2288
2338
  return segments[segments.length - 1] || "download";
@@ -2324,7 +2374,7 @@ function registerSandboxProxyRoutes(app2) {
2324
2374
  threadId,
2325
2375
  isolatedLevel
2326
2376
  );
2327
- const sandboxManager = (0, import_core15.getSandBoxManager)();
2377
+ const sandboxManager = (0, import_core16.getSandBoxManager)();
2328
2378
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2329
2379
  try {
2330
2380
  const data = await request.file();
@@ -2371,7 +2421,7 @@ function registerSandboxProxyRoutes(app2) {
2371
2421
  threadId,
2372
2422
  isolatedLevel
2373
2423
  );
2374
- const sandboxManager = (0, import_core15.getSandBoxManager)();
2424
+ const sandboxManager = (0, import_core16.getSandBoxManager)();
2375
2425
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2376
2426
  try {
2377
2427
  const resolvedPath = filePath.startsWith("/home/gem") ? filePath : `/home/gem/${filePath.replace(/^\//, "")}`;
@@ -2427,14 +2477,14 @@ function registerSandboxProxyRoutes(app2) {
2427
2477
  var fs = __toESM(require("fs/promises"));
2428
2478
  var path = __toESM(require("path"));
2429
2479
  var import_stream2 = require("stream");
2430
- var import_core16 = require("@axiom-lattice/core");
2431
2480
  var import_core17 = require("@axiom-lattice/core");
2432
2481
  var import_core18 = require("@axiom-lattice/core");
2482
+ var import_core19 = require("@axiom-lattice/core");
2433
2483
  var import_uuid2 = require("uuid");
2434
2484
  var WorkspaceController = class {
2435
2485
  constructor() {
2436
- this.workspaceStore = (0, import_core16.getStoreLattice)("default", "workspace").store;
2437
- 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;
2438
2488
  }
2439
2489
  getTenantId(request) {
2440
2490
  const userTenantId = request.user?.tenantId;
@@ -2567,11 +2617,11 @@ var WorkspaceController = class {
2567
2617
  throw new Error("Workspace not found");
2568
2618
  }
2569
2619
  if (workspace.storageType === "sandbox") {
2570
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2620
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2571
2621
  const sandboxName = "global";
2572
2622
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2573
2623
  return {
2574
- backend: new import_core17.SandboxFilesystem({
2624
+ backend: new import_core18.SandboxFilesystem({
2575
2625
  sandboxInstance: sandbox,
2576
2626
  workingDirectory: `/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`
2577
2627
  }),
@@ -2579,7 +2629,7 @@ var WorkspaceController = class {
2579
2629
  };
2580
2630
  } else {
2581
2631
  return {
2582
- backend: new import_core17.FilesystemBackend({
2632
+ backend: new import_core18.FilesystemBackend({
2583
2633
  rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
2584
2634
  virtualMode: true
2585
2635
  }),
@@ -2624,7 +2674,7 @@ var WorkspaceController = class {
2624
2674
  const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
2625
2675
  const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
2626
2676
  if (workspace.storageType === "sandbox") {
2627
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2677
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2628
2678
  const sandbox = await sandboxManager.createSandbox("global");
2629
2679
  const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
2630
2680
  const filename2 = this.getFilenameFromPath(resolvedPath);
@@ -2693,7 +2743,7 @@ var WorkspaceController = class {
2693
2743
  const { workspace } = await this.getBackend(tenantId, workspaceId, projectId);
2694
2744
  const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
2695
2745
  if (workspace.storageType === "sandbox") {
2696
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2746
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2697
2747
  const sandbox = await sandboxManager.createSandbox("global");
2698
2748
  const realPath = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId, resolvedPath);
2699
2749
  const filename2 = this.getFilenameFromPath(resolvedPath);
@@ -2863,7 +2913,7 @@ var WorkspaceController = class {
2863
2913
  return reply.status(400).send({ success: false, error: "Invalid path parameter" });
2864
2914
  }
2865
2915
  if (workspace.storageType === "sandbox") {
2866
- const sandboxManager = (0, import_core18.getSandBoxManager)();
2916
+ const sandboxManager = (0, import_core19.getSandBoxManager)();
2867
2917
  const sandboxName = "global";
2868
2918
  const sandbox = await sandboxManager.createSandbox(sandboxName);
2869
2919
  const baseDir = path.join("/home/gem/tenants", tenantId, "workspaces", workspaceId, projectId);
@@ -2969,7 +3019,7 @@ function registerWorkspaceRoutes(app2) {
2969
3019
  }
2970
3020
 
2971
3021
  // src/controllers/database-configs.ts
2972
- var import_core19 = require("@axiom-lattice/core");
3022
+ var import_core20 = require("@axiom-lattice/core");
2973
3023
  var import_crypto3 = require("crypto");
2974
3024
  function getTenantId6(request) {
2975
3025
  const userTenantId = request.user?.tenantId;
@@ -2981,7 +3031,7 @@ function getTenantId6(request) {
2981
3031
  async function getDatabaseConfigList(request, reply) {
2982
3032
  const tenantId = getTenantId6(request);
2983
3033
  try {
2984
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3034
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
2985
3035
  const store = storeLattice.store;
2986
3036
  const configs = await store.getAllConfigs(tenantId);
2987
3037
  console.log("Backend: getAllConfigs returned:", configs);
@@ -3012,7 +3062,7 @@ async function getDatabaseConfig(request, reply) {
3012
3062
  const tenantId = getTenantId6(request);
3013
3063
  const { key } = request.params;
3014
3064
  try {
3015
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3065
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3016
3066
  const store = storeLattice.store;
3017
3067
  const config = await store.getConfigByKey(tenantId, key);
3018
3068
  if (!config) {
@@ -3038,7 +3088,7 @@ async function createDatabaseConfig(request, reply) {
3038
3088
  const tenantId = getTenantId6(request);
3039
3089
  const body = request.body;
3040
3090
  try {
3041
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3091
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3042
3092
  const store = storeLattice.store;
3043
3093
  const existing = await store.getConfigByKey(tenantId, body.key);
3044
3094
  if (existing) {
@@ -3051,7 +3101,7 @@ async function createDatabaseConfig(request, reply) {
3051
3101
  const id = body.id || (0, import_crypto3.randomUUID)();
3052
3102
  const config = await store.createConfig(tenantId, id, body);
3053
3103
  try {
3054
- import_core19.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
3104
+ import_core20.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
3055
3105
  } catch (error) {
3056
3106
  console.warn("Failed to auto-register database:", error);
3057
3107
  }
@@ -3074,7 +3124,7 @@ async function updateDatabaseConfig(request, reply) {
3074
3124
  const { key } = request.params;
3075
3125
  const updates = request.body;
3076
3126
  try {
3077
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3127
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3078
3128
  const store = storeLattice.store;
3079
3129
  const existing = await store.getConfigByKey(tenantId, key);
3080
3130
  if (!existing) {
@@ -3093,7 +3143,7 @@ async function updateDatabaseConfig(request, reply) {
3093
3143
  }
3094
3144
  if (updates.config) {
3095
3145
  try {
3096
- import_core19.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
3146
+ import_core20.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
3097
3147
  } catch (error) {
3098
3148
  console.warn("Failed to re-register database:", error);
3099
3149
  }
@@ -3115,7 +3165,7 @@ async function deleteDatabaseConfig(request, reply) {
3115
3165
  const tenantId = getTenantId6(request);
3116
3166
  const { keyOrId } = request.params;
3117
3167
  try {
3118
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3168
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3119
3169
  const store = storeLattice.store;
3120
3170
  console.log("Delete request - keyOrId:", keyOrId);
3121
3171
  let config = await store.getConfigByKey(tenantId, keyOrId);
@@ -3142,8 +3192,8 @@ async function deleteDatabaseConfig(request, reply) {
3142
3192
  };
3143
3193
  }
3144
3194
  try {
3145
- if (import_core19.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
3146
- await import_core19.sqlDatabaseManager.removeDatabase(tenantId, configKey);
3195
+ if (import_core20.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
3196
+ await import_core20.sqlDatabaseManager.removeDatabase(tenantId, configKey);
3147
3197
  }
3148
3198
  } catch (error) {
3149
3199
  console.warn("Failed to remove from SqlDatabaseManager:", error);
@@ -3164,7 +3214,7 @@ async function testDatabaseConnection(request, reply) {
3164
3214
  const tenantId = getTenantId6(request);
3165
3215
  const { key } = request.params;
3166
3216
  try {
3167
- const storeLattice = (0, import_core19.getStoreLattice)("default", "database");
3217
+ const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
3168
3218
  const store = storeLattice.store;
3169
3219
  const config = await store.getConfigByKey(tenantId, key);
3170
3220
  if (!config) {
@@ -3175,16 +3225,16 @@ async function testDatabaseConnection(request, reply) {
3175
3225
  };
3176
3226
  }
3177
3227
  const testKey = `__test_${key}_${Date.now()}`;
3178
- import_core19.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
3228
+ import_core20.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
3179
3229
  const startTime = Date.now();
3180
- const db = await import_core19.sqlDatabaseManager.getDatabase(tenantId, testKey);
3230
+ const db = await import_core20.sqlDatabaseManager.getDatabase(tenantId, testKey);
3181
3231
  try {
3182
3232
  await db.connect();
3183
3233
  await db.listTables();
3184
3234
  const latency = Date.now() - startTime;
3185
3235
  await new Promise((resolve) => setTimeout(resolve, 100));
3186
3236
  await db.disconnect();
3187
- await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3237
+ await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3188
3238
  return {
3189
3239
  success: true,
3190
3240
  message: "Connection test successful",
@@ -3196,7 +3246,7 @@ async function testDatabaseConnection(request, reply) {
3196
3246
  } catch (error) {
3197
3247
  try {
3198
3248
  await db.disconnect();
3199
- await import_core19.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3249
+ await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
3200
3250
  } catch {
3201
3251
  }
3202
3252
  return {
@@ -3248,7 +3298,7 @@ function registerDatabaseConfigRoutes(app2) {
3248
3298
  }
3249
3299
 
3250
3300
  // src/controllers/metrics-configs.ts
3251
- var import_core20 = require("@axiom-lattice/core");
3301
+ var import_core21 = require("@axiom-lattice/core");
3252
3302
  var import_crypto4 = require("crypto");
3253
3303
  function getTenantId7(request) {
3254
3304
  const userTenantId = request.user?.tenantId;
@@ -3260,7 +3310,7 @@ function getTenantId7(request) {
3260
3310
  async function getMetricsServerConfigList(request, reply) {
3261
3311
  const tenantId = getTenantId7(request);
3262
3312
  try {
3263
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3313
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3264
3314
  const store = storeLattice.store;
3265
3315
  const configs = await store.getAllConfigs(tenantId);
3266
3316
  return {
@@ -3287,7 +3337,7 @@ async function getMetricsServerConfig(request, reply) {
3287
3337
  const tenantId = getTenantId7(request);
3288
3338
  const { key } = request.params;
3289
3339
  try {
3290
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3340
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3291
3341
  const store = storeLattice.store;
3292
3342
  const config = await store.getConfigByKey(tenantId, key);
3293
3343
  if (!config) {
@@ -3313,7 +3363,7 @@ async function createMetricsServerConfig(request, reply) {
3313
3363
  const tenantId = getTenantId7(request);
3314
3364
  const body = request.body;
3315
3365
  try {
3316
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3366
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3317
3367
  const store = storeLattice.store;
3318
3368
  const existing = await store.getConfigByKey(tenantId, body.key);
3319
3369
  if (existing) {
@@ -3342,7 +3392,7 @@ async function createMetricsServerConfig(request, reply) {
3342
3392
  };
3343
3393
  const config = await store.createConfig(tenantId, id, configData);
3344
3394
  try {
3345
- import_core20.metricsServerManager.registerServer(tenantId, config.key, config.config);
3395
+ import_core21.metricsServerManager.registerServer(tenantId, config.key, config.config);
3346
3396
  } catch (error) {
3347
3397
  console.warn("Failed to auto-register metrics server:", error);
3348
3398
  }
@@ -3365,7 +3415,7 @@ async function updateMetricsServerConfig(request, reply) {
3365
3415
  const { key } = request.params;
3366
3416
  const updates = request.body;
3367
3417
  try {
3368
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3418
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3369
3419
  const store = storeLattice.store;
3370
3420
  const existing = await store.getConfigByKey(tenantId, key);
3371
3421
  if (!existing) {
@@ -3393,7 +3443,7 @@ async function updateMetricsServerConfig(request, reply) {
3393
3443
  }
3394
3444
  if (updates.config) {
3395
3445
  try {
3396
- import_core20.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
3446
+ import_core21.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
3397
3447
  } catch (error) {
3398
3448
  console.warn("Failed to re-register metrics server:", error);
3399
3449
  }
@@ -3415,7 +3465,7 @@ async function deleteMetricsServerConfig(request, reply) {
3415
3465
  const tenantId = getTenantId7(request);
3416
3466
  const { keyOrId } = request.params;
3417
3467
  try {
3418
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3468
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3419
3469
  const store = storeLattice.store;
3420
3470
  let config = await store.getConfigByKey(tenantId, keyOrId);
3421
3471
  let configKey = keyOrId;
@@ -3440,8 +3490,8 @@ async function deleteMetricsServerConfig(request, reply) {
3440
3490
  };
3441
3491
  }
3442
3492
  try {
3443
- if (import_core20.metricsServerManager.hasServer(tenantId, configKey)) {
3444
- import_core20.metricsServerManager.removeServer(tenantId, configKey);
3493
+ if (import_core21.metricsServerManager.hasServer(tenantId, configKey)) {
3494
+ import_core21.metricsServerManager.removeServer(tenantId, configKey);
3445
3495
  }
3446
3496
  } catch (error) {
3447
3497
  console.warn("Failed to remove from MetricsServerManager:", error);
@@ -3462,7 +3512,7 @@ async function testMetricsServerConnection(request, reply) {
3462
3512
  const tenantId = getTenantId7(request);
3463
3513
  const { key } = request.params;
3464
3514
  try {
3465
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3515
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3466
3516
  const store = storeLattice.store;
3467
3517
  const config = await store.getConfigByKey(tenantId, key);
3468
3518
  if (!config) {
@@ -3473,11 +3523,11 @@ async function testMetricsServerConnection(request, reply) {
3473
3523
  };
3474
3524
  }
3475
3525
  const testKey = `__test_${key}_${Date.now()}`;
3476
- import_core20.metricsServerManager.registerServer(tenantId, testKey, config.config);
3526
+ import_core21.metricsServerManager.registerServer(tenantId, testKey, config.config);
3477
3527
  try {
3478
- const client = import_core20.metricsServerManager.getClient(tenantId, testKey);
3528
+ const client = import_core21.metricsServerManager.getClient(tenantId, testKey);
3479
3529
  const result = await client.testConnection();
3480
- import_core20.metricsServerManager.removeServer(tenantId, testKey);
3530
+ import_core21.metricsServerManager.removeServer(tenantId, testKey);
3481
3531
  return {
3482
3532
  success: true,
3483
3533
  message: result.connected ? "Connection test successful" : "Connection test failed",
@@ -3485,7 +3535,7 @@ async function testMetricsServerConnection(request, reply) {
3485
3535
  };
3486
3536
  } catch (error) {
3487
3537
  try {
3488
- import_core20.metricsServerManager.removeServer(tenantId, testKey);
3538
+ import_core21.metricsServerManager.removeServer(tenantId, testKey);
3489
3539
  } catch {
3490
3540
  }
3491
3541
  return {
@@ -3513,7 +3563,7 @@ async function listAvailableMetrics(request, reply) {
3513
3563
  const tenantId = getTenantId7(request);
3514
3564
  const { key } = request.params;
3515
3565
  try {
3516
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3566
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3517
3567
  const store = storeLattice.store;
3518
3568
  const config = await store.getConfigByKey(tenantId, key);
3519
3569
  if (!config) {
@@ -3523,10 +3573,10 @@ async function listAvailableMetrics(request, reply) {
3523
3573
  message: "Metrics server configuration not found"
3524
3574
  };
3525
3575
  }
3526
- if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
3527
- 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);
3528
3578
  }
3529
- const client = import_core20.metricsServerManager.getClient(tenantId, key);
3579
+ const client = import_core21.metricsServerManager.getClient(tenantId, key);
3530
3580
  const metrics = await client.listMetrics();
3531
3581
  return {
3532
3582
  success: true,
@@ -3552,7 +3602,7 @@ async function queryMetricsData(request, reply) {
3552
3602
  const { key } = request.params;
3553
3603
  const { metricName, startTime, endTime, step, labels } = request.body;
3554
3604
  try {
3555
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3605
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3556
3606
  const store = storeLattice.store;
3557
3607
  const config = await store.getConfigByKey(tenantId, key);
3558
3608
  if (!config) {
@@ -3569,10 +3619,10 @@ async function queryMetricsData(request, reply) {
3569
3619
  message: "metricName is required"
3570
3620
  };
3571
3621
  }
3572
- if (!import_core20.metricsServerManager.hasServer(tenantId, key)) {
3573
- 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);
3574
3624
  }
3575
- const client = import_core20.metricsServerManager.getClient(tenantId, key);
3625
+ const client = import_core21.metricsServerManager.getClient(tenantId, key);
3576
3626
  const result = await client.queryMetricData(metricName, {
3577
3627
  startTime,
3578
3628
  endTime,
@@ -3599,7 +3649,7 @@ async function getDataSources(request, reply) {
3599
3649
  const tenantId = getTenantId7(request);
3600
3650
  const { key } = request.params;
3601
3651
  try {
3602
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3652
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3603
3653
  const store = storeLattice.store;
3604
3654
  const config = await store.getConfigByKey(tenantId, key);
3605
3655
  if (!config) {
@@ -3617,7 +3667,7 @@ async function getDataSources(request, reply) {
3617
3667
  };
3618
3668
  }
3619
3669
  const semanticConfig = config.config;
3620
- const client = new import_core20.SemanticMetricsClient(semanticConfig);
3670
+ const client = new import_core21.SemanticMetricsClient(semanticConfig);
3621
3671
  const allDatasources = await client.getDataSources();
3622
3672
  const selectedIds = semanticConfig.selectedDataSources || [];
3623
3673
  const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
@@ -3640,7 +3690,7 @@ async function getDatasourceMetrics(request, reply) {
3640
3690
  const tenantId = getTenantId7(request);
3641
3691
  const { key, datasourceId } = request.params;
3642
3692
  try {
3643
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3693
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3644
3694
  const store = storeLattice.store;
3645
3695
  const config = await store.getConfigByKey(tenantId, key);
3646
3696
  if (!config) {
@@ -3658,7 +3708,7 @@ async function getDatasourceMetrics(request, reply) {
3658
3708
  };
3659
3709
  }
3660
3710
  const semanticConfig = config.config;
3661
- const client = new import_core20.SemanticMetricsClient(semanticConfig);
3711
+ const client = new import_core21.SemanticMetricsClient(semanticConfig);
3662
3712
  const metrics = await client.getDatasourceMetrics(datasourceId);
3663
3713
  return {
3664
3714
  success: true,
@@ -3678,7 +3728,7 @@ async function querySemanticMetrics(request, reply) {
3678
3728
  const { key } = request.params;
3679
3729
  const body = request.body;
3680
3730
  try {
3681
- const storeLattice = (0, import_core20.getStoreLattice)("default", "metrics");
3731
+ const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
3682
3732
  const store = storeLattice.store;
3683
3733
  const config = await store.getConfigByKey(tenantId, key);
3684
3734
  if (!config) {
@@ -3703,7 +3753,7 @@ async function querySemanticMetrics(request, reply) {
3703
3753
  };
3704
3754
  }
3705
3755
  const semanticConfig = config.config;
3706
- const client = new import_core20.SemanticMetricsClient(semanticConfig);
3756
+ const client = new import_core21.SemanticMetricsClient(semanticConfig);
3707
3757
  const result = await client.semanticQuery(body);
3708
3758
  const columnNames = result.columns.map((col) => col.name);
3709
3759
  const allDataPoints = [];
@@ -3763,7 +3813,7 @@ async function testSemanticDataSources(request, reply) {
3763
3813
  password: body.password,
3764
3814
  headers: body.headers
3765
3815
  };
3766
- const client = new import_core20.SemanticMetricsClient(testConfig);
3816
+ const client = new import_core21.SemanticMetricsClient(testConfig);
3767
3817
  const datasources = await client.getDataSources();
3768
3818
  return {
3769
3819
  success: true,
@@ -3799,7 +3849,7 @@ async function testDatasourceMetrics(request, reply) {
3799
3849
  password: body.password,
3800
3850
  headers: body.headers
3801
3851
  };
3802
- const client = new import_core20.SemanticMetricsClient(testConfig);
3852
+ const client = new import_core21.SemanticMetricsClient(testConfig);
3803
3853
  const metrics = await client.getDatasourceMetrics(datasourceId);
3804
3854
  return {
3805
3855
  success: true,
@@ -3831,7 +3881,7 @@ function registerMetricsServerConfigRoutes(app2) {
3831
3881
  }
3832
3882
 
3833
3883
  // src/controllers/mcp-configs.ts
3834
- var import_core21 = require("@axiom-lattice/core");
3884
+ var import_core22 = require("@axiom-lattice/core");
3835
3885
  var import_crypto5 = require("crypto");
3836
3886
  function getTenantId8(request) {
3837
3887
  const userTenantId = request.user?.tenantId;
@@ -3843,7 +3893,7 @@ function getTenantId8(request) {
3843
3893
  async function getMcpServerConfigList(request, reply) {
3844
3894
  const tenantId = getTenantId8(request);
3845
3895
  try {
3846
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3896
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3847
3897
  const store = storeLattice.store;
3848
3898
  const configs = await store.getAllConfigs(tenantId);
3849
3899
  return {
@@ -3870,7 +3920,7 @@ async function getMcpServerConfig(request, reply) {
3870
3920
  const tenantId = getTenantId8(request);
3871
3921
  const { key } = request.params;
3872
3922
  try {
3873
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3923
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3874
3924
  const store = storeLattice.store;
3875
3925
  const config = await store.getConfigByKey(tenantId, key);
3876
3926
  if (!config) {
@@ -3896,7 +3946,7 @@ async function createMcpServerConfig(request, reply) {
3896
3946
  const tenantId = getTenantId8(request);
3897
3947
  const body = request.body;
3898
3948
  try {
3899
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3949
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3900
3950
  const store = storeLattice.store;
3901
3951
  const existing = await store.getConfigByKey(tenantId, body.key);
3902
3952
  if (existing) {
@@ -3936,7 +3986,7 @@ async function updateMcpServerConfig(request, reply) {
3936
3986
  const { key } = request.params;
3937
3987
  const updates = request.body;
3938
3988
  try {
3939
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
3989
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3940
3990
  const store = storeLattice.store;
3941
3991
  const existing = await store.getConfigByKey(tenantId, key);
3942
3992
  if (!existing) {
@@ -3956,8 +4006,8 @@ async function updateMcpServerConfig(request, reply) {
3956
4006
  }
3957
4007
  if (shouldReconnect) {
3958
4008
  try {
3959
- if (import_core21.mcpManager.hasServer(key)) {
3960
- await import_core21.mcpManager.removeServer(key);
4009
+ if (import_core22.mcpManager.hasServer(key)) {
4010
+ await import_core22.mcpManager.removeServer(key);
3961
4011
  }
3962
4012
  await connectAndRegisterTools(updated);
3963
4013
  await store.updateConfig(tenantId, existing.id, { status: "connected" });
@@ -3985,7 +4035,7 @@ async function deleteMcpServerConfig(request, reply) {
3985
4035
  const tenantId = getTenantId8(request);
3986
4036
  const { keyOrId } = request.params;
3987
4037
  try {
3988
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4038
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
3989
4039
  const store = storeLattice.store;
3990
4040
  let config = await store.getConfigByKey(tenantId, keyOrId);
3991
4041
  let configKey = keyOrId;
@@ -4003,8 +4053,8 @@ async function deleteMcpServerConfig(request, reply) {
4003
4053
  };
4004
4054
  }
4005
4055
  try {
4006
- if (import_core21.mcpManager.hasServer(configKey)) {
4007
- await import_core21.mcpManager.removeServer(configKey);
4056
+ if (import_core22.mcpManager.hasServer(configKey)) {
4057
+ await import_core22.mcpManager.removeServer(configKey);
4008
4058
  }
4009
4059
  } catch (error) {
4010
4060
  console.warn("Failed to remove from MCP manager:", error);
@@ -4032,7 +4082,7 @@ async function testMcpServerConnection(request, reply) {
4032
4082
  const tenantId = getTenantId8(request);
4033
4083
  const { key } = request.params;
4034
4084
  try {
4035
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4085
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4036
4086
  const store = storeLattice.store;
4037
4087
  const config = await store.getConfigByKey(tenantId, key);
4038
4088
  if (!config) {
@@ -4046,11 +4096,11 @@ async function testMcpServerConnection(request, reply) {
4046
4096
  try {
4047
4097
  const testKey = `__test_${key}_${Date.now()}`;
4048
4098
  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();
4099
+ import_core22.mcpManager.addServer(testKey, connection);
4100
+ await import_core22.mcpManager.connect();
4101
+ const tools = await import_core22.mcpManager.getAllTools();
4052
4102
  const latency = Date.now() - startTime;
4053
- await import_core21.mcpManager.removeServer(testKey);
4103
+ await import_core22.mcpManager.removeServer(testKey);
4054
4104
  return {
4055
4105
  success: true,
4056
4106
  message: "Connection test successful",
@@ -4085,7 +4135,7 @@ async function listMcpServerTools(request, reply) {
4085
4135
  const tenantId = getTenantId8(request);
4086
4136
  const { key } = request.params;
4087
4137
  try {
4088
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4138
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4089
4139
  const store = storeLattice.store;
4090
4140
  const config = await store.getConfigByKey(tenantId, key);
4091
4141
  if (!config) {
@@ -4095,10 +4145,10 @@ async function listMcpServerTools(request, reply) {
4095
4145
  message: "MCP server configuration not found"
4096
4146
  };
4097
4147
  }
4098
- if (!import_core21.mcpManager.hasServer(key)) {
4148
+ if (!import_core22.mcpManager.hasServer(key)) {
4099
4149
  await connectAndRegisterTools(config);
4100
4150
  }
4101
- const tools = await import_core21.mcpManager.getAllTools();
4151
+ const tools = await import_core22.mcpManager.getAllTools();
4102
4152
  return {
4103
4153
  success: true,
4104
4154
  message: "Tools retrieved successfully",
@@ -4118,7 +4168,7 @@ async function connectMcpServer(request, reply) {
4118
4168
  const tenantId = getTenantId8(request);
4119
4169
  const { key } = request.params;
4120
4170
  try {
4121
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4171
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4122
4172
  const store = storeLattice.store;
4123
4173
  const config = await store.getConfigByKey(tenantId, key);
4124
4174
  if (!config) {
@@ -4139,7 +4189,7 @@ async function connectMcpServer(request, reply) {
4139
4189
  };
4140
4190
  } catch (error) {
4141
4191
  console.error("Failed to connect MCP server:", error);
4142
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4192
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4143
4193
  const store = storeLattice.store;
4144
4194
  const config = await store.getConfigByKey(tenantId, key);
4145
4195
  if (config) {
@@ -4155,7 +4205,7 @@ async function disconnectMcpServer(request, reply) {
4155
4205
  const tenantId = getTenantId8(request);
4156
4206
  const { key } = request.params;
4157
4207
  try {
4158
- const storeLattice = (0, import_core21.getStoreLattice)("default", "mcp");
4208
+ const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
4159
4209
  const store = storeLattice.store;
4160
4210
  const config = await store.getConfigByKey(tenantId, key);
4161
4211
  if (!config) {
@@ -4165,8 +4215,8 @@ async function disconnectMcpServer(request, reply) {
4165
4215
  message: "MCP server configuration not found"
4166
4216
  };
4167
4217
  }
4168
- if (import_core21.mcpManager.hasServer(key)) {
4169
- await import_core21.mcpManager.removeServer(key);
4218
+ if (import_core22.mcpManager.hasServer(key)) {
4219
+ await import_core22.mcpManager.removeServer(key);
4170
4220
  }
4171
4221
  const updated = await store.updateConfig(tenantId, config.id, {
4172
4222
  status: "disconnected"
@@ -4196,10 +4246,10 @@ async function testMcpServerTools(request, reply) {
4196
4246
  }
4197
4247
  const testKey = `__test_${Date.now()}`;
4198
4248
  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);
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);
4203
4253
  return {
4204
4254
  success: true,
4205
4255
  message: "Tools retrieved successfully",
@@ -4236,14 +4286,14 @@ function convertToConnection(config) {
4236
4286
  }
4237
4287
  async function connectAndRegisterTools(config) {
4238
4288
  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();
4289
+ import_core22.mcpManager.addServer(config.key, connection);
4290
+ await import_core22.mcpManager.connect();
4291
+ const allTools = await import_core22.mcpManager.getAllTools();
4242
4292
  const selectedTools = allTools.filter(
4243
4293
  (tool) => config.selectedTools.includes(tool.name)
4244
4294
  );
4245
4295
  for (const tool of selectedTools) {
4246
- import_core21.toolLatticeManager.registerExistingTool(tool.name, tool);
4296
+ import_core22.toolLatticeManager.registerExistingTool(tool.name, tool);
4247
4297
  }
4248
4298
  }
4249
4299
  function registerMcpServerConfigRoutes(app2) {
@@ -4260,11 +4310,11 @@ function registerMcpServerConfigRoutes(app2) {
4260
4310
  }
4261
4311
 
4262
4312
  // src/controllers/users.ts
4263
- var import_core22 = require("@axiom-lattice/core");
4313
+ var import_core23 = require("@axiom-lattice/core");
4264
4314
  var import_uuid3 = require("uuid");
4265
4315
  var UsersController = class {
4266
4316
  constructor() {
4267
- this.userStore = (0, import_core22.getStoreLattice)("default", "user").store;
4317
+ this.userStore = (0, import_core23.getStoreLattice)("default", "user").store;
4268
4318
  }
4269
4319
  async listUsers(request, reply) {
4270
4320
  const { email } = request.query;
@@ -4342,11 +4392,11 @@ function registerUserRoutes(app2) {
4342
4392
  }
4343
4393
 
4344
4394
  // src/controllers/tenants.ts
4345
- var import_core23 = require("@axiom-lattice/core");
4395
+ var import_core24 = require("@axiom-lattice/core");
4346
4396
  var import_uuid4 = require("uuid");
4347
4397
  var TenantsController = class {
4348
4398
  constructor() {
4349
- this.tenantStore = (0, import_core23.getStoreLattice)("default", "tenant").store;
4399
+ this.tenantStore = (0, import_core24.getStoreLattice)("default", "tenant").store;
4350
4400
  }
4351
4401
  // ==================== Tenant CRUD ====================
4352
4402
  async listTenants(request, reply) {
@@ -4410,7 +4460,7 @@ function registerTenantRoutes(app2) {
4410
4460
  }
4411
4461
 
4412
4462
  // src/controllers/auth.ts
4413
- var import_core24 = require("@axiom-lattice/core");
4463
+ var import_core25 = require("@axiom-lattice/core");
4414
4464
  var import_uuid5 = require("uuid");
4415
4465
  var defaultAuthConfig = {
4416
4466
  autoApproveUsers: true,
@@ -4419,9 +4469,9 @@ var defaultAuthConfig = {
4419
4469
  };
4420
4470
  var AuthController = class {
4421
4471
  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;
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;
4425
4475
  this.config = { ...defaultAuthConfig, ...config };
4426
4476
  }
4427
4477
  async register(request, reply) {
@@ -4696,6 +4746,57 @@ var AuthController = class {
4696
4746
  }
4697
4747
  return btoa(JSON.stringify(payload));
4698
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
+ }
4699
4800
  };
4700
4801
  function registerAuthRoutes(app2, config) {
4701
4802
  const controller = new AuthController(config);
@@ -4734,6 +4835,11 @@ function registerAuthRoutes(app2, config) {
4734
4835
  app2.post("/api/auth/approve", { preHandler: authHook }, (req, res) => controller.approveUser(req, res));
4735
4836
  app2.get("/api/auth/pending", { preHandler: authHook }, (req, res) => controller.listPendingUsers(req, res));
4736
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
+ );
4737
4843
  }
4738
4844
 
4739
4845
  // src/routes/index.ts
@@ -4870,6 +4976,10 @@ var registerLatticeRoutes = (app2) => {
4870
4976
  autoApproveUsers: process.env.AUTO_APPROVE_USERS !== "false",
4871
4977
  allowTenantRegistration: process.env.ALLOW_TENANT_REGISTRATION !== "false"
4872
4978
  });
4979
+ app2.delete(
4980
+ "/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
4981
+ removePendingMessageHandler
4982
+ );
4873
4983
  };
4874
4984
 
4875
4985
  // src/swagger.ts
@@ -4935,7 +5045,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
4935
5045
  };
4936
5046
 
4937
5047
  // src/services/agent_task_consumer.ts
4938
- var import_core25 = require("@axiom-lattice/core");
5048
+ var import_core26 = require("@axiom-lattice/core");
4939
5049
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
4940
5050
  const {
4941
5051
  assistant_id,
@@ -4950,18 +5060,18 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4950
5060
  console.log(
4951
5061
  `\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
4952
5062
  );
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);
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);
4955
5065
  if (callback_event) {
4956
5066
  agent.subscribeOnce("message:completed", (evt) => {
4957
- import_core25.eventBus.publish(callback_event, {
5067
+ import_core26.eventBus.publish(callback_event, {
4958
5068
  success: true,
4959
5069
  state: evt.state,
4960
5070
  config: { assistant_id, thread_id, tenant_id }
4961
5071
  });
4962
5072
  });
4963
5073
  agent.subscribeOnce("message:interrupted", (evt) => {
4964
- import_core25.eventBus.publish(callback_event, {
5074
+ import_core26.eventBus.publish(callback_event, {
4965
5075
  success: true,
4966
5076
  state: evt.state,
4967
5077
  config: { assistant_id, thread_id, tenant_id }
@@ -4985,7 +5095,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4985
5095
  return handleAgentTask(taskRequest, nextRetryCount);
4986
5096
  }
4987
5097
  if (callback_event) {
4988
- import_core25.eventBus.publish(callback_event, {
5098
+ import_core26.eventBus.publish(callback_event, {
4989
5099
  success: false,
4990
5100
  error: error instanceof Error ? error.message : String(error),
4991
5101
  config: { assistant_id, thread_id, tenant_id }
@@ -5023,7 +5133,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
5023
5133
  * 初始化事件监听和队列轮询
5024
5134
  */
5025
5135
  initialize() {
5026
- 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));
5027
5137
  this.startPollingQueue();
5028
5138
  console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
5029
5139
  }
@@ -5142,7 +5252,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
5142
5252
  handleAgentTask(taskRequest).catch((error) => {
5143
5253
  console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
5144
5254
  if (taskRequest.callback_event) {
5145
- import_core25.eventBus.publish(taskRequest.callback_event, {
5255
+ import_core26.eventBus.publish(taskRequest.callback_event, {
5146
5256
  success: false,
5147
5257
  error: error instanceof Error ? error.message : String(error),
5148
5258
  config: {
@@ -5162,7 +5272,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
5162
5272
  var AgentTaskConsumer = _AgentTaskConsumer;
5163
5273
 
5164
5274
  // src/index.ts
5165
- var import_core26 = require("@axiom-lattice/core");
5275
+ var import_core27 = require("@axiom-lattice/core");
5166
5276
  var import_protocols3 = require("@axiom-lattice/protocols");
5167
5277
  process.on("unhandledRejection", (reason, promise) => {
5168
5278
  console.error("\u672A\u5904\u7406\u7684Promise\u62D2\u7EDD:", reason);
@@ -5177,11 +5287,11 @@ var DEFAULT_LOGGER_CONFIG = {
5177
5287
  var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
5178
5288
  var logger = loggerLattice.client;
5179
5289
  function initializeLogger(config) {
5180
- if (import_core26.loggerLatticeManager.hasLattice("default")) {
5181
- import_core26.loggerLatticeManager.removeLattice("default");
5290
+ if (import_core27.loggerLatticeManager.hasLattice("default")) {
5291
+ import_core27.loggerLatticeManager.removeLattice("default");
5182
5292
  }
5183
- (0, import_core26.registerLoggerLattice)("default", config);
5184
- return (0, import_core26.getLoggerLattice)("default");
5293
+ (0, import_core27.registerLoggerLattice)("default", config);
5294
+ return (0, import_core27.getLoggerLattice)("default");
5185
5295
  }
5186
5296
  var app = (0, import_fastify.default)({
5187
5297
  logger: false,
@@ -5189,6 +5299,18 @@ var app = (0, import_fastify.default)({
5189
5299
  bodyLimit: Number(process.env.BODY_LIMIT) || 50 * 1024 * 1024
5190
5300
  // Default 50MB, configurable via BODY_LIMIT env var
5191
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
+ });
5192
5314
  app.addHook("onRequest", (request, reply, done) => {
5193
5315
  const getHeaderValue = (header) => {
5194
5316
  if (Array.isArray(header)) {
@@ -5205,11 +5327,6 @@ app.addHook("onRequest", (request, reply, done) => {
5205
5327
  }
5206
5328
  done();
5207
5329
  });
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
5330
  app.addHook("onResponse", (request, reply, done) => {
5214
5331
  const getHeaderValue = (header) => {
5215
5332
  if (Array.isArray(header)) {
@@ -5281,16 +5398,16 @@ var start = async (config) => {
5281
5398
  app.decorate("loggerLattice", loggerLattice);
5282
5399
  registerLatticeRoutes(app);
5283
5400
  try {
5284
- const storeLattice = (0, import_core26.getStoreLattice)("default", "database");
5401
+ const storeLattice = (0, import_core27.getStoreLattice)("default", "database");
5285
5402
  const store = storeLattice.store;
5286
- import_core26.sqlDatabaseManager.setConfigStore(store);
5403
+ import_core27.sqlDatabaseManager.setConfigStore(store);
5287
5404
  logger.info("Database config store set for SqlDatabaseManager");
5288
5405
  } catch (error) {
5289
5406
  logger.warn("Failed to set database config store: " + (error instanceof Error ? error.message : String(error)));
5290
5407
  }
5291
- if (!import_core26.sandboxLatticeManager.hasLattice("default")) {
5408
+ if (!import_core27.sandboxLatticeManager.hasLattice("default")) {
5292
5409
  const sandboxBaseURL = process.env.SANDBOX_BASE_URL || "http://localhost:8080";
5293
- import_core26.sandboxLatticeManager.registerLattice("default", {
5410
+ import_core27.sandboxLatticeManager.registerLattice("default", {
5294
5411
  baseURL: sandboxBaseURL
5295
5412
  });
5296
5413
  logger.info(`Registered sandbox manager with baseURL: ${sandboxBaseURL}`);
@@ -5313,7 +5430,7 @@ var start = async (config) => {
5313
5430
  }
5314
5431
  try {
5315
5432
  logger.info("Starting agent instance recovery...");
5316
- const restoreStats = await import_core26.agentInstanceManager.restore();
5433
+ const restoreStats = await import_core27.agentInstanceManager.restore();
5317
5434
  logger.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
5318
5435
  } catch (error) {
5319
5436
  logger.error("Agent recovery failed", { error });