@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.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +12 -0
- package/dist/index.js +116 -61
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/controllers/auth.ts +21 -27
- package/src/controllers/run.ts +15 -3
- package/src/controllers/workflow-tracking.ts +84 -0
- package/src/index.ts +41 -48
- package/src/routes/index.ts +5 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @axiom-lattice/gateway@2.1.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -11,20 +11,20 @@
|
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[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
13
|
|
|
14
|
-
src/index.ts:
|
|
15
|
-
[37m
|
|
14
|
+
src/index.ts:171:33:
|
|
15
|
+
[37m 171 │ const __filename = fileURLToPath([32mimport.meta[37m.url);
|
|
16
16
|
╵ [32m~~~~~~~~~~~[0m
|
|
17
17
|
|
|
18
18
|
You need to set the output format to "esm" for "import.meta" to work correctly.
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
21
|
+
[32mCJS[39m [1mdist/index.js [22m[32m204.59 KB[39m
|
|
22
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m436.01 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 357ms
|
|
24
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m201.26 KB[39m
|
|
25
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m436.63 KB[39m
|
|
26
|
+
[32mESM[39m ⚡️ Build success in 362ms
|
|
27
27
|
[34mDTS[39m Build start
|
|
28
|
-
[32mDTS[39m ⚡️ Build success in
|
|
28
|
+
[32mDTS[39m ⚡️ Build success in 13253ms
|
|
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
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
|
|
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 {
|
|
5104
|
+
const user = extractUserFromAuthHeader(request.headers.authorization);
|
|
5105
|
+
if (!user) {
|
|
5045
5106
|
return reply.status(401).send({
|
|
5046
5107
|
success: false,
|
|
5047
|
-
error: "Unauthorized
|
|
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}`);
|