@axiom-lattice/gateway 2.1.49 → 2.1.50
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 +8 -8
- package/CHANGELOG.md +8 -0
- package/dist/index.js +243 -126
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/controllers/auth.ts +73 -0
- package/src/controllers/run.ts +10 -2
- package/src/controllers/thread_status.ts +66 -228
- package/src/index.ts +16 -9
- package/src/routes/index.ts +9 -0
- package/src/types/index.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -208,10 +208,12 @@ var createRun = async (request, reply) => {
|
|
|
208
208
|
const {
|
|
209
209
|
assistant_id,
|
|
210
210
|
thread_id,
|
|
211
|
+
message_id,
|
|
211
212
|
command,
|
|
212
213
|
streaming,
|
|
213
214
|
background,
|
|
214
215
|
custom_run_config,
|
|
216
|
+
mode,
|
|
215
217
|
...input
|
|
216
218
|
} = request.body;
|
|
217
219
|
const tenant_id = request.headers["x-tenant-id"];
|
|
@@ -242,11 +244,12 @@ var createRun = async (request, reply) => {
|
|
|
242
244
|
"Access-Control-Allow-Origin": "*"
|
|
243
245
|
});
|
|
244
246
|
try {
|
|
247
|
+
const messageInput = message_id ? { ...input, id: message_id } : input;
|
|
245
248
|
const result = await agent.addMessage({
|
|
246
|
-
input,
|
|
249
|
+
input: messageInput,
|
|
247
250
|
command,
|
|
248
251
|
custom_run_config
|
|
249
|
-
});
|
|
252
|
+
}, mode);
|
|
250
253
|
const stream = agent.chunkStream(result.messageId, [MessageChunkTypes.MESSAGE_COMPLETED]);
|
|
251
254
|
for await (const chunk of stream) {
|
|
252
255
|
const success = reply.raw.write(`data: ${JSON.stringify(chunk)}
|
|
@@ -2068,6 +2071,53 @@ var getHealthSchema = {
|
|
|
2068
2071
|
}
|
|
2069
2072
|
};
|
|
2070
2073
|
|
|
2074
|
+
// src/controllers/thread_status.ts
|
|
2075
|
+
import { agentInstanceManager as agentInstanceManager4 } from "@axiom-lattice/core";
|
|
2076
|
+
async function removePendingMessageHandler(request, reply) {
|
|
2077
|
+
try {
|
|
2078
|
+
const { assistant_id, thread_id, message_id } = request.params;
|
|
2079
|
+
const tenant_id = request.headers["x-tenant-id"];
|
|
2080
|
+
const workspace_id = request.headers["x-workspace-id"];
|
|
2081
|
+
const project_id = request.headers["x-project-id"];
|
|
2082
|
+
if (!tenant_id) {
|
|
2083
|
+
return reply.code(400).send({ error: "Missing x-tenant-id header" });
|
|
2084
|
+
}
|
|
2085
|
+
if (!assistant_id) {
|
|
2086
|
+
return reply.code(400).send({ error: "Missing assistant_id parameter" });
|
|
2087
|
+
}
|
|
2088
|
+
const agent = agentInstanceManager4.getAgent({
|
|
2089
|
+
assistant_id,
|
|
2090
|
+
thread_id,
|
|
2091
|
+
tenant_id,
|
|
2092
|
+
workspace_id,
|
|
2093
|
+
project_id
|
|
2094
|
+
});
|
|
2095
|
+
if (!agent) {
|
|
2096
|
+
return reply.code(404).send({
|
|
2097
|
+
error: "Thread not found",
|
|
2098
|
+
threadId: thread_id
|
|
2099
|
+
});
|
|
2100
|
+
}
|
|
2101
|
+
const success = await agent.removePendingMessage(message_id);
|
|
2102
|
+
if (!success) {
|
|
2103
|
+
return reply.code(404).send({
|
|
2104
|
+
error: "Message not found",
|
|
2105
|
+
messageId: message_id
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
return reply.send({
|
|
2109
|
+
success: true,
|
|
2110
|
+
messageId: message_id
|
|
2111
|
+
});
|
|
2112
|
+
} catch (error) {
|
|
2113
|
+
console.error("Error removing pending message:", error);
|
|
2114
|
+
return reply.code(500).send({
|
|
2115
|
+
error: "Internal server error",
|
|
2116
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2071
2121
|
// src/controllers/sandbox.ts
|
|
2072
2122
|
import { Readable } from "stream";
|
|
2073
2123
|
|
|
@@ -4682,6 +4732,57 @@ var AuthController = class {
|
|
|
4682
4732
|
}
|
|
4683
4733
|
return btoa(JSON.stringify(payload));
|
|
4684
4734
|
}
|
|
4735
|
+
async changePassword(request, reply) {
|
|
4736
|
+
const userId = request.user?.id;
|
|
4737
|
+
const { currentPassword, newPassword } = request.body;
|
|
4738
|
+
if (!userId) {
|
|
4739
|
+
return reply.status(401).send({
|
|
4740
|
+
success: false,
|
|
4741
|
+
error: "Unauthorized"
|
|
4742
|
+
});
|
|
4743
|
+
}
|
|
4744
|
+
try {
|
|
4745
|
+
const user = await this.userStore.getUserById(userId);
|
|
4746
|
+
if (!user) {
|
|
4747
|
+
return reply.status(404).send({
|
|
4748
|
+
success: false,
|
|
4749
|
+
error: "User not found"
|
|
4750
|
+
});
|
|
4751
|
+
}
|
|
4752
|
+
const isValidPassword = await this.verifyPassword(
|
|
4753
|
+
currentPassword,
|
|
4754
|
+
user.metadata?.passwordHash || ""
|
|
4755
|
+
);
|
|
4756
|
+
if (!isValidPassword) {
|
|
4757
|
+
return reply.status(401).send({
|
|
4758
|
+
success: false,
|
|
4759
|
+
error: "Current password is incorrect"
|
|
4760
|
+
});
|
|
4761
|
+
}
|
|
4762
|
+
if (newPassword.length < 6) {
|
|
4763
|
+
return reply.status(400).send({
|
|
4764
|
+
success: false,
|
|
4765
|
+
error: "New password must be at least 6 characters"
|
|
4766
|
+
});
|
|
4767
|
+
}
|
|
4768
|
+
await this.userStore.updateUser(userId, {
|
|
4769
|
+
metadata: {
|
|
4770
|
+
...user.metadata,
|
|
4771
|
+
passwordHash: await this.hashPassword(newPassword)
|
|
4772
|
+
}
|
|
4773
|
+
});
|
|
4774
|
+
return reply.send({
|
|
4775
|
+
success: true,
|
|
4776
|
+
message: "Password changed successfully"
|
|
4777
|
+
});
|
|
4778
|
+
} catch (error) {
|
|
4779
|
+
console.error("Change password error:", error);
|
|
4780
|
+
return reply.status(500).send({
|
|
4781
|
+
success: false,
|
|
4782
|
+
error: "Failed to change password"
|
|
4783
|
+
});
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4685
4786
|
};
|
|
4686
4787
|
function registerAuthRoutes(app2, config) {
|
|
4687
4788
|
const controller = new AuthController(config);
|
|
@@ -4720,6 +4821,11 @@ function registerAuthRoutes(app2, config) {
|
|
|
4720
4821
|
app2.post("/api/auth/approve", { preHandler: authHook }, (req, res) => controller.approveUser(req, res));
|
|
4721
4822
|
app2.get("/api/auth/pending", { preHandler: authHook }, (req, res) => controller.listPendingUsers(req, res));
|
|
4722
4823
|
app2.post("/api/auth/assign-tenant", { preHandler: authHook }, (req, res) => controller.assignTenant(req, res));
|
|
4824
|
+
app2.post(
|
|
4825
|
+
"/api/auth/change-password",
|
|
4826
|
+
{ preHandler: authHook },
|
|
4827
|
+
(req, res) => controller.changePassword(req, res)
|
|
4828
|
+
);
|
|
4723
4829
|
}
|
|
4724
4830
|
|
|
4725
4831
|
// src/routes/index.ts
|
|
@@ -4856,6 +4962,10 @@ var registerLatticeRoutes = (app2) => {
|
|
|
4856
4962
|
autoApproveUsers: process.env.AUTO_APPROVE_USERS !== "false",
|
|
4857
4963
|
allowTenantRegistration: process.env.ALLOW_TENANT_REGISTRATION !== "false"
|
|
4858
4964
|
});
|
|
4965
|
+
app2.delete(
|
|
4966
|
+
"/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
|
|
4967
|
+
removePendingMessageHandler
|
|
4968
|
+
);
|
|
4859
4969
|
};
|
|
4860
4970
|
|
|
4861
4971
|
// src/swagger.ts
|
|
@@ -4921,7 +5031,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
|
|
|
4921
5031
|
};
|
|
4922
5032
|
|
|
4923
5033
|
// src/services/agent_task_consumer.ts
|
|
4924
|
-
import { eventBus as eventBus2, AGENT_TASK_EVENT, agentInstanceManager as
|
|
5034
|
+
import { eventBus as eventBus2, AGENT_TASK_EVENT, agentInstanceManager as agentInstanceManager5, QueueMode as QueueMode2 } from "@axiom-lattice/core";
|
|
4925
5035
|
var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
4926
5036
|
const {
|
|
4927
5037
|
assistant_id,
|
|
@@ -4936,8 +5046,8 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
4936
5046
|
console.log(
|
|
4937
5047
|
`\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
4938
5048
|
);
|
|
4939
|
-
const agent =
|
|
4940
|
-
await agent.addMessage({ input, command },
|
|
5049
|
+
const agent = agentInstanceManager5.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
|
|
5050
|
+
await agent.addMessage({ input, command }, QueueMode2.STEER);
|
|
4941
5051
|
if (callback_event) {
|
|
4942
5052
|
agent.subscribeOnce("message:completed", (evt) => {
|
|
4943
5053
|
eventBus2.publish(callback_event, {
|
|
@@ -5155,7 +5265,7 @@ import {
|
|
|
5155
5265
|
sandboxLatticeManager as sandboxLatticeManager2,
|
|
5156
5266
|
sqlDatabaseManager as sqlDatabaseManager2,
|
|
5157
5267
|
getStoreLattice as getStoreLattice12,
|
|
5158
|
-
agentInstanceManager as
|
|
5268
|
+
agentInstanceManager as agentInstanceManager6
|
|
5159
5269
|
} from "@axiom-lattice/core";
|
|
5160
5270
|
import {
|
|
5161
5271
|
LoggerType
|
|
@@ -5185,6 +5295,18 @@ var app = fastify({
|
|
|
5185
5295
|
bodyLimit: Number(process.env.BODY_LIMIT) || 50 * 1024 * 1024
|
|
5186
5296
|
// Default 50MB, configurable via BODY_LIMIT env var
|
|
5187
5297
|
});
|
|
5298
|
+
app.addContentTypeParser("application/json", { parseAs: "string" }, function(request, body, done) {
|
|
5299
|
+
if (request.method === "DELETE" || !body || body.length === 0) {
|
|
5300
|
+
done(null, {});
|
|
5301
|
+
return;
|
|
5302
|
+
}
|
|
5303
|
+
try {
|
|
5304
|
+
const json = JSON.parse(body);
|
|
5305
|
+
done(null, json);
|
|
5306
|
+
} catch (err) {
|
|
5307
|
+
done(err, void 0);
|
|
5308
|
+
}
|
|
5309
|
+
});
|
|
5188
5310
|
app.addHook("onRequest", (request, reply, done) => {
|
|
5189
5311
|
const getHeaderValue = (header) => {
|
|
5190
5312
|
if (Array.isArray(header)) {
|
|
@@ -5201,11 +5323,6 @@ app.addHook("onRequest", (request, reply, done) => {
|
|
|
5201
5323
|
}
|
|
5202
5324
|
done();
|
|
5203
5325
|
});
|
|
5204
|
-
app.addHook("onRequest", async (request, reply) => {
|
|
5205
|
-
if (request.method === "DELETE" && request.headers["content-type"]) {
|
|
5206
|
-
delete request.headers["content-type"];
|
|
5207
|
-
}
|
|
5208
|
-
});
|
|
5209
5326
|
app.addHook("onResponse", (request, reply, done) => {
|
|
5210
5327
|
const getHeaderValue = (header) => {
|
|
5211
5328
|
if (Array.isArray(header)) {
|
|
@@ -5309,7 +5426,7 @@ var start = async (config) => {
|
|
|
5309
5426
|
}
|
|
5310
5427
|
try {
|
|
5311
5428
|
logger.info("Starting agent instance recovery...");
|
|
5312
|
-
const restoreStats = await
|
|
5429
|
+
const restoreStats = await agentInstanceManager6.restore();
|
|
5313
5430
|
logger.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
|
|
5314
5431
|
} catch (error) {
|
|
5315
5432
|
logger.error("Agent recovery failed", { error });
|