@axiom-lattice/gateway 2.1.64 → 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.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +17 -0
- package/dist/index.js +56 -61
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/controllers/auth.ts +21 -27
- package/src/controllers/run.ts +15 -3
- package/src/index.ts +41 -48
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @axiom-lattice/gateway@2.1.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -9,22 +9,22 @@
|
|
|
9
9
|
[34mCLI[39m Cleaning output folder
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m199.60 KB[39m
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m433.06 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 312ms
|
|
12
15
|
[warn] [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m"import.meta" is not available with the "cjs" output format and will be empty[0m [empty-import-meta]
|
|
13
16
|
|
|
14
|
-
src/index.ts:
|
|
15
|
-
[37m
|
|
17
|
+
src/index.ts:171:33:
|
|
18
|
+
[37m 171 │ const __filename = fileURLToPath([32mimport.meta[37m.url);
|
|
16
19
|
╵ [32m~~~~~~~~~~~[0m
|
|
17
20
|
|
|
18
21
|
You need to set the output format to "esm" for "import.meta" to work correctly.
|
|
19
22
|
|
|
20
23
|
|
|
21
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
22
|
-
[32mCJS[39m [1mdist/index.js.map [22m[32m432.
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
24
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m199.74 KB[39m
|
|
25
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[32m432.91 KB[39m
|
|
26
|
-
[32mESM[39m ⚡️ Build success in 354ms
|
|
24
|
+
[32mCJS[39m [1mdist/index.js [22m[32m202.91 KB[39m
|
|
25
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m432.44 KB[39m
|
|
26
|
+
[32mCJS[39m ⚡️ Build success in 346ms
|
|
27
27
|
[34mDTS[39m Build start
|
|
28
|
-
[32mDTS[39m ⚡️ Build success in
|
|
28
|
+
[32mDTS[39m ⚡️ Build success in 12529ms
|
|
29
29
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.85 KB[39m
|
|
30
30
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.85 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @axiom-lattice/gateway
|
|
2
2
|
|
|
3
|
+
## 2.1.66
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a326dd4: add user id
|
|
8
|
+
|
|
9
|
+
## 2.1.65
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 3df9c3e: up version
|
|
14
|
+
- Updated dependencies [3df9c3e]
|
|
15
|
+
- @axiom-lattice/core@2.1.59
|
|
16
|
+
- @axiom-lattice/pg-stores@1.0.49
|
|
17
|
+
- @axiom-lattice/protocols@2.1.31
|
|
18
|
+
- @axiom-lattice/queue-redis@1.0.30
|
|
19
|
+
|
|
3
20
|
## 2.1.64
|
|
4
21
|
|
|
5
22
|
### 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
|
|
5025
|
-
if (!
|
|
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
|
|
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}`);
|