@axiom-lattice/gateway 2.1.76 → 2.1.78

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
@@ -1717,7 +1717,7 @@ async function executeSqlQuery(client, body, reply) {
1717
1717
  }
1718
1718
 
1719
1719
  // src/controllers/workflow-tracking.ts
1720
- import { getStoreLattice as getStoreLattice4, agentInstanceManager as agentInstanceManager4 } from "@axiom-lattice/core";
1720
+ import { getStoreLattice as getStoreLattice4, agentInstanceManager as agentInstanceManager4, ThreadStatus as ThreadStatus2 } from "@axiom-lattice/core";
1721
1721
  import { MessageChunkTypes as MessageChunkTypes2 } from "@axiom-lattice/protocols";
1722
1722
  function getTenantId6(request) {
1723
1723
  const userTenantId = request.user?.tenantId;
@@ -1963,6 +1963,41 @@ async function getWorkflowRun(request, reply) {
1963
1963
  return reply.status(500).send({ success: false, message: "Failed to retrieve workflow run" });
1964
1964
  }
1965
1965
  }
1966
+ async function deleteWorkflowRun(request, reply) {
1967
+ const { runId } = request.params;
1968
+ const tenantId = getTenantId6(request);
1969
+ try {
1970
+ const store = getTrackingStore();
1971
+ if (!store) {
1972
+ return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
1973
+ }
1974
+ const run = await store.getWorkflowRun(runId);
1975
+ if (!run) {
1976
+ return reply.status(404).send({ success: false, message: "Workflow run not found" });
1977
+ }
1978
+ if (run.status === "running") {
1979
+ try {
1980
+ const workspace_id = request.headers["x-workspace-id"];
1981
+ const project_id = request.headers["x-project-id"];
1982
+ const agent = agentInstanceManager4.getAgent({
1983
+ assistant_id: run.assistantId,
1984
+ thread_id: run.threadId,
1985
+ tenant_id: tenantId,
1986
+ workspace_id,
1987
+ project_id
1988
+ });
1989
+ await agent.abort();
1990
+ } catch (err) {
1991
+ request.log.warn({ runId, error: err.message }, "Failed to abort agent, deleting tracking records anyway");
1992
+ }
1993
+ }
1994
+ await store.deleteWorkflowRun(runId);
1995
+ return { success: true, message: "Workflow run deleted" };
1996
+ } catch (error) {
1997
+ request.log.error(error, "Failed to delete workflow run");
1998
+ return reply.status(500).send({ success: false, message: "Failed to delete workflow run" });
1999
+ }
2000
+ }
1966
2001
  async function getRunSteps(request, reply) {
1967
2002
  const { runId } = request.params;
1968
2003
  const { step_type, status: stepStatus } = request.query;
@@ -2035,6 +2070,14 @@ async function replyInboxTask(request, reply) {
2035
2070
  workspace_id,
2036
2071
  project_id
2037
2072
  });
2073
+ const runStatus = await agent.getRunStatus();
2074
+ if (runStatus !== ThreadStatus2.INTERRUPTED) {
2075
+ return reply.status(409).send({
2076
+ success: false,
2077
+ message: `Cannot resume: graph is not interrupted (current status: ${runStatus})`,
2078
+ data: { runId: run.id, assistantId: run.assistantId, threadId: run.threadId, status: runStatus }
2079
+ });
2080
+ }
2038
2081
  agent.addMessage({
2039
2082
  input: { message: "Clarification answers submitted" },
2040
2083
  command: {
@@ -6524,7 +6567,7 @@ var registerLatticeRoutes = (app2, channelDeps) => {
6524
6567
  const inboundMessage = {
6525
6568
  channel: msg.channel,
6526
6569
  channelInstallationId: msg.channelInstallationId || "",
6527
- tenantId: msg.tenantId || "default",
6570
+ tenantId: msg.tenantId,
6528
6571
  sender: {
6529
6572
  id: msg.sender.id,
6530
6573
  displayName: msg.sender.displayName
@@ -6565,6 +6608,7 @@ var registerLatticeRoutes = (app2, channelDeps) => {
6565
6608
  getWorkflowRuns
6566
6609
  );
6567
6610
  app2.get("/api/workflows/runs/:runId", getWorkflowRun);
6611
+ app2.delete("/api/workflows/runs/:runId", deleteWorkflowRun);
6568
6612
  app2.get("/api/workflows/runs/:runId/steps", getRunSteps);
6569
6613
  app2.get("/api/workflows/runs/:runId/tasks", getRunTasks);
6570
6614
  app2.post("/api/workflows/inbox/reply", replyInboxTask);
@@ -6603,11 +6647,17 @@ var MessageRouter = class {
6603
6647
  };
6604
6648
  try {
6605
6649
  await this.runMiddlewares(ctx, async () => {
6650
+ const tenantId = message.tenantId || (await this.installationStore.getInstallationById(message.channelInstallationId))?.tenantId;
6651
+ if (!tenantId) {
6652
+ throw new Error(
6653
+ "tenantId is required: provide it in the message or ensure the channelInstallation has a tenantId"
6654
+ );
6655
+ }
6606
6656
  let binding = await this.bindingRegistry.resolve({
6607
6657
  channel: message.channel,
6608
6658
  senderId: message.sender.id,
6609
6659
  channelInstallationId: message.channelInstallationId,
6610
- tenantId: message.tenantId
6660
+ tenantId
6611
6661
  });
6612
6662
  if (!binding) {
6613
6663
  const installation = await this.installationStore.getInstallationById(
@@ -6623,7 +6673,7 @@ var MessageRouter = class {
6623
6673
  id: "fallback",
6624
6674
  channel: message.channel,
6625
6675
  channelInstallationId: message.channelInstallationId,
6626
- tenantId: message.tenantId,
6676
+ tenantId,
6627
6677
  senderId: message.sender.id,
6628
6678
  agentId: installation.fallbackAgentId,
6629
6679
  threadId: void 0,
@@ -6649,7 +6699,7 @@ var MessageRouter = class {
6649
6699
  const threadStore = getStoreLattice14("default", "thread").store;
6650
6700
  const newThreadId = randomUUID7();
6651
6701
  const newThread = await threadStore.createThread(
6652
- message.tenantId,
6702
+ tenantId,
6653
6703
  ctx.binding.agentId,
6654
6704
  newThreadId,
6655
6705
  {
@@ -6670,7 +6720,7 @@ var MessageRouter = class {
6670
6720
  }
6671
6721
  }
6672
6722
  const agent = agentInstanceManager6.getAgent({
6673
- tenant_id: message.tenantId,
6723
+ tenant_id: tenantId,
6674
6724
  assistant_id: ctx.binding.agentId,
6675
6725
  thread_id: threadId,
6676
6726
  workspace_id: ctx.binding.workspaceId || "",