@axiom-lattice/gateway 2.1.65 → 2.1.67

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @axiom-lattice/gateway@2.1.65 build /home/runner/work/agentic/agentic/packages/gateway
2
+ > @axiom-lattice/gateway@2.1.67 build /home/runner/work/agentic/agentic/packages/gateway
3
3
  > tsup src/index.ts --format cjs,esm --dts --clean --sourcemap
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -11,20 +11,20 @@
11
11
  ESM Build start
12
12
  [warn] ▲ [WARNING] "import.meta" is not available with the "cjs" output format and will be empty [empty-import-meta]
13
13
 
14
- src/index.ts:152:33:
15
-  152 │ const __filename = fileURLToPath(import.meta.url);
14
+ src/index.ts:171:33:
15
+  171 │ const __filename = fileURLToPath(import.meta.url);
16
16
  ╵ ~~~~~~~~~~~
17
17
 
18
18
  You need to set the output format to "esm" for "import.meta" to work correctly.
19
19
 
20
20
 
21
- ESM dist/index.mjs 199.74 KB
22
- ESM dist/index.mjs.map 432.91 KB
23
- ESM ⚡️ Build success in 395ms
24
- CJS dist/index.js 203.07 KB
25
- CJS dist/index.js.map 432.28 KB
26
- CJS ⚡️ Build success in 403ms
21
+ CJS dist/index.js 204.59 KB
22
+ CJS dist/index.js.map 436.01 KB
23
+ CJS ⚡️ Build success in 357ms
24
+ ESM dist/index.mjs 201.26 KB
25
+ ESM dist/index.mjs.map 436.63 KB
26
+ ESM ⚡️ Build success in 362ms
27
27
  DTS Build start
28
- DTS ⚡️ Build success in 12510ms
28
+ DTS ⚡️ Build success in 13253ms
29
29
  DTS dist/index.d.ts 3.85 KB
30
30
  DTS dist/index.d.mts 3.85 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @axiom-lattice/gateway
2
2
 
3
+ ## 2.1.67
4
+
5
+ ### Patch Changes
6
+
7
+ - dd414e2: add /api/workflows/inbox/reply
8
+
9
+ ## 2.1.66
10
+
11
+ ### Patch Changes
12
+
13
+ - a326dd4: add user id
14
+
3
15
  ## 2.1.65
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -236,6 +236,11 @@ var getAgentGraph = async (request, reply) => {
236
236
  var import_uuid = require("uuid");
237
237
  var import_core3 = require("@axiom-lattice/core");
238
238
  var import_protocols = require("@axiom-lattice/protocols");
239
+ function getUserId(request) {
240
+ const authUser = request.user;
241
+ if (authUser?.id) return authUser.id;
242
+ return request.headers["x-user-id"] || void 0;
243
+ }
239
244
  var createRun = async (request, reply) => {
240
245
  try {
241
246
  const {
@@ -253,6 +258,8 @@ var createRun = async (request, reply) => {
253
258
  const workspace_id = request.headers["x-workspace-id"];
254
259
  const project_id = request.headers["x-project-id"];
255
260
  const x_request_id = request.headers["x-request-id"] || (0, import_uuid.v4)();
261
+ const user_id = getUserId(request);
262
+ const mergedConfig = user_id ? { ...custom_run_config, user_id } : custom_run_config;
256
263
  if (!assistant_id) {
257
264
  reply.status(400).send({
258
265
  success: false,
@@ -266,7 +273,7 @@ var createRun = async (request, reply) => {
266
273
  tenant_id,
267
274
  workspace_id,
268
275
  project_id,
269
- custom_run_config
276
+ custom_run_config: mergedConfig
270
277
  });
271
278
  if (streaming) {
272
279
  reply.hijack();
@@ -281,7 +288,7 @@ var createRun = async (request, reply) => {
281
288
  const result = await agent.addMessage({
282
289
  input: messageInput,
283
290
  command,
284
- custom_run_config
291
+ custom_run_config: mergedConfig
285
292
  }, mode);
286
293
  const stream = agent.chunkStream(result.messageId, [import_protocols.MessageChunkTypes.MESSAGE_COMPLETED]);
287
294
  for await (const chunk of stream) {
@@ -311,7 +318,7 @@ var createRun = async (request, reply) => {
311
318
  const result = await agent.invoke({
312
319
  input: { message: msg, ...restInputNonStream },
313
320
  command,
314
- custom_run_config
321
+ custom_run_config: mergedConfig
315
322
  });
316
323
  reply.status(200).send({
317
324
  success: true,
@@ -2023,6 +2030,65 @@ async function getRunTasks(request, reply) {
2023
2030
  return reply.status(500).send({ success: false, message: "Failed to retrieve user tasks" });
2024
2031
  }
2025
2032
  }
2033
+ async function replyInboxTask(request, reply) {
2034
+ const { runId, answers } = request.body;
2035
+ const tenantId = getTenantId6(request);
2036
+ try {
2037
+ const store = getTrackingStore();
2038
+ if (!store) {
2039
+ return reply.status(404).send({
2040
+ success: false,
2041
+ message: "No workflow tracking store configured"
2042
+ });
2043
+ }
2044
+ const run = await store.getWorkflowRun(runId);
2045
+ if (!run) {
2046
+ return reply.status(404).send({
2047
+ success: false,
2048
+ message: "Workflow run not found"
2049
+ });
2050
+ }
2051
+ const agent = import_core13.agentInstanceManager.getAgent({
2052
+ assistant_id: run.assistantId,
2053
+ thread_id: run.threadId,
2054
+ tenant_id: tenantId
2055
+ });
2056
+ try {
2057
+ await agent.addMessage({
2058
+ input: { message: "Clarification answers submitted" },
2059
+ command: {
2060
+ resume: {
2061
+ action: "submit",
2062
+ data: { answers },
2063
+ message: "Clarification answers submitted"
2064
+ }
2065
+ }
2066
+ });
2067
+ } catch (error) {
2068
+ return reply.status(400).send({
2069
+ success: false,
2070
+ message: "Failed to resume workflow",
2071
+ error: error instanceof Error ? error.message : String(error)
2072
+ });
2073
+ }
2074
+ return reply.status(200).send({
2075
+ success: true,
2076
+ message: "Resume request submitted successfully",
2077
+ data: {
2078
+ runId: run.id,
2079
+ assistantId: run.assistantId,
2080
+ threadId: run.threadId,
2081
+ status: "resuming"
2082
+ }
2083
+ });
2084
+ } catch (error) {
2085
+ request.log.error(error, "Failed to reply inbox task");
2086
+ return reply.status(500).send({
2087
+ success: false,
2088
+ message: "Failed to submit resume request"
2089
+ });
2090
+ }
2091
+ }
2026
2092
 
2027
2093
  // src/schemas/data-query.ts
2028
2094
  var dataQuerySchema = {
@@ -5018,35 +5084,31 @@ var AuthController = class {
5018
5084
  }
5019
5085
  }
5020
5086
  };
5087
+ function extractUserFromAuthHeader(authHeader) {
5088
+ if (!authHeader?.startsWith("Bearer ")) return void 0;
5089
+ const token = authHeader.substring(7);
5090
+ try {
5091
+ const payload = JSON.parse(atob(token));
5092
+ if (payload.exp && payload.exp < Date.now()) return void 0;
5093
+ return {
5094
+ id: payload.userId,
5095
+ tenantId: payload.tenantId
5096
+ };
5097
+ } catch {
5098
+ return void 0;
5099
+ }
5100
+ }
5021
5101
  function registerAuthRoutes(app2, config) {
5022
5102
  const controller = new AuthController(config);
5023
5103
  const authHook = async (request, reply) => {
5024
- const authHeader = request.headers.authorization;
5025
- if (!authHeader || !authHeader.startsWith("Bearer ")) {
5026
- return reply.status(401).send({
5027
- success: false,
5028
- error: "Unauthorized - Missing or invalid token"
5029
- });
5030
- }
5031
- const token = authHeader.substring(7);
5032
- try {
5033
- const payload = JSON.parse(atob(token));
5034
- if (payload.exp && payload.exp < Date.now()) {
5035
- return reply.status(401).send({
5036
- success: false,
5037
- error: "Unauthorized - Token expired"
5038
- });
5039
- }
5040
- request.user = {
5041
- id: payload.userId,
5042
- tenantId: payload.tenantId
5043
- };
5044
- } catch {
5104
+ const user = extractUserFromAuthHeader(request.headers.authorization);
5105
+ if (!user) {
5045
5106
  return reply.status(401).send({
5046
5107
  success: false,
5047
- error: "Unauthorized - Invalid token"
5108
+ error: "Unauthorized"
5048
5109
  });
5049
5110
  }
5111
+ request.user = user;
5050
5112
  };
5051
5113
  app2.post("/api/auth/register", controller.register.bind(controller));
5052
5114
  app2.post("/api/auth/login", controller.login.bind(controller));
@@ -5912,6 +5974,7 @@ var registerLatticeRoutes = (app2) => {
5912
5974
  app2.get("/api/workflows/runs/:runId", getWorkflowRun);
5913
5975
  app2.get("/api/workflows/runs/:runId/steps", getRunSteps);
5914
5976
  app2.get("/api/workflows/runs/:runId/tasks", getRunTasks);
5977
+ app2.post("/api/workflows/inbox/reply", replyInboxTask);
5915
5978
  app2.delete(
5916
5979
  "/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
5917
5980
  removePendingMessageHandler
@@ -6279,16 +6342,33 @@ app.addContentTypeParser("application/json", { parseAs: "string" }, function(req
6279
6342
  done(err, void 0);
6280
6343
  }
6281
6344
  });
6345
+ var getHeaderValue = (header) => {
6346
+ if (Array.isArray(header)) {
6347
+ return header[0];
6348
+ }
6349
+ return header;
6350
+ };
6351
+ var PUBLIC_ROUTES = ["/api/auth/login", "/api/auth/register", "/health"];
6352
+ app.addHook("preHandler", async (request, reply) => {
6353
+ const user = extractUserFromAuthHeader(request.headers.authorization);
6354
+ if (user) {
6355
+ request.user = user;
6356
+ return;
6357
+ }
6358
+ const authRequired = process.env.AUTH_REQUIRED === "true";
6359
+ if (!authRequired) return;
6360
+ if (request.method === "OPTIONS") return;
6361
+ if (PUBLIC_ROUTES.some((r) => request.url === r)) return;
6362
+ return reply.status(401).send({
6363
+ success: false,
6364
+ error: "Unauthorized - Missing or invalid token"
6365
+ });
6366
+ });
6282
6367
  app.addHook("onRequest", (request, reply, done) => {
6283
- const getHeaderValue = (header) => {
6284
- if (Array.isArray(header)) {
6285
- return header[0];
6286
- }
6287
- return header;
6288
- };
6289
6368
  const context = {
6290
6369
  "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
6291
- "x-request-id": getHeaderValue(request.headers["x-request-id"])
6370
+ "x-request-id": getHeaderValue(request.headers["x-request-id"]),
6371
+ "x-user-id": getHeaderValue(request.headers["x-user-id"])
6292
6372
  };
6293
6373
  if (loggerLattice.updateContext) {
6294
6374
  loggerLattice.updateContext(context);
@@ -6296,15 +6376,10 @@ app.addHook("onRequest", (request, reply, done) => {
6296
6376
  done();
6297
6377
  });
6298
6378
  app.addHook("onResponse", (request, reply, done) => {
6299
- const getHeaderValue = (header) => {
6300
- if (Array.isArray(header)) {
6301
- return header[0];
6302
- }
6303
- return header;
6304
- };
6305
6379
  const context = {
6306
6380
  "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
6307
- "x-request-id": getHeaderValue(request.headers["x-request-id"])
6381
+ "x-request-id": getHeaderValue(request.headers["x-request-id"]),
6382
+ "x-user-id": getHeaderValue(request.headers["x-user-id"])
6308
6383
  };
6309
6384
  done();
6310
6385
  });
@@ -6329,15 +6404,10 @@ app.register(import_static.default, {
6329
6404
  prefix: "/"
6330
6405
  });
6331
6406
  app.setErrorHandler((error, request, reply) => {
6332
- const getHeaderValue = (header) => {
6333
- if (Array.isArray(header)) {
6334
- return header[0];
6335
- }
6336
- return header;
6337
- };
6338
6407
  const context = {
6339
6408
  "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
6340
- "x-request-id": getHeaderValue(request.headers["x-request-id"])
6409
+ "x-request-id": getHeaderValue(request.headers["x-request-id"]),
6410
+ "x-user-id": getHeaderValue(request.headers["x-user-id"])
6341
6411
  };
6342
6412
  logger.error(
6343
6413
  `\u8BF7\u6C42\u9519\u8BEF: ${request.method} ${request.url} error:${error.message}`,
@@ -6395,21 +6465,6 @@ var start = async (config) => {
6395
6465
  import_core29.sandboxLatticeManager.registerLattice("default", getConfiguredSandboxProvider());
6396
6466
  logger.info("Registered sandbox manager from env configuration");
6397
6467
  }
6398
- if (process.env.DATABASE_URL) {
6399
- try {
6400
- const { PostgreSQLWorkflowTrackingStore } = await import("@axiom-lattice/pg-stores");
6401
- const pgStore = new PostgreSQLWorkflowTrackingStore({
6402
- poolConfig: process.env.DATABASE_URL
6403
- });
6404
- if (import_core29.storeLatticeManager.hasLattice("default", "workflowTracking")) {
6405
- import_core29.storeLatticeManager.removeLattice("default", "workflowTracking");
6406
- }
6407
- import_core29.storeLatticeManager.registerLattice("default", "workflowTracking", pgStore);
6408
- logger.info("Workflow tracking store switched to PostgreSQL");
6409
- } catch (error) {
6410
- logger.warn("Failed to switch workflow tracking to PostgreSQL, keeping in-memory: " + (error instanceof Error ? error.message : String(error)));
6411
- }
6412
- }
6413
6468
  const target_port = config?.port || Number(process.env.PORT) || 4001;
6414
6469
  await app.listen({ port: target_port, host: "0.0.0.0" });
6415
6470
  logger.info(`Lattice Gateway is running on port: ${target_port}`);