@axiom-lattice/gateway 2.1.49 → 2.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -208,10 +208,12 @@ var createRun = async (request, reply) => {
208
208
  const {
209
209
  assistant_id,
210
210
  thread_id,
211
+ message_id,
211
212
  command,
212
213
  streaming,
213
214
  background,
214
215
  custom_run_config,
216
+ mode,
215
217
  ...input
216
218
  } = request.body;
217
219
  const tenant_id = request.headers["x-tenant-id"];
@@ -242,11 +244,12 @@ var createRun = async (request, reply) => {
242
244
  "Access-Control-Allow-Origin": "*"
243
245
  });
244
246
  try {
247
+ const messageInput = message_id ? { ...input, id: message_id } : input;
245
248
  const result = await agent.addMessage({
246
- input,
249
+ input: messageInput,
247
250
  command,
248
251
  custom_run_config
249
- });
252
+ }, mode);
250
253
  const stream = agent.chunkStream(result.messageId, [MessageChunkTypes.MESSAGE_COMPLETED]);
251
254
  for await (const chunk of stream) {
252
255
  const success = reply.raw.write(`data: ${JSON.stringify(chunk)}
@@ -562,9 +565,20 @@ function getTenantId2(request) {
562
565
  async function getThreadList(request, reply) {
563
566
  const tenantId = getTenantId2(request);
564
567
  const { assistantId } = request.params;
568
+ const metadataFilter = {};
569
+ if (request.query.workspaceId) {
570
+ metadataFilter.workspaceId = request.query.workspaceId;
571
+ }
572
+ if (request.query.projectId) {
573
+ metadataFilter.projectId = request.query.projectId;
574
+ }
565
575
  const storeLattice = getStoreLattice2("default", "thread");
566
576
  const threadStore = storeLattice.store;
567
- const threads = await threadStore.getThreadsByAssistantId(tenantId, assistantId);
577
+ const threads = await threadStore.getThreadsByAssistantId(
578
+ tenantId,
579
+ assistantId,
580
+ Object.keys(metadataFilter).length > 0 ? metadataFilter : void 0
581
+ );
568
582
  return {
569
583
  success: true,
570
584
  message: "Successfully retrieved thread list",
@@ -597,9 +611,23 @@ async function createThread(request, reply) {
597
611
  const { assistantId } = request.params;
598
612
  const data = request.body;
599
613
  const threadId = randomUUID2();
614
+ const workspaceId = request.headers["x-workspace-id"];
615
+ const projectId = request.headers["x-project-id"];
616
+ const enrichedMetadata = {
617
+ ...data.metadata,
618
+ tenantId
619
+ };
620
+ if (workspaceId) {
621
+ enrichedMetadata.workspaceId = workspaceId;
622
+ }
623
+ if (projectId) {
624
+ enrichedMetadata.projectId = projectId;
625
+ }
600
626
  const storeLattice = getStoreLattice2("default", "thread");
601
627
  const threadStore = storeLattice.store;
602
- const newThread = await threadStore.createThread(tenantId, assistantId, threadId, data);
628
+ const newThread = await threadStore.createThread(tenantId, assistantId, threadId, {
629
+ metadata: enrichedMetadata
630
+ });
603
631
  return reply.status(201).send({
604
632
  success: true,
605
633
  message: "Successfully created thread",
@@ -2068,6 +2096,53 @@ var getHealthSchema = {
2068
2096
  }
2069
2097
  };
2070
2098
 
2099
+ // src/controllers/thread_status.ts
2100
+ import { agentInstanceManager as agentInstanceManager4 } from "@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 = agentInstanceManager4.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
+
2071
2146
  // src/controllers/sandbox.ts
2072
2147
  import { Readable } from "stream";
2073
2148
 
@@ -4682,6 +4757,57 @@ var AuthController = class {
4682
4757
  }
4683
4758
  return btoa(JSON.stringify(payload));
4684
4759
  }
4760
+ async changePassword(request, reply) {
4761
+ const userId = request.user?.id;
4762
+ const { currentPassword, newPassword } = request.body;
4763
+ if (!userId) {
4764
+ return reply.status(401).send({
4765
+ success: false,
4766
+ error: "Unauthorized"
4767
+ });
4768
+ }
4769
+ try {
4770
+ const user = await this.userStore.getUserById(userId);
4771
+ if (!user) {
4772
+ return reply.status(404).send({
4773
+ success: false,
4774
+ error: "User not found"
4775
+ });
4776
+ }
4777
+ const isValidPassword = await this.verifyPassword(
4778
+ currentPassword,
4779
+ user.metadata?.passwordHash || ""
4780
+ );
4781
+ if (!isValidPassword) {
4782
+ return reply.status(401).send({
4783
+ success: false,
4784
+ error: "Current password is incorrect"
4785
+ });
4786
+ }
4787
+ if (newPassword.length < 6) {
4788
+ return reply.status(400).send({
4789
+ success: false,
4790
+ error: "New password must be at least 6 characters"
4791
+ });
4792
+ }
4793
+ await this.userStore.updateUser(userId, {
4794
+ metadata: {
4795
+ ...user.metadata,
4796
+ passwordHash: await this.hashPassword(newPassword)
4797
+ }
4798
+ });
4799
+ return reply.send({
4800
+ success: true,
4801
+ message: "Password changed successfully"
4802
+ });
4803
+ } catch (error) {
4804
+ console.error("Change password error:", error);
4805
+ return reply.status(500).send({
4806
+ success: false,
4807
+ error: "Failed to change password"
4808
+ });
4809
+ }
4810
+ }
4685
4811
  };
4686
4812
  function registerAuthRoutes(app2, config) {
4687
4813
  const controller = new AuthController(config);
@@ -4720,6 +4846,11 @@ function registerAuthRoutes(app2, config) {
4720
4846
  app2.post("/api/auth/approve", { preHandler: authHook }, (req, res) => controller.approveUser(req, res));
4721
4847
  app2.get("/api/auth/pending", { preHandler: authHook }, (req, res) => controller.listPendingUsers(req, res));
4722
4848
  app2.post("/api/auth/assign-tenant", { preHandler: authHook }, (req, res) => controller.assignTenant(req, res));
4849
+ app2.post(
4850
+ "/api/auth/change-password",
4851
+ { preHandler: authHook },
4852
+ (req, res) => controller.changePassword(req, res)
4853
+ );
4723
4854
  }
4724
4855
 
4725
4856
  // src/routes/index.ts
@@ -4856,6 +4987,10 @@ var registerLatticeRoutes = (app2) => {
4856
4987
  autoApproveUsers: process.env.AUTO_APPROVE_USERS !== "false",
4857
4988
  allowTenantRegistration: process.env.ALLOW_TENANT_REGISTRATION !== "false"
4858
4989
  });
4990
+ app2.delete(
4991
+ "/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
4992
+ removePendingMessageHandler
4993
+ );
4859
4994
  };
4860
4995
 
4861
4996
  // src/swagger.ts
@@ -4921,7 +5056,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
4921
5056
  };
4922
5057
 
4923
5058
  // src/services/agent_task_consumer.ts
4924
- import { eventBus as eventBus2, AGENT_TASK_EVENT, agentInstanceManager as agentInstanceManager4, QueueMode } from "@axiom-lattice/core";
5059
+ import { eventBus as eventBus2, AGENT_TASK_EVENT, agentInstanceManager as agentInstanceManager5, QueueMode as QueueMode2 } from "@axiom-lattice/core";
4925
5060
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
4926
5061
  const {
4927
5062
  assistant_id,
@@ -4936,8 +5071,8 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
4936
5071
  console.log(
4937
5072
  `\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
4938
5073
  );
4939
- const agent = agentInstanceManager4.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
4940
- await agent.addMessage({ input, command }, QueueMode.STEER);
5074
+ const agent = agentInstanceManager5.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
5075
+ await agent.addMessage({ input, command, custom_run_config: runConfig }, QueueMode2.STEER);
4941
5076
  if (callback_event) {
4942
5077
  agent.subscribeOnce("message:completed", (evt) => {
4943
5078
  eventBus2.publish(callback_event, {
@@ -5155,7 +5290,7 @@ import {
5155
5290
  sandboxLatticeManager as sandboxLatticeManager2,
5156
5291
  sqlDatabaseManager as sqlDatabaseManager2,
5157
5292
  getStoreLattice as getStoreLattice12,
5158
- agentInstanceManager as agentInstanceManager5
5293
+ agentInstanceManager as agentInstanceManager6
5159
5294
  } from "@axiom-lattice/core";
5160
5295
  import {
5161
5296
  LoggerType
@@ -5185,6 +5320,18 @@ var app = fastify({
5185
5320
  bodyLimit: Number(process.env.BODY_LIMIT) || 50 * 1024 * 1024
5186
5321
  // Default 50MB, configurable via BODY_LIMIT env var
5187
5322
  });
5323
+ app.addContentTypeParser("application/json", { parseAs: "string" }, function(request, body, done) {
5324
+ if (request.method === "DELETE" || !body || body.length === 0) {
5325
+ done(null, {});
5326
+ return;
5327
+ }
5328
+ try {
5329
+ const json = JSON.parse(body);
5330
+ done(null, json);
5331
+ } catch (err) {
5332
+ done(err, void 0);
5333
+ }
5334
+ });
5188
5335
  app.addHook("onRequest", (request, reply, done) => {
5189
5336
  const getHeaderValue = (header) => {
5190
5337
  if (Array.isArray(header)) {
@@ -5201,11 +5348,6 @@ app.addHook("onRequest", (request, reply, done) => {
5201
5348
  }
5202
5349
  done();
5203
5350
  });
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
5351
  app.addHook("onResponse", (request, reply, done) => {
5210
5352
  const getHeaderValue = (header) => {
5211
5353
  if (Array.isArray(header)) {
@@ -5309,7 +5451,7 @@ var start = async (config) => {
5309
5451
  }
5310
5452
  try {
5311
5453
  logger.info("Starting agent instance recovery...");
5312
- const restoreStats = await agentInstanceManager5.restore();
5454
+ const restoreStats = await agentInstanceManager6.restore();
5313
5455
  logger.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
5314
5456
  } catch (error) {
5315
5457
  logger.error("Agent recovery failed", { error });