@axiom-lattice/gateway 2.1.65 → 2.1.66

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.66 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
@@ -9,22 +9,22 @@
9
9
  CLI Cleaning output folder
10
10
  CJS Build start
11
11
  ESM Build start
12
+ ESM dist/index.mjs 199.60 KB
13
+ ESM dist/index.mjs.map 433.06 KB
14
+ ESM ⚡️ Build success in 312ms
12
15
  [warn] ▲ [WARNING] "import.meta" is not available with the "cjs" output format and will be empty [empty-import-meta]
13
16
 
14
- src/index.ts:152:33:
15
-  152 │ const __filename = fileURLToPath(import.meta.url);
17
+ src/index.ts:171:33:
18
+  171 │ const __filename = fileURLToPath(import.meta.url);
16
19
  ╵ ~~~~~~~~~~~
17
20
 
18
21
  You need to set the output format to "esm" for "import.meta" to work correctly.
19
22
 
20
23
 
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
24
+ CJS dist/index.js 202.91 KB
25
+ CJS dist/index.js.map 432.44 KB
26
+ CJS ⚡️ Build success in 346ms
27
27
  DTS Build start
28
- DTS ⚡️ Build success in 12510ms
28
+ DTS ⚡️ Build success in 12529ms
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,11 @@
1
1
  # @axiom-lattice/gateway
2
2
 
3
+ ## 2.1.66
4
+
5
+ ### Patch Changes
6
+
7
+ - a326dd4: add user id
8
+
3
9
  ## 2.1.65
4
10
 
5
11
  ### 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,
@@ -5018,35 +5025,31 @@ var AuthController = class {
5018
5025
  }
5019
5026
  }
5020
5027
  };
5028
+ function extractUserFromAuthHeader(authHeader) {
5029
+ if (!authHeader?.startsWith("Bearer ")) return void 0;
5030
+ const token = authHeader.substring(7);
5031
+ try {
5032
+ const payload = JSON.parse(atob(token));
5033
+ if (payload.exp && payload.exp < Date.now()) return void 0;
5034
+ return {
5035
+ id: payload.userId,
5036
+ tenantId: payload.tenantId
5037
+ };
5038
+ } catch {
5039
+ return void 0;
5040
+ }
5041
+ }
5021
5042
  function registerAuthRoutes(app2, config) {
5022
5043
  const controller = new AuthController(config);
5023
5044
  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 {
5045
+ const user = extractUserFromAuthHeader(request.headers.authorization);
5046
+ if (!user) {
5045
5047
  return reply.status(401).send({
5046
5048
  success: false,
5047
- error: "Unauthorized - Invalid token"
5049
+ error: "Unauthorized"
5048
5050
  });
5049
5051
  }
5052
+ request.user = user;
5050
5053
  };
5051
5054
  app2.post("/api/auth/register", controller.register.bind(controller));
5052
5055
  app2.post("/api/auth/login", controller.login.bind(controller));
@@ -6279,16 +6282,33 @@ app.addContentTypeParser("application/json", { parseAs: "string" }, function(req
6279
6282
  done(err, void 0);
6280
6283
  }
6281
6284
  });
6285
+ var getHeaderValue = (header) => {
6286
+ if (Array.isArray(header)) {
6287
+ return header[0];
6288
+ }
6289
+ return header;
6290
+ };
6291
+ var PUBLIC_ROUTES = ["/api/auth/login", "/api/auth/register", "/health"];
6292
+ app.addHook("preHandler", async (request, reply) => {
6293
+ const user = extractUserFromAuthHeader(request.headers.authorization);
6294
+ if (user) {
6295
+ request.user = user;
6296
+ return;
6297
+ }
6298
+ const authRequired = process.env.AUTH_REQUIRED === "true";
6299
+ if (!authRequired) return;
6300
+ if (request.method === "OPTIONS") return;
6301
+ if (PUBLIC_ROUTES.some((r) => request.url === r)) return;
6302
+ return reply.status(401).send({
6303
+ success: false,
6304
+ error: "Unauthorized - Missing or invalid token"
6305
+ });
6306
+ });
6282
6307
  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
6308
  const context = {
6290
6309
  "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
6291
- "x-request-id": getHeaderValue(request.headers["x-request-id"])
6310
+ "x-request-id": getHeaderValue(request.headers["x-request-id"]),
6311
+ "x-user-id": getHeaderValue(request.headers["x-user-id"])
6292
6312
  };
6293
6313
  if (loggerLattice.updateContext) {
6294
6314
  loggerLattice.updateContext(context);
@@ -6296,15 +6316,10 @@ app.addHook("onRequest", (request, reply, done) => {
6296
6316
  done();
6297
6317
  });
6298
6318
  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
6319
  const context = {
6306
6320
  "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
6307
- "x-request-id": getHeaderValue(request.headers["x-request-id"])
6321
+ "x-request-id": getHeaderValue(request.headers["x-request-id"]),
6322
+ "x-user-id": getHeaderValue(request.headers["x-user-id"])
6308
6323
  };
6309
6324
  done();
6310
6325
  });
@@ -6329,15 +6344,10 @@ app.register(import_static.default, {
6329
6344
  prefix: "/"
6330
6345
  });
6331
6346
  app.setErrorHandler((error, request, reply) => {
6332
- const getHeaderValue = (header) => {
6333
- if (Array.isArray(header)) {
6334
- return header[0];
6335
- }
6336
- return header;
6337
- };
6338
6347
  const context = {
6339
6348
  "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
6340
- "x-request-id": getHeaderValue(request.headers["x-request-id"])
6349
+ "x-request-id": getHeaderValue(request.headers["x-request-id"]),
6350
+ "x-user-id": getHeaderValue(request.headers["x-user-id"])
6341
6351
  };
6342
6352
  logger.error(
6343
6353
  `\u8BF7\u6C42\u9519\u8BEF: ${request.method} ${request.url} error:${error.message}`,
@@ -6395,21 +6405,6 @@ var start = async (config) => {
6395
6405
  import_core29.sandboxLatticeManager.registerLattice("default", getConfiguredSandboxProvider());
6396
6406
  logger.info("Registered sandbox manager from env configuration");
6397
6407
  }
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
6408
  const target_port = config?.port || Number(process.env.PORT) || 4001;
6414
6409
  await app.listen({ port: target_port, host: "0.0.0.0" });
6415
6410
  logger.info(`Lattice Gateway is running on port: ${target_port}`);