@axiom-lattice/gateway 2.1.92 → 2.1.93
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 +9 -9
- package/CHANGELOG.md +12 -0
- package/dist/index.js +961 -385
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +865 -288
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/scripts/seed-lark-installation.ts +54 -0
- package/src/channels/lark/LarkChannelAdapter.ts +140 -18
- package/src/channels/lark/types.ts +0 -13
- package/src/channels/lark/verification.ts +1 -36
- package/src/controllers/__tests__/run.test.ts +115 -0
- package/src/controllers/__tests__/tasks.test.ts +215 -0
- package/src/controllers/agent_task.ts +7 -0
- package/src/controllers/assistant.ts +15 -2
- package/src/controllers/auth.ts +9 -0
- package/src/controllers/menu-items.ts +114 -0
- package/src/controllers/personal-assistant.ts +191 -0
- package/src/controllers/run.ts +47 -0
- package/src/controllers/tasks.ts +187 -0
- package/src/index.ts +50 -20
- package/src/router/MessageRouter.ts +107 -41
- package/src/routes/index.ts +23 -0
- package/src/routes/menu-items.ts +10 -0
- package/src/services/agent_task_consumer.ts +2 -8
- package/src/channels/lark/__tests__/aggregator.test.ts +0 -23
- package/src/channels/lark/aggregator.ts +0 -16
- package/src/channels/lark/config.ts +0 -44
- package/src/channels/lark/runner.ts +0 -37
package/dist/index.js
CHANGED
|
@@ -56,8 +56,8 @@ async function createLarkSender(config, client) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
async function createDefaultLarkClient(config) {
|
|
59
|
-
const
|
|
60
|
-
return new
|
|
59
|
+
const Lark2 = await import("@larksuiteoapi/node-sdk");
|
|
60
|
+
return new Lark2.Client({
|
|
61
61
|
appId: config.appId,
|
|
62
62
|
appSecret: config.appSecret
|
|
63
63
|
});
|
|
@@ -303,7 +303,7 @@ async function handleTasksSend(request, reply) {
|
|
|
303
303
|
taskStore.set(taskId, record);
|
|
304
304
|
let agent;
|
|
305
305
|
try {
|
|
306
|
-
agent =
|
|
306
|
+
agent = import_core34.agentInstanceManager.getAgent({
|
|
307
307
|
assistant_id: assistantId,
|
|
308
308
|
thread_id: threadId,
|
|
309
309
|
tenant_id: tenantId,
|
|
@@ -395,7 +395,7 @@ async function handleTasksCancel(request, reply) {
|
|
|
395
395
|
return;
|
|
396
396
|
}
|
|
397
397
|
try {
|
|
398
|
-
const agent =
|
|
398
|
+
const agent = import_core34.agentInstanceManager.getAgent({
|
|
399
399
|
assistant_id: record.assistantId,
|
|
400
400
|
thread_id: record.threadId,
|
|
401
401
|
tenant_id: record.tenantId,
|
|
@@ -432,7 +432,7 @@ async function handleTasksStream(request, reply) {
|
|
|
432
432
|
}
|
|
433
433
|
let agent;
|
|
434
434
|
try {
|
|
435
|
-
agent =
|
|
435
|
+
agent = import_core34.agentInstanceManager.getAgent({
|
|
436
436
|
assistant_id: record.assistantId,
|
|
437
437
|
thread_id: record.threadId,
|
|
438
438
|
tenant_id: record.tenantId,
|
|
@@ -627,12 +627,12 @@ function registerA2ARoutes(app2) {
|
|
|
627
627
|
handleApiKeyRotate
|
|
628
628
|
);
|
|
629
629
|
}
|
|
630
|
-
var import_uuid9,
|
|
630
|
+
var import_uuid9, import_core34, import_protocols4, taskStore, _a2aKeyStore, _storeKeyMap;
|
|
631
631
|
var init_a2a = __esm({
|
|
632
632
|
"src/routes/a2a.ts"() {
|
|
633
633
|
"use strict";
|
|
634
634
|
import_uuid9 = require("uuid");
|
|
635
|
-
|
|
635
|
+
import_core34 = require("@axiom-lattice/core");
|
|
636
636
|
import_protocols4 = require("@axiom-lattice/protocols");
|
|
637
637
|
taskStore = /* @__PURE__ */ new Map();
|
|
638
638
|
_a2aKeyStore = null;
|
|
@@ -666,6 +666,11 @@ function getTenantId(request) {
|
|
|
666
666
|
}
|
|
667
667
|
return request.headers["x-tenant-id"] || "default";
|
|
668
668
|
}
|
|
669
|
+
function getUserId(request) {
|
|
670
|
+
const userId = request.user?.id;
|
|
671
|
+
if (userId) return userId;
|
|
672
|
+
return request.headers["x-user-id"] || void 0;
|
|
673
|
+
}
|
|
669
674
|
function convertAgentConfigToAssistant(config) {
|
|
670
675
|
return {
|
|
671
676
|
id: config.key,
|
|
@@ -698,12 +703,17 @@ async function getAssistantList(request, reply) {
|
|
|
698
703
|
assistantMap.set(assistant.id, assistant);
|
|
699
704
|
});
|
|
700
705
|
const allAssistants = Array.from(assistantMap.values());
|
|
706
|
+
const userId = getUserId(request);
|
|
707
|
+
const filtered = allAssistants.filter((a) => {
|
|
708
|
+
if (!a.ownerUserId) return true;
|
|
709
|
+
return a.ownerUserId === userId;
|
|
710
|
+
});
|
|
701
711
|
return {
|
|
702
712
|
success: true,
|
|
703
713
|
message: "Successfully retrieved assistant list",
|
|
704
714
|
data: {
|
|
705
|
-
records:
|
|
706
|
-
total:
|
|
715
|
+
records: filtered,
|
|
716
|
+
total: filtered.length
|
|
707
717
|
}
|
|
708
718
|
};
|
|
709
719
|
}
|
|
@@ -849,7 +859,7 @@ var getAgentGraph = async (request, reply) => {
|
|
|
849
859
|
var import_uuid = require("uuid");
|
|
850
860
|
var import_core3 = require("@axiom-lattice/core");
|
|
851
861
|
var import_protocols = require("@axiom-lattice/protocols");
|
|
852
|
-
function
|
|
862
|
+
function getUserId2(request) {
|
|
853
863
|
const authUser = request.user;
|
|
854
864
|
if (authUser?.id) return authUser.id;
|
|
855
865
|
return request.headers["x-user-id"] || void 0;
|
|
@@ -871,7 +881,7 @@ var createRun = async (request, reply) => {
|
|
|
871
881
|
const workspace_id = request.headers["x-workspace-id"];
|
|
872
882
|
const project_id = request.headers["x-project-id"];
|
|
873
883
|
const x_request_id = request.headers["x-request-id"] || (0, import_uuid.v4)();
|
|
874
|
-
const user_id =
|
|
884
|
+
const user_id = getUserId2(request);
|
|
875
885
|
const mergedConfig = user_id ? { ...custom_run_config, user_id } : custom_run_config;
|
|
876
886
|
if (!assistant_id) {
|
|
877
887
|
reply.status(400).send({
|
|
@@ -1025,6 +1035,33 @@ var abortRun = async (request, reply) => {
|
|
|
1025
1035
|
});
|
|
1026
1036
|
}
|
|
1027
1037
|
};
|
|
1038
|
+
var recoverRun = async (request, reply) => {
|
|
1039
|
+
try {
|
|
1040
|
+
const { assistantId, threadId } = request.params;
|
|
1041
|
+
const tenant_id = request.headers["x-tenant-id"];
|
|
1042
|
+
const workspace_id = request.headers["x-workspace-id"] || "default";
|
|
1043
|
+
const project_id = request.headers["x-project-id"] || "default";
|
|
1044
|
+
const agent = import_core3.agentInstanceManager.getAgent({
|
|
1045
|
+
assistant_id: assistantId,
|
|
1046
|
+
thread_id: threadId,
|
|
1047
|
+
tenant_id,
|
|
1048
|
+
workspace_id,
|
|
1049
|
+
project_id
|
|
1050
|
+
});
|
|
1051
|
+
await agent.resumeTask();
|
|
1052
|
+
const status = await agent.getRunStatus();
|
|
1053
|
+
reply.status(200).send({
|
|
1054
|
+
success: true,
|
|
1055
|
+
threadId,
|
|
1056
|
+
status
|
|
1057
|
+
});
|
|
1058
|
+
} catch (error) {
|
|
1059
|
+
reply.status(500).send({
|
|
1060
|
+
success: false,
|
|
1061
|
+
error: `Recover failed: ${error.message}`
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1028
1065
|
|
|
1029
1066
|
// src/controllers/memory.ts
|
|
1030
1067
|
var import_core4 = require("@axiom-lattice/core");
|
|
@@ -1197,6 +1234,8 @@ var triggerAgentTask = async (request, reply) => {
|
|
|
1197
1234
|
try {
|
|
1198
1235
|
const { assistant_id, thread_id, input, command } = request.body;
|
|
1199
1236
|
const tenant_id = request.headers["x-tenant-id"];
|
|
1237
|
+
const workspace_id = request.headers["x-workspace-id"];
|
|
1238
|
+
const project_id = request.headers["x-project-id"];
|
|
1200
1239
|
if (!assistant_id) {
|
|
1201
1240
|
reply.status(400).send({
|
|
1202
1241
|
success: false,
|
|
@@ -1217,7 +1256,12 @@ var triggerAgentTask = async (request, reply) => {
|
|
|
1217
1256
|
thread_id,
|
|
1218
1257
|
input,
|
|
1219
1258
|
command,
|
|
1220
|
-
"x-tenant-id": tenant_id
|
|
1259
|
+
"x-tenant-id": tenant_id,
|
|
1260
|
+
runConfig: {
|
|
1261
|
+
workspaceId: workspace_id,
|
|
1262
|
+
projectId: project_id,
|
|
1263
|
+
user_id: request.user?.id
|
|
1264
|
+
}
|
|
1221
1265
|
});
|
|
1222
1266
|
reply.status(200).send({
|
|
1223
1267
|
success: true
|
|
@@ -2805,6 +2849,268 @@ async function replyInboxTask(request, reply) {
|
|
|
2805
2849
|
}
|
|
2806
2850
|
}
|
|
2807
2851
|
|
|
2852
|
+
// src/controllers/personal-assistant.ts
|
|
2853
|
+
var import_core14 = require("@axiom-lattice/core");
|
|
2854
|
+
var import_crypto3 = require("crypto");
|
|
2855
|
+
function getWorkspaceId2(request) {
|
|
2856
|
+
return request.headers["x-workspace-id"] || "default";
|
|
2857
|
+
}
|
|
2858
|
+
function getTenantId7(request) {
|
|
2859
|
+
const userTenantId = request.user?.tenantId;
|
|
2860
|
+
if (userTenantId) return userTenantId;
|
|
2861
|
+
return request.headers["x-tenant-id"] || "default";
|
|
2862
|
+
}
|
|
2863
|
+
function getUserId3(request) {
|
|
2864
|
+
const userId = request.user?.id || request.headers["x-user-id"];
|
|
2865
|
+
if (!userId) throw new Error("User ID is required");
|
|
2866
|
+
return userId;
|
|
2867
|
+
}
|
|
2868
|
+
function getLinkStore() {
|
|
2869
|
+
return (0, import_core14.getStoreLattice)("default", "userTenantLink").store;
|
|
2870
|
+
}
|
|
2871
|
+
function getAssistantStore() {
|
|
2872
|
+
return (0, import_core14.getStoreLattice)("default", "assistant").store;
|
|
2873
|
+
}
|
|
2874
|
+
function getProjectStore() {
|
|
2875
|
+
return (0, import_core14.getStoreLattice)("default", "project").store;
|
|
2876
|
+
}
|
|
2877
|
+
async function getLinkMeta(userId, tenantId) {
|
|
2878
|
+
const link = await getLinkStore().getLink(userId, tenantId);
|
|
2879
|
+
return link?.metadata || {};
|
|
2880
|
+
}
|
|
2881
|
+
async function updateLinkMeta(userId, tenantId, meta) {
|
|
2882
|
+
await getLinkStore().updateLink(userId, tenantId, { metadata: meta });
|
|
2883
|
+
}
|
|
2884
|
+
async function createPersonalAssistant(request, reply) {
|
|
2885
|
+
const tenantId = getTenantId7(request);
|
|
2886
|
+
const userId = getUserId3(request);
|
|
2887
|
+
const { name, personality } = request.body;
|
|
2888
|
+
if (!name || !personality) {
|
|
2889
|
+
return reply.status(400).send({ success: false, message: "name and personality are required" });
|
|
2890
|
+
}
|
|
2891
|
+
const store = getAssistantStore();
|
|
2892
|
+
const existing = await store.getByOwner(tenantId, userId);
|
|
2893
|
+
if (existing) {
|
|
2894
|
+
return reply.status(409).send({ success: false, message: "You already have a personal assistant" });
|
|
2895
|
+
}
|
|
2896
|
+
const assistantId = (0, import_crypto3.randomUUID)();
|
|
2897
|
+
const projectStore = getProjectStore();
|
|
2898
|
+
const projectId = (0, import_crypto3.randomUUID)();
|
|
2899
|
+
const wsId = getWorkspaceId2(request);
|
|
2900
|
+
await projectStore.createProject(tenantId, wsId, projectId, {
|
|
2901
|
+
name: `${name}'s Space`,
|
|
2902
|
+
description: "Personal workspace for your assistant"
|
|
2903
|
+
});
|
|
2904
|
+
const config = import_core14.PersonalAssistantConfig.get();
|
|
2905
|
+
config.key = assistantId;
|
|
2906
|
+
import_core14.PersonalAssistantConfig.render(config, name, personality);
|
|
2907
|
+
const data = { name, graphDefinition: config, ownerUserId: userId };
|
|
2908
|
+
const assistant = await store.createAssistant(tenantId, assistantId, data);
|
|
2909
|
+
const meta = await getLinkMeta(userId, tenantId);
|
|
2910
|
+
meta.personalAssistantId = assistantId;
|
|
2911
|
+
meta.personalProjectId = projectId;
|
|
2912
|
+
meta.personalWorkspaceId = wsId;
|
|
2913
|
+
await updateLinkMeta(userId, tenantId, meta);
|
|
2914
|
+
return reply.status(201).send({
|
|
2915
|
+
success: true,
|
|
2916
|
+
message: "Personal assistant created",
|
|
2917
|
+
data: { id: assistant.id, name: assistant.name, projectId, workspaceId: wsId, createdAt: assistant.createdAt }
|
|
2918
|
+
});
|
|
2919
|
+
}
|
|
2920
|
+
async function getPersonalAssistant(request, reply) {
|
|
2921
|
+
const tenantId = getTenantId7(request);
|
|
2922
|
+
const userId = getUserId3(request);
|
|
2923
|
+
const store = getAssistantStore();
|
|
2924
|
+
const assistant = await store.getByOwner(tenantId, userId);
|
|
2925
|
+
if (!assistant) {
|
|
2926
|
+
return reply.status(404).send({ success: false, message: "No personal assistant found" });
|
|
2927
|
+
}
|
|
2928
|
+
const meta = await getLinkMeta(userId, tenantId);
|
|
2929
|
+
const projectId = meta.personalProjectId || "default";
|
|
2930
|
+
const workspaceId = meta.personalWorkspaceId || "default";
|
|
2931
|
+
return {
|
|
2932
|
+
success: true,
|
|
2933
|
+
message: "Personal assistant found",
|
|
2934
|
+
data: { id: assistant.id, name: assistant.name, projectId, workspaceId, createdAt: assistant.createdAt }
|
|
2935
|
+
};
|
|
2936
|
+
}
|
|
2937
|
+
async function deletePersonalAssistant(request, reply) {
|
|
2938
|
+
const tenantId = getTenantId7(request);
|
|
2939
|
+
const userId = getUserId3(request);
|
|
2940
|
+
const store = getAssistantStore();
|
|
2941
|
+
const assistant = await store.getByOwner(tenantId, userId);
|
|
2942
|
+
if (!assistant) {
|
|
2943
|
+
return reply.status(404).send({ success: false, message: "No personal assistant found" });
|
|
2944
|
+
}
|
|
2945
|
+
const deleted = await store.deleteAssistant(tenantId, assistant.id);
|
|
2946
|
+
if (!deleted) {
|
|
2947
|
+
return reply.status(500).send({ success: false, message: "Failed to delete personal assistant" });
|
|
2948
|
+
}
|
|
2949
|
+
const threadStore = (0, import_core14.getStoreLattice)("default", "thread").store;
|
|
2950
|
+
try {
|
|
2951
|
+
const threads = await threadStore.getThreadsByAssistantId(tenantId, assistant.id);
|
|
2952
|
+
for (const t of threads) {
|
|
2953
|
+
await threadStore.deleteThread(tenantId, t.id);
|
|
2954
|
+
}
|
|
2955
|
+
} catch {
|
|
2956
|
+
}
|
|
2957
|
+
const meta = await getLinkMeta(userId, tenantId);
|
|
2958
|
+
const projectId = meta.personalProjectId;
|
|
2959
|
+
const wsId = meta.personalWorkspaceId;
|
|
2960
|
+
if (projectId && wsId) {
|
|
2961
|
+
try {
|
|
2962
|
+
await getProjectStore().deleteProject(tenantId, projectId);
|
|
2963
|
+
} catch {
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
delete meta.personalAssistantId;
|
|
2967
|
+
delete meta.personalProjectId;
|
|
2968
|
+
delete meta.personalWorkspaceId;
|
|
2969
|
+
await updateLinkMeta(userId, tenantId, meta);
|
|
2970
|
+
return { success: true, message: "Personal assistant deleted" };
|
|
2971
|
+
}
|
|
2972
|
+
|
|
2973
|
+
// src/controllers/tasks.ts
|
|
2974
|
+
var import_core15 = require("@axiom-lattice/core");
|
|
2975
|
+
function getTenantId8(request) {
|
|
2976
|
+
const userTenantId = request.user?.tenantId;
|
|
2977
|
+
if (userTenantId) return userTenantId;
|
|
2978
|
+
return request.headers["x-tenant-id"] || "default";
|
|
2979
|
+
}
|
|
2980
|
+
function getUserId4(request) {
|
|
2981
|
+
const userId = request.user?.id || request.headers["x-user-id"];
|
|
2982
|
+
if (!userId) throw new Error("User ID is required");
|
|
2983
|
+
return userId;
|
|
2984
|
+
}
|
|
2985
|
+
function getStore() {
|
|
2986
|
+
return (0, import_core15.getStoreLattice)("default", "task").store;
|
|
2987
|
+
}
|
|
2988
|
+
async function listTasks(request, reply) {
|
|
2989
|
+
try {
|
|
2990
|
+
const tenantId = getTenantId8(request);
|
|
2991
|
+
const userId = getUserId4(request);
|
|
2992
|
+
const query = request.query;
|
|
2993
|
+
const store = getStore();
|
|
2994
|
+
const tasks = await store.list({
|
|
2995
|
+
tenantId,
|
|
2996
|
+
ownerId: query.ownerId || userId,
|
|
2997
|
+
status: query.status,
|
|
2998
|
+
priority: query.priority,
|
|
2999
|
+
ownerType: query.ownerType,
|
|
3000
|
+
metadata: query.metadata ? JSON.parse(query.metadata) : void 0,
|
|
3001
|
+
limit: query.limit ? parseInt(query.limit) : void 0,
|
|
3002
|
+
offset: query.offset ? parseInt(query.offset) : void 0
|
|
3003
|
+
});
|
|
3004
|
+
return { success: true, data: tasks, count: tasks.length };
|
|
3005
|
+
} catch (error) {
|
|
3006
|
+
return { success: false, error: error.message };
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
async function getTask(request, reply) {
|
|
3010
|
+
try {
|
|
3011
|
+
const tenantId = getTenantId8(request);
|
|
3012
|
+
const userId = getUserId4(request);
|
|
3013
|
+
const { id } = request.params;
|
|
3014
|
+
const store = getStore();
|
|
3015
|
+
const task = await store.getById(tenantId, id);
|
|
3016
|
+
if (!task) {
|
|
3017
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
3018
|
+
}
|
|
3019
|
+
if (task.ownerType === "user" && task.ownerId !== userId) {
|
|
3020
|
+
return reply.status(403).send({ success: false, error: "Access denied" });
|
|
3021
|
+
}
|
|
3022
|
+
return { success: true, data: task };
|
|
3023
|
+
} catch (error) {
|
|
3024
|
+
return { success: false, error: error.message };
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
async function createTask(request, reply) {
|
|
3028
|
+
try {
|
|
3029
|
+
const tenantId = getTenantId8(request);
|
|
3030
|
+
const userId = getUserId4(request);
|
|
3031
|
+
const body = request.body;
|
|
3032
|
+
if (!body.title) {
|
|
3033
|
+
return reply.status(400).send({ success: false, error: "title is required" });
|
|
3034
|
+
}
|
|
3035
|
+
const store = getStore();
|
|
3036
|
+
const task = await store.create({
|
|
3037
|
+
...body,
|
|
3038
|
+
tenantId,
|
|
3039
|
+
ownerType: body.ownerType || "user",
|
|
3040
|
+
ownerId: body.ownerId || userId
|
|
3041
|
+
});
|
|
3042
|
+
return reply.status(201).send({ success: true, data: task });
|
|
3043
|
+
} catch (error) {
|
|
3044
|
+
return reply.status(500).send({ success: false, error: error.message });
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
async function updateTask(request, reply) {
|
|
3048
|
+
try {
|
|
3049
|
+
const tenantId = getTenantId8(request);
|
|
3050
|
+
const userId = getUserId4(request);
|
|
3051
|
+
const { id } = request.params;
|
|
3052
|
+
const store = getStore();
|
|
3053
|
+
const existing = await store.getById(tenantId, id);
|
|
3054
|
+
if (!existing) {
|
|
3055
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
3056
|
+
}
|
|
3057
|
+
if (existing.ownerType === "user" && existing.ownerId !== userId) {
|
|
3058
|
+
return reply.status(403).send({ success: false, error: "Access denied" });
|
|
3059
|
+
}
|
|
3060
|
+
const task = await store.update(tenantId, id, request.body);
|
|
3061
|
+
if (!task) {
|
|
3062
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
3063
|
+
}
|
|
3064
|
+
return { success: true, data: task };
|
|
3065
|
+
} catch (error) {
|
|
3066
|
+
return reply.status(500).send({ success: false, error: error.message });
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
async function deleteTask(request, reply) {
|
|
3070
|
+
try {
|
|
3071
|
+
const tenantId = getTenantId8(request);
|
|
3072
|
+
const userId = getUserId4(request);
|
|
3073
|
+
const { id } = request.params;
|
|
3074
|
+
const store = getStore();
|
|
3075
|
+
const existing = await store.getById(tenantId, id);
|
|
3076
|
+
if (!existing) {
|
|
3077
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
3078
|
+
}
|
|
3079
|
+
if (existing.ownerType === "user" && existing.ownerId !== userId) {
|
|
3080
|
+
return reply.status(403).send({ success: false, error: "Access denied" });
|
|
3081
|
+
}
|
|
3082
|
+
const deleted = await store.delete(tenantId, id);
|
|
3083
|
+
if (!deleted) {
|
|
3084
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
3085
|
+
}
|
|
3086
|
+
return { success: true, message: "Task deleted" };
|
|
3087
|
+
} catch (error) {
|
|
3088
|
+
return reply.status(500).send({ success: false, error: error.message });
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
async function completeTask(request, reply) {
|
|
3092
|
+
try {
|
|
3093
|
+
const tenantId = getTenantId8(request);
|
|
3094
|
+
const userId = getUserId4(request);
|
|
3095
|
+
const { id } = request.params;
|
|
3096
|
+
const store = getStore();
|
|
3097
|
+
const existing = await store.getById(tenantId, id);
|
|
3098
|
+
if (!existing) {
|
|
3099
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
3100
|
+
}
|
|
3101
|
+
if (existing.ownerType === "user" && existing.ownerId !== userId) {
|
|
3102
|
+
return reply.status(403).send({ success: false, error: "Access denied" });
|
|
3103
|
+
}
|
|
3104
|
+
const task = await store.update(tenantId, id, { status: "completed" });
|
|
3105
|
+
if (!task) {
|
|
3106
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
3107
|
+
}
|
|
3108
|
+
return { success: true, data: task };
|
|
3109
|
+
} catch (error) {
|
|
3110
|
+
return reply.status(500).send({ success: false, error: error.message });
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
|
|
2808
3114
|
// src/schemas/data-query.ts
|
|
2809
3115
|
var dataQuerySchema = {
|
|
2810
3116
|
description: "Execute data query (semantic or SQL)",
|
|
@@ -3146,7 +3452,7 @@ var getHealthSchema = {
|
|
|
3146
3452
|
};
|
|
3147
3453
|
|
|
3148
3454
|
// src/controllers/thread_status.ts
|
|
3149
|
-
var
|
|
3455
|
+
var import_core16 = require("@axiom-lattice/core");
|
|
3150
3456
|
async function removePendingMessageHandler(request, reply) {
|
|
3151
3457
|
try {
|
|
3152
3458
|
const { assistant_id, thread_id, message_id } = request.params;
|
|
@@ -3159,7 +3465,7 @@ async function removePendingMessageHandler(request, reply) {
|
|
|
3159
3465
|
if (!assistant_id) {
|
|
3160
3466
|
return reply.code(400).send({ error: "Missing assistant_id parameter" });
|
|
3161
3467
|
}
|
|
3162
|
-
const agent =
|
|
3468
|
+
const agent = import_core16.agentInstanceManager.getAgent({
|
|
3163
3469
|
assistant_id,
|
|
3164
3470
|
thread_id,
|
|
3165
3471
|
tenant_id,
|
|
@@ -3193,7 +3499,7 @@ async function removePendingMessageHandler(request, reply) {
|
|
|
3193
3499
|
}
|
|
3194
3500
|
|
|
3195
3501
|
// src/services/sandbox_service.ts
|
|
3196
|
-
var
|
|
3502
|
+
var import_core17 = require("@axiom-lattice/core");
|
|
3197
3503
|
var ERROR_HTML = `<!DOCTYPE html>
|
|
3198
3504
|
<html lang="zh-CN">
|
|
3199
3505
|
<head>
|
|
@@ -3305,7 +3611,7 @@ var ERROR_HTML = `<!DOCTYPE html>
|
|
|
3305
3611
|
</html>`;
|
|
3306
3612
|
var SandboxService = class {
|
|
3307
3613
|
getFilesystemVmIsolation(tenantId, assistantId) {
|
|
3308
|
-
const agentLattice =
|
|
3614
|
+
const agentLattice = import_core17.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
|
|
3309
3615
|
if (!agentLattice) {
|
|
3310
3616
|
return null;
|
|
3311
3617
|
}
|
|
@@ -3319,9 +3625,9 @@ var SandboxService = class {
|
|
|
3319
3625
|
computeSandboxName(assistantId, threadId, vmIsolation, tenantId, workspaceId, projectId) {
|
|
3320
3626
|
switch (vmIsolation) {
|
|
3321
3627
|
case "agent":
|
|
3322
|
-
return (0,
|
|
3628
|
+
return (0, import_core17.normalizeSandboxName)(`${tenantId ?? "default"}-${assistantId}`);
|
|
3323
3629
|
case "project":
|
|
3324
|
-
return (0,
|
|
3630
|
+
return (0, import_core17.normalizeSandboxName)(
|
|
3325
3631
|
`${tenantId ?? "default"}-${workspaceId ?? "default"}-${projectId ?? "default"}`
|
|
3326
3632
|
);
|
|
3327
3633
|
case "global":
|
|
@@ -3369,15 +3675,15 @@ var SandboxService = class {
|
|
|
3369
3675
|
);
|
|
3370
3676
|
return rewritten;
|
|
3371
3677
|
}
|
|
3372
|
-
generateErrorHtml(assistantId, threadId, vmIsolation,
|
|
3373
|
-
const encodedError = encodeURIComponent(
|
|
3374
|
-
return ERROR_HTML.replace("{assistantId}", assistantId).replace("{threadId}", threadId).replace("{vmIsolation}", vmIsolation).replace("{errorMessage}",
|
|
3678
|
+
generateErrorHtml(assistantId, threadId, vmIsolation, errorMessage2) {
|
|
3679
|
+
const encodedError = encodeURIComponent(errorMessage2);
|
|
3680
|
+
return ERROR_HTML.replace("{assistantId}", assistantId).replace("{threadId}", threadId).replace("{vmIsolation}", vmIsolation).replace("{errorMessage}", errorMessage2);
|
|
3375
3681
|
}
|
|
3376
3682
|
};
|
|
3377
3683
|
var sandboxService = new SandboxService();
|
|
3378
3684
|
|
|
3379
3685
|
// src/controllers/sandbox.ts
|
|
3380
|
-
var
|
|
3686
|
+
var import_core18 = require("@axiom-lattice/core");
|
|
3381
3687
|
function getFilenameFromPath(path3) {
|
|
3382
3688
|
const segments = path3.replace(/\/+$/, "").split("/");
|
|
3383
3689
|
return segments[segments.length - 1] || "download";
|
|
@@ -3416,7 +3722,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
3416
3722
|
}
|
|
3417
3723
|
const workspaceId = request.headers["x-workspace-id"];
|
|
3418
3724
|
const projectId = request.headers["x-project-id"];
|
|
3419
|
-
const sandboxManager = (0,
|
|
3725
|
+
const sandboxManager = (0, import_core18.getSandBoxManager)();
|
|
3420
3726
|
const sandbox = await sandboxManager.getSandboxFromConfig({
|
|
3421
3727
|
assistant_id: assistantId,
|
|
3422
3728
|
thread_id: threadId,
|
|
@@ -3464,7 +3770,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
3464
3770
|
}
|
|
3465
3771
|
const workspaceId = request.headers["x-workspace-id"];
|
|
3466
3772
|
const projectId = request.headers["x-project-id"];
|
|
3467
|
-
const sandboxManager = (0,
|
|
3773
|
+
const sandboxManager = (0, import_core18.getSandBoxManager)();
|
|
3468
3774
|
const sandbox = await sandboxManager.getSandboxFromConfig({
|
|
3469
3775
|
assistant_id: assistantId,
|
|
3470
3776
|
thread_id: threadId,
|
|
@@ -3497,14 +3803,14 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
3497
3803
|
// src/controllers/workspace.ts
|
|
3498
3804
|
var fs = __toESM(require("fs/promises"));
|
|
3499
3805
|
var path = __toESM(require("path"));
|
|
3500
|
-
var import_core17 = require("@axiom-lattice/core");
|
|
3501
|
-
var import_core18 = require("@axiom-lattice/core");
|
|
3502
3806
|
var import_core19 = require("@axiom-lattice/core");
|
|
3807
|
+
var import_core20 = require("@axiom-lattice/core");
|
|
3808
|
+
var import_core21 = require("@axiom-lattice/core");
|
|
3503
3809
|
var import_uuid2 = require("uuid");
|
|
3504
3810
|
var WorkspaceController = class {
|
|
3505
3811
|
constructor() {
|
|
3506
|
-
this.workspaceStore = (0,
|
|
3507
|
-
this.projectStore = (0,
|
|
3812
|
+
this.workspaceStore = (0, import_core19.getStoreLattice)("default", "workspace").store;
|
|
3813
|
+
this.projectStore = (0, import_core19.getStoreLattice)("default", "project").store;
|
|
3508
3814
|
}
|
|
3509
3815
|
getTenantId(request) {
|
|
3510
3816
|
const userTenantId = request.user?.tenantId;
|
|
@@ -3637,7 +3943,7 @@ var WorkspaceController = class {
|
|
|
3637
3943
|
throw new Error("Workspace not found");
|
|
3638
3944
|
}
|
|
3639
3945
|
if (workspace.storageType === "sandbox") {
|
|
3640
|
-
const sandboxManager = (0,
|
|
3946
|
+
const sandboxManager = (0, import_core21.getSandBoxManager)();
|
|
3641
3947
|
const volumeConfig = {
|
|
3642
3948
|
assistant_id: assistantId || "",
|
|
3643
3949
|
thread_id: "",
|
|
@@ -3651,14 +3957,14 @@ var WorkspaceController = class {
|
|
|
3651
3957
|
}
|
|
3652
3958
|
const sandbox = await sandboxManager.getSandboxFromConfig(volumeConfig);
|
|
3653
3959
|
return {
|
|
3654
|
-
backend: new
|
|
3960
|
+
backend: new import_core20.SandboxFilesystem({
|
|
3655
3961
|
sandboxInstance: sandbox
|
|
3656
3962
|
}),
|
|
3657
3963
|
workspace
|
|
3658
3964
|
};
|
|
3659
3965
|
} else {
|
|
3660
3966
|
return {
|
|
3661
|
-
backend: new
|
|
3967
|
+
backend: new import_core20.FilesystemBackend({
|
|
3662
3968
|
rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
|
|
3663
3969
|
virtualMode: true
|
|
3664
3970
|
}),
|
|
@@ -3736,7 +4042,7 @@ var WorkspaceController = class {
|
|
|
3736
4042
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId, assistantId);
|
|
3737
4043
|
const resolvedPath = filePath;
|
|
3738
4044
|
if (workspace.storageType === "sandbox") {
|
|
3739
|
-
const sandboxManager = (0,
|
|
4045
|
+
const sandboxManager = (0, import_core21.getSandBoxManager)();
|
|
3740
4046
|
const volumeConfig = {
|
|
3741
4047
|
assistant_id: assistantId || "",
|
|
3742
4048
|
thread_id: "",
|
|
@@ -3786,7 +4092,7 @@ var WorkspaceController = class {
|
|
|
3786
4092
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId, assistantId);
|
|
3787
4093
|
const resolvedPath = filePath;
|
|
3788
4094
|
if (workspace.storageType === "sandbox") {
|
|
3789
|
-
const sandboxManager = (0,
|
|
4095
|
+
const sandboxManager = (0, import_core21.getSandBoxManager)();
|
|
3790
4096
|
const volumeConfig = {
|
|
3791
4097
|
assistant_id: assistantId || "",
|
|
3792
4098
|
thread_id: "",
|
|
@@ -3920,7 +4226,7 @@ var WorkspaceController = class {
|
|
|
3920
4226
|
return reply.status(400).send({ success: false, error: "Invalid path parameter" });
|
|
3921
4227
|
}
|
|
3922
4228
|
if (workspace.storageType === "sandbox") {
|
|
3923
|
-
const sandboxManager = (0,
|
|
4229
|
+
const sandboxManager = (0, import_core21.getSandBoxManager)();
|
|
3924
4230
|
const volumeConfig = {
|
|
3925
4231
|
assistant_id: assistantId || "",
|
|
3926
4232
|
thread_id: "",
|
|
@@ -4028,9 +4334,9 @@ function registerWorkspaceRoutes(app2) {
|
|
|
4028
4334
|
}
|
|
4029
4335
|
|
|
4030
4336
|
// src/controllers/database-configs.ts
|
|
4031
|
-
var
|
|
4032
|
-
var
|
|
4033
|
-
function
|
|
4337
|
+
var import_core22 = require("@axiom-lattice/core");
|
|
4338
|
+
var import_crypto4 = require("crypto");
|
|
4339
|
+
function getTenantId9(request) {
|
|
4034
4340
|
const userTenantId = request.user?.tenantId;
|
|
4035
4341
|
if (userTenantId) {
|
|
4036
4342
|
return userTenantId;
|
|
@@ -4038,9 +4344,9 @@ function getTenantId7(request) {
|
|
|
4038
4344
|
return request.headers["x-tenant-id"] || "default";
|
|
4039
4345
|
}
|
|
4040
4346
|
async function getDatabaseConfigList(request, reply) {
|
|
4041
|
-
const tenantId =
|
|
4347
|
+
const tenantId = getTenantId9(request);
|
|
4042
4348
|
try {
|
|
4043
|
-
const storeLattice = (0,
|
|
4349
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "database");
|
|
4044
4350
|
const store = storeLattice.store;
|
|
4045
4351
|
const configs = await store.getAllConfigs(tenantId);
|
|
4046
4352
|
console.log("Backend: getAllConfigs returned:", configs);
|
|
@@ -4068,10 +4374,10 @@ async function getDatabaseConfigList(request, reply) {
|
|
|
4068
4374
|
}
|
|
4069
4375
|
}
|
|
4070
4376
|
async function getDatabaseConfig(request, reply) {
|
|
4071
|
-
const tenantId =
|
|
4377
|
+
const tenantId = getTenantId9(request);
|
|
4072
4378
|
const { key } = request.params;
|
|
4073
4379
|
try {
|
|
4074
|
-
const storeLattice = (0,
|
|
4380
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "database");
|
|
4075
4381
|
const store = storeLattice.store;
|
|
4076
4382
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4077
4383
|
if (!config) {
|
|
@@ -4094,10 +4400,10 @@ async function getDatabaseConfig(request, reply) {
|
|
|
4094
4400
|
}
|
|
4095
4401
|
}
|
|
4096
4402
|
async function createDatabaseConfig(request, reply) {
|
|
4097
|
-
const tenantId =
|
|
4403
|
+
const tenantId = getTenantId9(request);
|
|
4098
4404
|
const body = request.body;
|
|
4099
4405
|
try {
|
|
4100
|
-
const storeLattice = (0,
|
|
4406
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "database");
|
|
4101
4407
|
const store = storeLattice.store;
|
|
4102
4408
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
4103
4409
|
if (existing) {
|
|
@@ -4107,10 +4413,10 @@ async function createDatabaseConfig(request, reply) {
|
|
|
4107
4413
|
message: "Database configuration with this key already exists"
|
|
4108
4414
|
};
|
|
4109
4415
|
}
|
|
4110
|
-
const id = body.id || (0,
|
|
4416
|
+
const id = body.id || (0, import_crypto4.randomUUID)();
|
|
4111
4417
|
const config = await store.createConfig(tenantId, id, body);
|
|
4112
4418
|
try {
|
|
4113
|
-
|
|
4419
|
+
import_core22.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
|
|
4114
4420
|
} catch (error) {
|
|
4115
4421
|
console.warn("Failed to auto-register database:", error);
|
|
4116
4422
|
}
|
|
@@ -4129,11 +4435,11 @@ async function createDatabaseConfig(request, reply) {
|
|
|
4129
4435
|
}
|
|
4130
4436
|
}
|
|
4131
4437
|
async function updateDatabaseConfig(request, reply) {
|
|
4132
|
-
const tenantId =
|
|
4438
|
+
const tenantId = getTenantId9(request);
|
|
4133
4439
|
const { key } = request.params;
|
|
4134
4440
|
const updates = request.body;
|
|
4135
4441
|
try {
|
|
4136
|
-
const storeLattice = (0,
|
|
4442
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "database");
|
|
4137
4443
|
const store = storeLattice.store;
|
|
4138
4444
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
4139
4445
|
if (!existing) {
|
|
@@ -4152,7 +4458,7 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
4152
4458
|
}
|
|
4153
4459
|
if (updates.config) {
|
|
4154
4460
|
try {
|
|
4155
|
-
|
|
4461
|
+
import_core22.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
|
|
4156
4462
|
} catch (error) {
|
|
4157
4463
|
console.warn("Failed to re-register database:", error);
|
|
4158
4464
|
}
|
|
@@ -4171,10 +4477,10 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
4171
4477
|
}
|
|
4172
4478
|
}
|
|
4173
4479
|
async function deleteDatabaseConfig(request, reply) {
|
|
4174
|
-
const tenantId =
|
|
4480
|
+
const tenantId = getTenantId9(request);
|
|
4175
4481
|
const { keyOrId } = request.params;
|
|
4176
4482
|
try {
|
|
4177
|
-
const storeLattice = (0,
|
|
4483
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "database");
|
|
4178
4484
|
const store = storeLattice.store;
|
|
4179
4485
|
console.log("Delete request - keyOrId:", keyOrId);
|
|
4180
4486
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
@@ -4201,8 +4507,8 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
4201
4507
|
};
|
|
4202
4508
|
}
|
|
4203
4509
|
try {
|
|
4204
|
-
if (
|
|
4205
|
-
await
|
|
4510
|
+
if (import_core22.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
|
|
4511
|
+
await import_core22.sqlDatabaseManager.removeDatabase(tenantId, configKey);
|
|
4206
4512
|
}
|
|
4207
4513
|
} catch (error) {
|
|
4208
4514
|
console.warn("Failed to remove from SqlDatabaseManager:", error);
|
|
@@ -4220,10 +4526,10 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
4220
4526
|
}
|
|
4221
4527
|
}
|
|
4222
4528
|
async function testDatabaseConnection(request, reply) {
|
|
4223
|
-
const tenantId =
|
|
4529
|
+
const tenantId = getTenantId9(request);
|
|
4224
4530
|
const { key } = request.params;
|
|
4225
4531
|
try {
|
|
4226
|
-
const storeLattice = (0,
|
|
4532
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "database");
|
|
4227
4533
|
const store = storeLattice.store;
|
|
4228
4534
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4229
4535
|
if (!config) {
|
|
@@ -4234,16 +4540,16 @@ async function testDatabaseConnection(request, reply) {
|
|
|
4234
4540
|
};
|
|
4235
4541
|
}
|
|
4236
4542
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
4237
|
-
|
|
4543
|
+
import_core22.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
|
|
4238
4544
|
const startTime = Date.now();
|
|
4239
|
-
const db = await
|
|
4545
|
+
const db = await import_core22.sqlDatabaseManager.getDatabase(tenantId, testKey);
|
|
4240
4546
|
try {
|
|
4241
4547
|
await db.connect();
|
|
4242
4548
|
await db.listTables();
|
|
4243
4549
|
const latency = Date.now() - startTime;
|
|
4244
4550
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
4245
4551
|
await db.disconnect();
|
|
4246
|
-
await
|
|
4552
|
+
await import_core22.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
4247
4553
|
return {
|
|
4248
4554
|
success: true,
|
|
4249
4555
|
message: "Connection test successful",
|
|
@@ -4255,7 +4561,7 @@ async function testDatabaseConnection(request, reply) {
|
|
|
4255
4561
|
} catch (error) {
|
|
4256
4562
|
try {
|
|
4257
4563
|
await db.disconnect();
|
|
4258
|
-
await
|
|
4564
|
+
await import_core22.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
4259
4565
|
} catch {
|
|
4260
4566
|
}
|
|
4261
4567
|
return {
|
|
@@ -4307,9 +4613,9 @@ function registerDatabaseConfigRoutes(app2) {
|
|
|
4307
4613
|
}
|
|
4308
4614
|
|
|
4309
4615
|
// src/controllers/metrics-configs.ts
|
|
4310
|
-
var
|
|
4311
|
-
var
|
|
4312
|
-
function
|
|
4616
|
+
var import_core23 = require("@axiom-lattice/core");
|
|
4617
|
+
var import_crypto5 = require("crypto");
|
|
4618
|
+
function getTenantId10(request) {
|
|
4313
4619
|
const userTenantId = request.user?.tenantId;
|
|
4314
4620
|
if (userTenantId) {
|
|
4315
4621
|
return userTenantId;
|
|
@@ -4317,9 +4623,9 @@ function getTenantId8(request) {
|
|
|
4317
4623
|
return request.headers["x-tenant-id"] || "default";
|
|
4318
4624
|
}
|
|
4319
4625
|
async function getMetricsServerConfigList(request, reply) {
|
|
4320
|
-
const tenantId =
|
|
4626
|
+
const tenantId = getTenantId10(request);
|
|
4321
4627
|
try {
|
|
4322
|
-
const storeLattice = (0,
|
|
4628
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4323
4629
|
const store = storeLattice.store;
|
|
4324
4630
|
const configs = await store.getAllConfigs(tenantId);
|
|
4325
4631
|
return {
|
|
@@ -4343,10 +4649,10 @@ async function getMetricsServerConfigList(request, reply) {
|
|
|
4343
4649
|
}
|
|
4344
4650
|
}
|
|
4345
4651
|
async function getMetricsServerConfig(request, reply) {
|
|
4346
|
-
const tenantId =
|
|
4652
|
+
const tenantId = getTenantId10(request);
|
|
4347
4653
|
const { key } = request.params;
|
|
4348
4654
|
try {
|
|
4349
|
-
const storeLattice = (0,
|
|
4655
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4350
4656
|
const store = storeLattice.store;
|
|
4351
4657
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4352
4658
|
if (!config) {
|
|
@@ -4369,10 +4675,10 @@ async function getMetricsServerConfig(request, reply) {
|
|
|
4369
4675
|
}
|
|
4370
4676
|
}
|
|
4371
4677
|
async function createMetricsServerConfig(request, reply) {
|
|
4372
|
-
const tenantId =
|
|
4678
|
+
const tenantId = getTenantId10(request);
|
|
4373
4679
|
const body = request.body;
|
|
4374
4680
|
try {
|
|
4375
|
-
const storeLattice = (0,
|
|
4681
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4376
4682
|
const store = storeLattice.store;
|
|
4377
4683
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
4378
4684
|
if (existing) {
|
|
@@ -4389,7 +4695,7 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
4389
4695
|
message: "selectedDataSources is required for semantic metrics servers"
|
|
4390
4696
|
};
|
|
4391
4697
|
}
|
|
4392
|
-
const id = body.id || (0,
|
|
4698
|
+
const id = body.id || (0, import_crypto5.randomUUID)();
|
|
4393
4699
|
const configData = {
|
|
4394
4700
|
key: body.key,
|
|
4395
4701
|
name: body.name,
|
|
@@ -4401,7 +4707,7 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
4401
4707
|
};
|
|
4402
4708
|
const config = await store.createConfig(tenantId, id, configData);
|
|
4403
4709
|
try {
|
|
4404
|
-
|
|
4710
|
+
import_core23.metricsServerManager.registerServer(tenantId, config.key, config.config);
|
|
4405
4711
|
} catch (error) {
|
|
4406
4712
|
console.warn("Failed to auto-register metrics server:", error);
|
|
4407
4713
|
}
|
|
@@ -4420,11 +4726,11 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
4420
4726
|
}
|
|
4421
4727
|
}
|
|
4422
4728
|
async function updateMetricsServerConfig(request, reply) {
|
|
4423
|
-
const tenantId =
|
|
4729
|
+
const tenantId = getTenantId10(request);
|
|
4424
4730
|
const { key } = request.params;
|
|
4425
4731
|
const updates = request.body;
|
|
4426
4732
|
try {
|
|
4427
|
-
const storeLattice = (0,
|
|
4733
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4428
4734
|
const store = storeLattice.store;
|
|
4429
4735
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
4430
4736
|
if (!existing) {
|
|
@@ -4452,7 +4758,7 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
4452
4758
|
}
|
|
4453
4759
|
if (updates.config) {
|
|
4454
4760
|
try {
|
|
4455
|
-
|
|
4761
|
+
import_core23.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
|
|
4456
4762
|
} catch (error) {
|
|
4457
4763
|
console.warn("Failed to re-register metrics server:", error);
|
|
4458
4764
|
}
|
|
@@ -4471,10 +4777,10 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
4471
4777
|
}
|
|
4472
4778
|
}
|
|
4473
4779
|
async function deleteMetricsServerConfig(request, reply) {
|
|
4474
|
-
const tenantId =
|
|
4780
|
+
const tenantId = getTenantId10(request);
|
|
4475
4781
|
const { keyOrId } = request.params;
|
|
4476
4782
|
try {
|
|
4477
|
-
const storeLattice = (0,
|
|
4783
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4478
4784
|
const store = storeLattice.store;
|
|
4479
4785
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
4480
4786
|
let configKey = keyOrId;
|
|
@@ -4499,8 +4805,8 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
4499
4805
|
};
|
|
4500
4806
|
}
|
|
4501
4807
|
try {
|
|
4502
|
-
if (
|
|
4503
|
-
|
|
4808
|
+
if (import_core23.metricsServerManager.hasServer(tenantId, configKey)) {
|
|
4809
|
+
import_core23.metricsServerManager.removeServer(tenantId, configKey);
|
|
4504
4810
|
}
|
|
4505
4811
|
} catch (error) {
|
|
4506
4812
|
console.warn("Failed to remove from MetricsServerManager:", error);
|
|
@@ -4518,10 +4824,10 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
4518
4824
|
}
|
|
4519
4825
|
}
|
|
4520
4826
|
async function testMetricsServerConnection(request, reply) {
|
|
4521
|
-
const tenantId =
|
|
4827
|
+
const tenantId = getTenantId10(request);
|
|
4522
4828
|
const { key } = request.params;
|
|
4523
4829
|
try {
|
|
4524
|
-
const storeLattice = (0,
|
|
4830
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4525
4831
|
const store = storeLattice.store;
|
|
4526
4832
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4527
4833
|
if (!config) {
|
|
@@ -4532,11 +4838,11 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
4532
4838
|
};
|
|
4533
4839
|
}
|
|
4534
4840
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
4535
|
-
|
|
4841
|
+
import_core23.metricsServerManager.registerServer(tenantId, testKey, config.config);
|
|
4536
4842
|
try {
|
|
4537
|
-
const client = await
|
|
4843
|
+
const client = await import_core23.metricsServerManager.getClient(tenantId, testKey);
|
|
4538
4844
|
const result = await client.testConnection();
|
|
4539
|
-
|
|
4845
|
+
import_core23.metricsServerManager.removeServer(tenantId, testKey);
|
|
4540
4846
|
return {
|
|
4541
4847
|
success: true,
|
|
4542
4848
|
message: result.connected ? "Connection test successful" : "Connection test failed",
|
|
@@ -4544,7 +4850,7 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
4544
4850
|
};
|
|
4545
4851
|
} catch (error) {
|
|
4546
4852
|
try {
|
|
4547
|
-
|
|
4853
|
+
import_core23.metricsServerManager.removeServer(tenantId, testKey);
|
|
4548
4854
|
} catch {
|
|
4549
4855
|
}
|
|
4550
4856
|
return {
|
|
@@ -4569,10 +4875,10 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
4569
4875
|
}
|
|
4570
4876
|
}
|
|
4571
4877
|
async function listAvailableMetrics(request, reply) {
|
|
4572
|
-
const tenantId =
|
|
4878
|
+
const tenantId = getTenantId10(request);
|
|
4573
4879
|
const { key } = request.params;
|
|
4574
4880
|
try {
|
|
4575
|
-
const storeLattice = (0,
|
|
4881
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4576
4882
|
const store = storeLattice.store;
|
|
4577
4883
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4578
4884
|
if (!config) {
|
|
@@ -4582,10 +4888,10 @@ async function listAvailableMetrics(request, reply) {
|
|
|
4582
4888
|
message: "Metrics server configuration not found"
|
|
4583
4889
|
};
|
|
4584
4890
|
}
|
|
4585
|
-
if (!
|
|
4586
|
-
|
|
4891
|
+
if (!import_core23.metricsServerManager.hasServer(tenantId, key)) {
|
|
4892
|
+
import_core23.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
4587
4893
|
}
|
|
4588
|
-
const client = await
|
|
4894
|
+
const client = await import_core23.metricsServerManager.getClient(tenantId, key);
|
|
4589
4895
|
const metrics = await client.listMetrics();
|
|
4590
4896
|
return {
|
|
4591
4897
|
success: true,
|
|
@@ -4607,11 +4913,11 @@ async function listAvailableMetrics(request, reply) {
|
|
|
4607
4913
|
}
|
|
4608
4914
|
}
|
|
4609
4915
|
async function queryMetricsData(request, reply) {
|
|
4610
|
-
const tenantId =
|
|
4916
|
+
const tenantId = getTenantId10(request);
|
|
4611
4917
|
const { key } = request.params;
|
|
4612
4918
|
const { metricName, startTime, endTime, step, labels } = request.body;
|
|
4613
4919
|
try {
|
|
4614
|
-
const storeLattice = (0,
|
|
4920
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4615
4921
|
const store = storeLattice.store;
|
|
4616
4922
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4617
4923
|
if (!config) {
|
|
@@ -4628,10 +4934,10 @@ async function queryMetricsData(request, reply) {
|
|
|
4628
4934
|
message: "metricName is required"
|
|
4629
4935
|
};
|
|
4630
4936
|
}
|
|
4631
|
-
if (!
|
|
4632
|
-
|
|
4937
|
+
if (!import_core23.metricsServerManager.hasServer(tenantId, key)) {
|
|
4938
|
+
import_core23.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
4633
4939
|
}
|
|
4634
|
-
const client = await
|
|
4940
|
+
const client = await import_core23.metricsServerManager.getClient(tenantId, key);
|
|
4635
4941
|
const result = await client.queryMetricData(metricName, {
|
|
4636
4942
|
startTime,
|
|
4637
4943
|
endTime,
|
|
@@ -4655,10 +4961,10 @@ async function queryMetricsData(request, reply) {
|
|
|
4655
4961
|
}
|
|
4656
4962
|
}
|
|
4657
4963
|
async function getDataSources(request, reply) {
|
|
4658
|
-
const tenantId =
|
|
4964
|
+
const tenantId = getTenantId10(request);
|
|
4659
4965
|
const { key } = request.params;
|
|
4660
4966
|
try {
|
|
4661
|
-
const storeLattice = (0,
|
|
4967
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4662
4968
|
const store = storeLattice.store;
|
|
4663
4969
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4664
4970
|
if (!config) {
|
|
@@ -4676,7 +4982,7 @@ async function getDataSources(request, reply) {
|
|
|
4676
4982
|
};
|
|
4677
4983
|
}
|
|
4678
4984
|
const semanticConfig = config.config;
|
|
4679
|
-
const client = new
|
|
4985
|
+
const client = new import_core23.SemanticMetricsClient(semanticConfig);
|
|
4680
4986
|
const allDatasources = await client.getDataSources();
|
|
4681
4987
|
const selectedIds = semanticConfig.selectedDataSources || [];
|
|
4682
4988
|
const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
|
|
@@ -4696,10 +5002,10 @@ async function getDataSources(request, reply) {
|
|
|
4696
5002
|
}
|
|
4697
5003
|
}
|
|
4698
5004
|
async function getDatasourceMetrics(request, reply) {
|
|
4699
|
-
const tenantId =
|
|
5005
|
+
const tenantId = getTenantId10(request);
|
|
4700
5006
|
const { key, datasourceId } = request.params;
|
|
4701
5007
|
try {
|
|
4702
|
-
const storeLattice = (0,
|
|
5008
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4703
5009
|
const store = storeLattice.store;
|
|
4704
5010
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4705
5011
|
if (!config) {
|
|
@@ -4717,7 +5023,7 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
4717
5023
|
};
|
|
4718
5024
|
}
|
|
4719
5025
|
const semanticConfig = config.config;
|
|
4720
|
-
const client = new
|
|
5026
|
+
const client = new import_core23.SemanticMetricsClient(semanticConfig);
|
|
4721
5027
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
4722
5028
|
return {
|
|
4723
5029
|
success: true,
|
|
@@ -4733,11 +5039,11 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
4733
5039
|
}
|
|
4734
5040
|
}
|
|
4735
5041
|
async function querySemanticMetrics(request, reply) {
|
|
4736
|
-
const tenantId =
|
|
5042
|
+
const tenantId = getTenantId10(request);
|
|
4737
5043
|
const { key } = request.params;
|
|
4738
5044
|
const body = request.body;
|
|
4739
5045
|
try {
|
|
4740
|
-
const storeLattice = (0,
|
|
5046
|
+
const storeLattice = (0, import_core23.getStoreLattice)("default", "metrics");
|
|
4741
5047
|
const store = storeLattice.store;
|
|
4742
5048
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4743
5049
|
if (!config) {
|
|
@@ -4762,7 +5068,7 @@ async function querySemanticMetrics(request, reply) {
|
|
|
4762
5068
|
};
|
|
4763
5069
|
}
|
|
4764
5070
|
const semanticConfig = config.config;
|
|
4765
|
-
const client = new
|
|
5071
|
+
const client = new import_core23.SemanticMetricsClient(semanticConfig);
|
|
4766
5072
|
const result = await client.semanticQuery(body);
|
|
4767
5073
|
const columnNames = result.columns.map((col) => col.name);
|
|
4768
5074
|
const allDataPoints = [];
|
|
@@ -4822,7 +5128,7 @@ async function testSemanticDataSources(request, reply) {
|
|
|
4822
5128
|
password: body.password,
|
|
4823
5129
|
headers: body.headers
|
|
4824
5130
|
};
|
|
4825
|
-
const client = new
|
|
5131
|
+
const client = new import_core23.SemanticMetricsClient(testConfig);
|
|
4826
5132
|
const datasources = await client.getDataSources();
|
|
4827
5133
|
return {
|
|
4828
5134
|
success: true,
|
|
@@ -4858,7 +5164,7 @@ async function testDatasourceMetrics(request, reply) {
|
|
|
4858
5164
|
password: body.password,
|
|
4859
5165
|
headers: body.headers
|
|
4860
5166
|
};
|
|
4861
|
-
const client = new
|
|
5167
|
+
const client = new import_core23.SemanticMetricsClient(testConfig);
|
|
4862
5168
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
4863
5169
|
return {
|
|
4864
5170
|
success: true,
|
|
@@ -4890,9 +5196,9 @@ function registerMetricsServerConfigRoutes(app2) {
|
|
|
4890
5196
|
}
|
|
4891
5197
|
|
|
4892
5198
|
// src/controllers/mcp-configs.ts
|
|
4893
|
-
var
|
|
4894
|
-
var
|
|
4895
|
-
function
|
|
5199
|
+
var import_core24 = require("@axiom-lattice/core");
|
|
5200
|
+
var import_crypto6 = require("crypto");
|
|
5201
|
+
function getTenantId11(request) {
|
|
4896
5202
|
const userTenantId = request.user?.tenantId;
|
|
4897
5203
|
if (userTenantId) {
|
|
4898
5204
|
return userTenantId;
|
|
@@ -4900,9 +5206,9 @@ function getTenantId9(request) {
|
|
|
4900
5206
|
return request.headers["x-tenant-id"] || "default";
|
|
4901
5207
|
}
|
|
4902
5208
|
async function getMcpServerConfigList(request, reply) {
|
|
4903
|
-
const tenantId =
|
|
5209
|
+
const tenantId = getTenantId11(request);
|
|
4904
5210
|
try {
|
|
4905
|
-
const storeLattice = (0,
|
|
5211
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
4906
5212
|
const store = storeLattice.store;
|
|
4907
5213
|
const configs = await store.getAllConfigs(tenantId);
|
|
4908
5214
|
return {
|
|
@@ -4926,10 +5232,10 @@ async function getMcpServerConfigList(request, reply) {
|
|
|
4926
5232
|
}
|
|
4927
5233
|
}
|
|
4928
5234
|
async function getMcpServerConfig(request, reply) {
|
|
4929
|
-
const tenantId =
|
|
5235
|
+
const tenantId = getTenantId11(request);
|
|
4930
5236
|
const { key } = request.params;
|
|
4931
5237
|
try {
|
|
4932
|
-
const storeLattice = (0,
|
|
5238
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
4933
5239
|
const store = storeLattice.store;
|
|
4934
5240
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4935
5241
|
if (!config) {
|
|
@@ -4952,10 +5258,10 @@ async function getMcpServerConfig(request, reply) {
|
|
|
4952
5258
|
}
|
|
4953
5259
|
}
|
|
4954
5260
|
async function createMcpServerConfig(request, reply) {
|
|
4955
|
-
const tenantId =
|
|
5261
|
+
const tenantId = getTenantId11(request);
|
|
4956
5262
|
const body = request.body;
|
|
4957
5263
|
try {
|
|
4958
|
-
const storeLattice = (0,
|
|
5264
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
4959
5265
|
const store = storeLattice.store;
|
|
4960
5266
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
4961
5267
|
if (existing) {
|
|
@@ -4965,7 +5271,7 @@ async function createMcpServerConfig(request, reply) {
|
|
|
4965
5271
|
message: "MCP server configuration with this key already exists"
|
|
4966
5272
|
};
|
|
4967
5273
|
}
|
|
4968
|
-
const id = body.id || (0,
|
|
5274
|
+
const id = body.id || (0, import_crypto6.randomUUID)();
|
|
4969
5275
|
const config = await store.createConfig(tenantId, id, body);
|
|
4970
5276
|
try {
|
|
4971
5277
|
await connectAndRegisterTools(config);
|
|
@@ -4991,11 +5297,11 @@ async function createMcpServerConfig(request, reply) {
|
|
|
4991
5297
|
}
|
|
4992
5298
|
}
|
|
4993
5299
|
async function updateMcpServerConfig(request, reply) {
|
|
4994
|
-
const tenantId =
|
|
5300
|
+
const tenantId = getTenantId11(request);
|
|
4995
5301
|
const { key } = request.params;
|
|
4996
5302
|
const updates = request.body;
|
|
4997
5303
|
try {
|
|
4998
|
-
const storeLattice = (0,
|
|
5304
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
4999
5305
|
const store = storeLattice.store;
|
|
5000
5306
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
5001
5307
|
if (!existing) {
|
|
@@ -5015,8 +5321,8 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
5015
5321
|
}
|
|
5016
5322
|
if (shouldReconnect) {
|
|
5017
5323
|
try {
|
|
5018
|
-
if (
|
|
5019
|
-
await
|
|
5324
|
+
if (import_core24.mcpManager.hasServer(key)) {
|
|
5325
|
+
await import_core24.mcpManager.removeServer(key);
|
|
5020
5326
|
}
|
|
5021
5327
|
await connectAndRegisterTools(updated);
|
|
5022
5328
|
await store.updateConfig(tenantId, existing.id, { status: "connected" });
|
|
@@ -5041,10 +5347,10 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
5041
5347
|
}
|
|
5042
5348
|
}
|
|
5043
5349
|
async function deleteMcpServerConfig(request, reply) {
|
|
5044
|
-
const tenantId =
|
|
5350
|
+
const tenantId = getTenantId11(request);
|
|
5045
5351
|
const { keyOrId } = request.params;
|
|
5046
5352
|
try {
|
|
5047
|
-
const storeLattice = (0,
|
|
5353
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
5048
5354
|
const store = storeLattice.store;
|
|
5049
5355
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
5050
5356
|
let configKey = keyOrId;
|
|
@@ -5062,8 +5368,8 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
5062
5368
|
};
|
|
5063
5369
|
}
|
|
5064
5370
|
try {
|
|
5065
|
-
if (
|
|
5066
|
-
await
|
|
5371
|
+
if (import_core24.mcpManager.hasServer(configKey)) {
|
|
5372
|
+
await import_core24.mcpManager.removeServer(configKey);
|
|
5067
5373
|
}
|
|
5068
5374
|
} catch (error) {
|
|
5069
5375
|
console.warn("Failed to remove from MCP manager:", error);
|
|
@@ -5088,10 +5394,10 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
5088
5394
|
}
|
|
5089
5395
|
}
|
|
5090
5396
|
async function testMcpServerConnection(request, reply) {
|
|
5091
|
-
const tenantId =
|
|
5397
|
+
const tenantId = getTenantId11(request);
|
|
5092
5398
|
const { key } = request.params;
|
|
5093
5399
|
try {
|
|
5094
|
-
const storeLattice = (0,
|
|
5400
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
5095
5401
|
const store = storeLattice.store;
|
|
5096
5402
|
const config = await store.getConfigByKey(tenantId, key);
|
|
5097
5403
|
if (!config) {
|
|
@@ -5105,11 +5411,11 @@ async function testMcpServerConnection(request, reply) {
|
|
|
5105
5411
|
try {
|
|
5106
5412
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
5107
5413
|
const connection = convertToConnection(config.config);
|
|
5108
|
-
|
|
5109
|
-
await
|
|
5110
|
-
const tools = await
|
|
5414
|
+
import_core24.mcpManager.addServer(testKey, connection);
|
|
5415
|
+
await import_core24.mcpManager.connect();
|
|
5416
|
+
const tools = await import_core24.mcpManager.getAllTools();
|
|
5111
5417
|
const latency = Date.now() - startTime;
|
|
5112
|
-
await
|
|
5418
|
+
await import_core24.mcpManager.removeServer(testKey);
|
|
5113
5419
|
return {
|
|
5114
5420
|
success: true,
|
|
5115
5421
|
message: "Connection test successful",
|
|
@@ -5141,10 +5447,10 @@ async function testMcpServerConnection(request, reply) {
|
|
|
5141
5447
|
}
|
|
5142
5448
|
}
|
|
5143
5449
|
async function listMcpServerTools(request, reply) {
|
|
5144
|
-
const tenantId =
|
|
5450
|
+
const tenantId = getTenantId11(request);
|
|
5145
5451
|
const { key } = request.params;
|
|
5146
5452
|
try {
|
|
5147
|
-
const storeLattice = (0,
|
|
5453
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
5148
5454
|
const store = storeLattice.store;
|
|
5149
5455
|
const config = await store.getConfigByKey(tenantId, key);
|
|
5150
5456
|
if (!config) {
|
|
@@ -5154,10 +5460,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
5154
5460
|
message: "MCP server configuration not found"
|
|
5155
5461
|
};
|
|
5156
5462
|
}
|
|
5157
|
-
if (!
|
|
5463
|
+
if (!import_core24.mcpManager.hasServer(key)) {
|
|
5158
5464
|
await connectAndRegisterTools(config);
|
|
5159
5465
|
}
|
|
5160
|
-
const tools = await
|
|
5466
|
+
const tools = await import_core24.mcpManager.getAllTools();
|
|
5161
5467
|
return {
|
|
5162
5468
|
success: true,
|
|
5163
5469
|
message: "Tools retrieved successfully",
|
|
@@ -5174,10 +5480,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
5174
5480
|
}
|
|
5175
5481
|
}
|
|
5176
5482
|
async function connectMcpServer(request, reply) {
|
|
5177
|
-
const tenantId =
|
|
5483
|
+
const tenantId = getTenantId11(request);
|
|
5178
5484
|
const { key } = request.params;
|
|
5179
5485
|
try {
|
|
5180
|
-
const storeLattice = (0,
|
|
5486
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
5181
5487
|
const store = storeLattice.store;
|
|
5182
5488
|
const config = await store.getConfigByKey(tenantId, key);
|
|
5183
5489
|
if (!config) {
|
|
@@ -5198,7 +5504,7 @@ async function connectMcpServer(request, reply) {
|
|
|
5198
5504
|
};
|
|
5199
5505
|
} catch (error) {
|
|
5200
5506
|
console.error("Failed to connect MCP server:", error);
|
|
5201
|
-
const storeLattice = (0,
|
|
5507
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
5202
5508
|
const store = storeLattice.store;
|
|
5203
5509
|
const config = await store.getConfigByKey(tenantId, key);
|
|
5204
5510
|
if (config) {
|
|
@@ -5211,10 +5517,10 @@ async function connectMcpServer(request, reply) {
|
|
|
5211
5517
|
}
|
|
5212
5518
|
}
|
|
5213
5519
|
async function disconnectMcpServer(request, reply) {
|
|
5214
|
-
const tenantId =
|
|
5520
|
+
const tenantId = getTenantId11(request);
|
|
5215
5521
|
const { key } = request.params;
|
|
5216
5522
|
try {
|
|
5217
|
-
const storeLattice = (0,
|
|
5523
|
+
const storeLattice = (0, import_core24.getStoreLattice)("default", "mcp");
|
|
5218
5524
|
const store = storeLattice.store;
|
|
5219
5525
|
const config = await store.getConfigByKey(tenantId, key);
|
|
5220
5526
|
if (!config) {
|
|
@@ -5224,8 +5530,8 @@ async function disconnectMcpServer(request, reply) {
|
|
|
5224
5530
|
message: "MCP server configuration not found"
|
|
5225
5531
|
};
|
|
5226
5532
|
}
|
|
5227
|
-
if (
|
|
5228
|
-
await
|
|
5533
|
+
if (import_core24.mcpManager.hasServer(key)) {
|
|
5534
|
+
await import_core24.mcpManager.removeServer(key);
|
|
5229
5535
|
}
|
|
5230
5536
|
const updated = await store.updateConfig(tenantId, config.id, {
|
|
5231
5537
|
status: "disconnected"
|
|
@@ -5255,10 +5561,10 @@ async function testMcpServerTools(request, reply) {
|
|
|
5255
5561
|
}
|
|
5256
5562
|
const testKey = `__test_${Date.now()}`;
|
|
5257
5563
|
const connection = convertToConnection(body.config);
|
|
5258
|
-
|
|
5259
|
-
await
|
|
5260
|
-
const tools = await
|
|
5261
|
-
await
|
|
5564
|
+
import_core24.mcpManager.addServer(testKey, connection);
|
|
5565
|
+
await import_core24.mcpManager.connect();
|
|
5566
|
+
const tools = await import_core24.mcpManager.getAllTools();
|
|
5567
|
+
await import_core24.mcpManager.removeServer(testKey);
|
|
5262
5568
|
return {
|
|
5263
5569
|
success: true,
|
|
5264
5570
|
message: "Tools retrieved successfully",
|
|
@@ -5295,14 +5601,14 @@ function convertToConnection(config) {
|
|
|
5295
5601
|
}
|
|
5296
5602
|
async function connectAndRegisterTools(config) {
|
|
5297
5603
|
const connection = convertToConnection(config.config);
|
|
5298
|
-
|
|
5299
|
-
await
|
|
5300
|
-
const allTools = await
|
|
5604
|
+
import_core24.mcpManager.addServer(config.key, connection);
|
|
5605
|
+
await import_core24.mcpManager.connect();
|
|
5606
|
+
const allTools = await import_core24.mcpManager.getAllTools();
|
|
5301
5607
|
const selectedTools = allTools.filter(
|
|
5302
5608
|
(tool) => config.selectedTools.includes(tool.name)
|
|
5303
5609
|
);
|
|
5304
5610
|
for (const tool of selectedTools) {
|
|
5305
|
-
|
|
5611
|
+
import_core24.toolLatticeManager.registerExistingTool(tool.name, tool);
|
|
5306
5612
|
}
|
|
5307
5613
|
}
|
|
5308
5614
|
function registerMcpServerConfigRoutes(app2) {
|
|
@@ -5319,12 +5625,12 @@ function registerMcpServerConfigRoutes(app2) {
|
|
|
5319
5625
|
}
|
|
5320
5626
|
|
|
5321
5627
|
// src/controllers/eval.ts
|
|
5322
|
-
var
|
|
5628
|
+
var import_core26 = require("@axiom-lattice/core");
|
|
5323
5629
|
var import_uuid4 = require("uuid");
|
|
5324
5630
|
|
|
5325
5631
|
// src/services/eval-runner.ts
|
|
5326
5632
|
var import_events = require("events");
|
|
5327
|
-
var
|
|
5633
|
+
var import_core25 = require("@axiom-lattice/core");
|
|
5328
5634
|
var import_agent_eval = require("@axiom-lattice/agent-eval");
|
|
5329
5635
|
var import_uuid3 = require("uuid");
|
|
5330
5636
|
function mapLogs(logs) {
|
|
@@ -5386,7 +5692,7 @@ var EvalRunner = class {
|
|
|
5386
5692
|
if (hasModelKey) {
|
|
5387
5693
|
judgeModelConfig = { modelKey: judgeCfg.modelKey };
|
|
5388
5694
|
} else if (!hasCredentials) {
|
|
5389
|
-
const firstModel =
|
|
5695
|
+
const firstModel = import_core25.modelLatticeManager.getAllLattices()[0];
|
|
5390
5696
|
if (firstModel) {
|
|
5391
5697
|
judgeModelConfig = { modelKey: firstModel.key };
|
|
5392
5698
|
} else {
|
|
@@ -5497,13 +5803,13 @@ var EvalRunner = class {
|
|
|
5497
5803
|
return this.runs.has(runId);
|
|
5498
5804
|
}
|
|
5499
5805
|
getEvalStore() {
|
|
5500
|
-
return (0,
|
|
5806
|
+
return (0, import_core25.getStoreLattice)("default", "eval").store;
|
|
5501
5807
|
}
|
|
5502
5808
|
};
|
|
5503
5809
|
var evalRunner = new EvalRunner();
|
|
5504
5810
|
|
|
5505
5811
|
// src/controllers/eval.ts
|
|
5506
|
-
function
|
|
5812
|
+
function getTenantId12(request) {
|
|
5507
5813
|
const userTenantId = request.user?.tenantId;
|
|
5508
5814
|
if (userTenantId) {
|
|
5509
5815
|
return userTenantId;
|
|
@@ -5511,11 +5817,11 @@ function getTenantId10(request) {
|
|
|
5511
5817
|
return request.headers["x-tenant-id"] || "default";
|
|
5512
5818
|
}
|
|
5513
5819
|
function getEvalStore() {
|
|
5514
|
-
return (0,
|
|
5820
|
+
return (0, import_core26.getStoreLattice)("default", "eval").store;
|
|
5515
5821
|
}
|
|
5516
5822
|
async function createProject(request, reply) {
|
|
5517
5823
|
try {
|
|
5518
|
-
const tenantId =
|
|
5824
|
+
const tenantId = getTenantId12(request);
|
|
5519
5825
|
const store = getEvalStore();
|
|
5520
5826
|
const id = (0, import_uuid4.v4)();
|
|
5521
5827
|
const data = request.body;
|
|
@@ -5540,7 +5846,7 @@ async function createProject(request, reply) {
|
|
|
5540
5846
|
}
|
|
5541
5847
|
async function listProjects(request, reply) {
|
|
5542
5848
|
try {
|
|
5543
|
-
const tenantId =
|
|
5849
|
+
const tenantId = getTenantId12(request);
|
|
5544
5850
|
const store = getEvalStore();
|
|
5545
5851
|
let projects = await store.getProjectsByTenant(tenantId);
|
|
5546
5852
|
if (projects.length === 0) {
|
|
@@ -5574,7 +5880,7 @@ async function listProjects(request, reply) {
|
|
|
5574
5880
|
}
|
|
5575
5881
|
async function getProject(request, reply) {
|
|
5576
5882
|
try {
|
|
5577
|
-
const tenantId =
|
|
5883
|
+
const tenantId = getTenantId12(request);
|
|
5578
5884
|
const store = getEvalStore();
|
|
5579
5885
|
const { pid } = request.params;
|
|
5580
5886
|
const project = await store.getProjectById(tenantId, pid);
|
|
@@ -5594,7 +5900,7 @@ async function getProject(request, reply) {
|
|
|
5594
5900
|
}
|
|
5595
5901
|
async function updateProject(request, reply) {
|
|
5596
5902
|
try {
|
|
5597
|
-
const tenantId =
|
|
5903
|
+
const tenantId = getTenantId12(request);
|
|
5598
5904
|
const store = getEvalStore();
|
|
5599
5905
|
const { pid } = request.params;
|
|
5600
5906
|
const existing = await store.getProjectById(tenantId, pid);
|
|
@@ -5614,7 +5920,7 @@ async function updateProject(request, reply) {
|
|
|
5614
5920
|
}
|
|
5615
5921
|
async function deleteProject(request, reply) {
|
|
5616
5922
|
try {
|
|
5617
|
-
const tenantId =
|
|
5923
|
+
const tenantId = getTenantId12(request);
|
|
5618
5924
|
const store = getEvalStore();
|
|
5619
5925
|
const { pid } = request.params;
|
|
5620
5926
|
const existing = await store.getProjectById(tenantId, pid);
|
|
@@ -5633,7 +5939,7 @@ async function deleteProject(request, reply) {
|
|
|
5633
5939
|
}
|
|
5634
5940
|
async function createSuite(request, reply) {
|
|
5635
5941
|
try {
|
|
5636
|
-
const tenantId =
|
|
5942
|
+
const tenantId = getTenantId12(request);
|
|
5637
5943
|
const store = getEvalStore();
|
|
5638
5944
|
const { pid } = request.params;
|
|
5639
5945
|
const project = await store.getProjectById(tenantId, pid);
|
|
@@ -5655,7 +5961,7 @@ async function createSuite(request, reply) {
|
|
|
5655
5961
|
}
|
|
5656
5962
|
async function updateSuite(request, reply) {
|
|
5657
5963
|
try {
|
|
5658
|
-
const tenantId =
|
|
5964
|
+
const tenantId = getTenantId12(request);
|
|
5659
5965
|
const store = getEvalStore();
|
|
5660
5966
|
const { sid } = request.params;
|
|
5661
5967
|
const existing = await store.getSuiteById(tenantId, sid);
|
|
@@ -5675,7 +5981,7 @@ async function updateSuite(request, reply) {
|
|
|
5675
5981
|
}
|
|
5676
5982
|
async function deleteSuite(request, reply) {
|
|
5677
5983
|
try {
|
|
5678
|
-
const tenantId =
|
|
5984
|
+
const tenantId = getTenantId12(request);
|
|
5679
5985
|
const store = getEvalStore();
|
|
5680
5986
|
const { sid } = request.params;
|
|
5681
5987
|
const existing = await store.getSuiteById(tenantId, sid);
|
|
@@ -5694,7 +6000,7 @@ async function deleteSuite(request, reply) {
|
|
|
5694
6000
|
}
|
|
5695
6001
|
async function createCase(request, reply) {
|
|
5696
6002
|
try {
|
|
5697
|
-
const tenantId =
|
|
6003
|
+
const tenantId = getTenantId12(request);
|
|
5698
6004
|
const store = getEvalStore();
|
|
5699
6005
|
const { sid } = request.params;
|
|
5700
6006
|
const suite = await store.getSuiteById(tenantId, sid);
|
|
@@ -5723,7 +6029,7 @@ async function createCase(request, reply) {
|
|
|
5723
6029
|
}
|
|
5724
6030
|
async function listCasesForSuite(request, reply) {
|
|
5725
6031
|
try {
|
|
5726
|
-
const tenantId =
|
|
6032
|
+
const tenantId = getTenantId12(request);
|
|
5727
6033
|
const store = getEvalStore();
|
|
5728
6034
|
const { sid } = request.params;
|
|
5729
6035
|
const cases = await store.getCasesBySuite(tenantId, sid);
|
|
@@ -5739,7 +6045,7 @@ async function listCasesForSuite(request, reply) {
|
|
|
5739
6045
|
}
|
|
5740
6046
|
async function updateCase(request, reply) {
|
|
5741
6047
|
try {
|
|
5742
|
-
const tenantId =
|
|
6048
|
+
const tenantId = getTenantId12(request);
|
|
5743
6049
|
const store = getEvalStore();
|
|
5744
6050
|
const { cid } = request.params;
|
|
5745
6051
|
const existing = await store.getCaseById(tenantId, cid);
|
|
@@ -5759,7 +6065,7 @@ async function updateCase(request, reply) {
|
|
|
5759
6065
|
}
|
|
5760
6066
|
async function deleteCase(request, reply) {
|
|
5761
6067
|
try {
|
|
5762
|
-
const tenantId =
|
|
6068
|
+
const tenantId = getTenantId12(request);
|
|
5763
6069
|
const store = getEvalStore();
|
|
5764
6070
|
const { cid } = request.params;
|
|
5765
6071
|
const existing = await store.getCaseById(tenantId, cid);
|
|
@@ -5791,7 +6097,7 @@ function registerEvalRoutes(app2) {
|
|
|
5791
6097
|
app2.delete("/api/eval/projects/:pid/suites/:sid/cases/:cid", deleteCase);
|
|
5792
6098
|
app2.post("/api/eval/projects/:pid/runs", async (request, reply) => {
|
|
5793
6099
|
try {
|
|
5794
|
-
const tenantId =
|
|
6100
|
+
const tenantId = getTenantId12(request);
|
|
5795
6101
|
const { pid } = request.params;
|
|
5796
6102
|
const runId = await evalRunner.startRun(tenantId, pid);
|
|
5797
6103
|
reply.status(202).send({ success: true, message: "Run started", data: { run_id: runId } });
|
|
@@ -5803,7 +6109,7 @@ function registerEvalRoutes(app2) {
|
|
|
5803
6109
|
});
|
|
5804
6110
|
app2.get("/api/eval/runs", async (request, reply) => {
|
|
5805
6111
|
try {
|
|
5806
|
-
const tenantId =
|
|
6112
|
+
const tenantId = getTenantId12(request);
|
|
5807
6113
|
const query = request.query;
|
|
5808
6114
|
const runs = await getEvalStore().getRunsByTenant(tenantId, { projectId: query.project_id, status: query.status });
|
|
5809
6115
|
reply.send({ success: true, message: "Ok", data: { records: runs, total: runs.length } });
|
|
@@ -5813,7 +6119,7 @@ function registerEvalRoutes(app2) {
|
|
|
5813
6119
|
});
|
|
5814
6120
|
app2.get("/api/eval/runs/:rid", async (request, reply) => {
|
|
5815
6121
|
try {
|
|
5816
|
-
const tenantId =
|
|
6122
|
+
const tenantId = getTenantId12(request);
|
|
5817
6123
|
const { rid } = request.params;
|
|
5818
6124
|
const run = await getEvalStore().getRunById(tenantId, rid);
|
|
5819
6125
|
if (!run) return reply.status(404).send({ success: false, message: "Run not found" });
|
|
@@ -5835,7 +6141,7 @@ function registerEvalRoutes(app2) {
|
|
|
5835
6141
|
const emitter = evalRunner.getEventEmitter();
|
|
5836
6142
|
const eventKey = `run:${rid}`;
|
|
5837
6143
|
if (!evalRunner.isRunning(rid)) {
|
|
5838
|
-
const tenantId =
|
|
6144
|
+
const tenantId = getTenantId12(request);
|
|
5839
6145
|
const run = await getEvalStore().getRunById(tenantId, rid);
|
|
5840
6146
|
if (run) {
|
|
5841
6147
|
const eventType = run.status === "completed" ? "completed" : "error";
|
|
@@ -5874,7 +6180,7 @@ data: ${JSON.stringify(event.data)}
|
|
|
5874
6180
|
});
|
|
5875
6181
|
app2.delete("/api/eval/runs/:rid", async (request, reply) => {
|
|
5876
6182
|
try {
|
|
5877
|
-
const tenantId =
|
|
6183
|
+
const tenantId = getTenantId12(request);
|
|
5878
6184
|
const { rid } = request.params;
|
|
5879
6185
|
const deleted = await getEvalStore().deleteRun(tenantId, rid);
|
|
5880
6186
|
if (!deleted) return reply.status(404).send({ success: false, message: "Run not found" });
|
|
@@ -5885,7 +6191,7 @@ data: ${JSON.stringify(event.data)}
|
|
|
5885
6191
|
});
|
|
5886
6192
|
app2.get("/api/eval/reports/projects/:pid", async (request, reply) => {
|
|
5887
6193
|
try {
|
|
5888
|
-
const tenantId =
|
|
6194
|
+
const tenantId = getTenantId12(request);
|
|
5889
6195
|
const { pid } = request.params;
|
|
5890
6196
|
const report = await getEvalStore().getProjectReport(tenantId, pid);
|
|
5891
6197
|
if (!report) return reply.status(404).send({ success: false, message: "Project not found" });
|
|
@@ -5897,11 +6203,11 @@ data: ${JSON.stringify(event.data)}
|
|
|
5897
6203
|
}
|
|
5898
6204
|
|
|
5899
6205
|
// src/controllers/users.ts
|
|
5900
|
-
var
|
|
6206
|
+
var import_core27 = require("@axiom-lattice/core");
|
|
5901
6207
|
var import_uuid5 = require("uuid");
|
|
5902
6208
|
var UsersController = class {
|
|
5903
6209
|
constructor() {
|
|
5904
|
-
this.userStore = (0,
|
|
6210
|
+
this.userStore = (0, import_core27.getStoreLattice)("default", "user").store;
|
|
5905
6211
|
}
|
|
5906
6212
|
async listUsers(request, reply) {
|
|
5907
6213
|
const { email } = request.query;
|
|
@@ -5979,11 +6285,11 @@ function registerUserRoutes(app2) {
|
|
|
5979
6285
|
}
|
|
5980
6286
|
|
|
5981
6287
|
// src/controllers/tenants.ts
|
|
5982
|
-
var
|
|
6288
|
+
var import_core28 = require("@axiom-lattice/core");
|
|
5983
6289
|
var import_uuid6 = require("uuid");
|
|
5984
6290
|
var TenantsController = class {
|
|
5985
6291
|
constructor() {
|
|
5986
|
-
this.tenantStore = (0,
|
|
6292
|
+
this.tenantStore = (0, import_core28.getStoreLattice)("default", "tenant").store;
|
|
5987
6293
|
}
|
|
5988
6294
|
// ==================== Tenant CRUD ====================
|
|
5989
6295
|
async listTenants(request, reply) {
|
|
@@ -6047,7 +6353,7 @@ function registerTenantRoutes(app2) {
|
|
|
6047
6353
|
}
|
|
6048
6354
|
|
|
6049
6355
|
// src/controllers/auth.ts
|
|
6050
|
-
var
|
|
6356
|
+
var import_core29 = require("@axiom-lattice/core");
|
|
6051
6357
|
var import_uuid7 = require("uuid");
|
|
6052
6358
|
var defaultAuthConfig = {
|
|
6053
6359
|
autoApproveUsers: true,
|
|
@@ -6056,9 +6362,9 @@ var defaultAuthConfig = {
|
|
|
6056
6362
|
};
|
|
6057
6363
|
var AuthController = class {
|
|
6058
6364
|
constructor(config = {}) {
|
|
6059
|
-
this.userStore = (0,
|
|
6060
|
-
this.tenantStore = (0,
|
|
6061
|
-
this.userTenantLinkStore = (0,
|
|
6365
|
+
this.userStore = (0, import_core29.getStoreLattice)("default", "user").store;
|
|
6366
|
+
this.tenantStore = (0, import_core29.getStoreLattice)("default", "tenant").store;
|
|
6367
|
+
this.userTenantLinkStore = (0, import_core29.getStoreLattice)("default", "userTenantLink").store;
|
|
6062
6368
|
this.config = { ...defaultAuthConfig, ...config };
|
|
6063
6369
|
}
|
|
6064
6370
|
async register(request, reply) {
|
|
@@ -6212,6 +6518,8 @@ var AuthController = class {
|
|
|
6212
6518
|
});
|
|
6213
6519
|
}
|
|
6214
6520
|
const token = await this.generateToken(userId, tenantId);
|
|
6521
|
+
const link = await this.userTenantLinkStore.getLink(userId, tenantId);
|
|
6522
|
+
const linkMeta = link?.metadata || {};
|
|
6215
6523
|
return {
|
|
6216
6524
|
success: true,
|
|
6217
6525
|
data: {
|
|
@@ -6220,7 +6528,12 @@ var AuthController = class {
|
|
|
6220
6528
|
name: tenant.name,
|
|
6221
6529
|
status: tenant.status
|
|
6222
6530
|
},
|
|
6223
|
-
token
|
|
6531
|
+
token,
|
|
6532
|
+
personalAssistant: linkMeta.personalAssistantId ? {
|
|
6533
|
+
assistantId: linkMeta.personalAssistantId,
|
|
6534
|
+
projectId: linkMeta.personalProjectId || "default",
|
|
6535
|
+
workspaceId: linkMeta.personalWorkspaceId || "default"
|
|
6536
|
+
} : null
|
|
6224
6537
|
}
|
|
6225
6538
|
};
|
|
6226
6539
|
} catch (error) {
|
|
@@ -6466,82 +6779,6 @@ function normalizeChatType(chatType) {
|
|
|
6466
6779
|
return chatType === "p2p" ? "direct" : "group";
|
|
6467
6780
|
}
|
|
6468
6781
|
|
|
6469
|
-
// src/channels/lark/LarkChannelAdapter.ts
|
|
6470
|
-
var larkConfigSchema = import_zod.z.object({
|
|
6471
|
-
appId: import_zod.z.string(),
|
|
6472
|
-
appSecret: import_zod.z.string(),
|
|
6473
|
-
verificationToken: import_zod.z.string().optional(),
|
|
6474
|
-
encryptKey: import_zod.z.string().optional()
|
|
6475
|
-
});
|
|
6476
|
-
var larkChannelAdapter = {
|
|
6477
|
-
channel: "lark",
|
|
6478
|
-
configSchema: larkConfigSchema,
|
|
6479
|
-
async receive(rawPayload, installation) {
|
|
6480
|
-
const event = parseLarkMessageEvent(rawPayload);
|
|
6481
|
-
if (!event) return null;
|
|
6482
|
-
return {
|
|
6483
|
-
channel: "lark",
|
|
6484
|
-
channelInstallationId: installation.id,
|
|
6485
|
-
tenantId: installation.tenantId,
|
|
6486
|
-
sender: {
|
|
6487
|
-
id: event.openId,
|
|
6488
|
-
displayName: void 0
|
|
6489
|
-
},
|
|
6490
|
-
content: {
|
|
6491
|
-
text: event.text,
|
|
6492
|
-
metadata: {
|
|
6493
|
-
chatId: event.chatId,
|
|
6494
|
-
chatType: event.chatType,
|
|
6495
|
-
messageId: event.messageId
|
|
6496
|
-
}
|
|
6497
|
-
},
|
|
6498
|
-
conversation: {
|
|
6499
|
-
id: event.chatId,
|
|
6500
|
-
type: event.chatType
|
|
6501
|
-
},
|
|
6502
|
-
replyTarget: {
|
|
6503
|
-
adapterChannel: "lark",
|
|
6504
|
-
channelInstallationId: installation.id,
|
|
6505
|
-
rawTarget: {
|
|
6506
|
-
chatId: event.chatId,
|
|
6507
|
-
messageId: event.messageId,
|
|
6508
|
-
chatType: event.chatType
|
|
6509
|
-
}
|
|
6510
|
-
}
|
|
6511
|
-
};
|
|
6512
|
-
},
|
|
6513
|
-
async sendReply(replyTarget, message, installation) {
|
|
6514
|
-
const { createLarkSender: createLarkSender2 } = await Promise.resolve().then(() => (init_sender(), sender_exports));
|
|
6515
|
-
const sender = await createLarkSender2(installation.config);
|
|
6516
|
-
await sender.sendTextReply({
|
|
6517
|
-
chatId: replyTarget.rawTarget.chatId,
|
|
6518
|
-
text: message.text
|
|
6519
|
-
});
|
|
6520
|
-
}
|
|
6521
|
-
};
|
|
6522
|
-
|
|
6523
|
-
// src/channels/lark/verification.ts
|
|
6524
|
-
var import_crypto6 = __toESM(require("crypto"));
|
|
6525
|
-
function parseLarkRequestBody(body, encryptKey) {
|
|
6526
|
-
const parsed = body || {};
|
|
6527
|
-
if (encryptKey && typeof parsed.encrypt === "string") {
|
|
6528
|
-
return decryptLarkPayload(encryptKey, parsed.encrypt);
|
|
6529
|
-
}
|
|
6530
|
-
return parsed;
|
|
6531
|
-
}
|
|
6532
|
-
function decryptLarkPayload(encryptKey, encryptedPayload) {
|
|
6533
|
-
const key = import_crypto6.default.createHash("sha256").update(encryptKey).digest();
|
|
6534
|
-
const buffer = Buffer.from(encryptedPayload, "base64");
|
|
6535
|
-
const iv = buffer.subarray(0, 16);
|
|
6536
|
-
const ciphertext = buffer.subarray(16);
|
|
6537
|
-
const decipher = import_crypto6.default.createDecipheriv("aes-256-cbc", key, iv);
|
|
6538
|
-
const plaintext = Buffer.concat([
|
|
6539
|
-
decipher.update(ciphertext),
|
|
6540
|
-
decipher.final()
|
|
6541
|
-
]).toString("utf8");
|
|
6542
|
-
return JSON.parse(plaintext);
|
|
6543
|
-
}
|
|
6544
|
-
|
|
6545
6782
|
// src/logger/Logger.ts
|
|
6546
6783
|
var import_pino = __toESM(require("pino"));
|
|
6547
6784
|
var import_pino_pretty = require("pino-pretty");
|
|
@@ -6680,8 +6917,165 @@ var Logger = class _Logger {
|
|
|
6680
6917
|
}
|
|
6681
6918
|
};
|
|
6682
6919
|
|
|
6683
|
-
// src/channels/lark/
|
|
6920
|
+
// src/channels/lark/LarkChannelAdapter.ts
|
|
6921
|
+
var Lark = __toESM(require("@larksuiteoapi/node-sdk"));
|
|
6684
6922
|
var logger = new Logger({ serviceName: "lattice/gateway/lark" });
|
|
6923
|
+
var activeConnections = /* @__PURE__ */ new Map();
|
|
6924
|
+
function parseTextContent(content) {
|
|
6925
|
+
if (!content) return null;
|
|
6926
|
+
try {
|
|
6927
|
+
const parsed = JSON.parse(content);
|
|
6928
|
+
return typeof parsed.text === "string" ? parsed.text : null;
|
|
6929
|
+
} catch {
|
|
6930
|
+
return null;
|
|
6931
|
+
}
|
|
6932
|
+
}
|
|
6933
|
+
function normalizeChatType2(chatType) {
|
|
6934
|
+
return chatType === "p2p" ? "direct" : "group";
|
|
6935
|
+
}
|
|
6936
|
+
function wsEventToInbound(event, installationId, tenantId) {
|
|
6937
|
+
const messageId = event.message?.message_id;
|
|
6938
|
+
const chatId = event.message?.chat_id;
|
|
6939
|
+
const openId = event.sender?.sender_id?.open_id;
|
|
6940
|
+
if (!messageId || !chatId || !openId) return null;
|
|
6941
|
+
if (event.message?.message_type !== "text") return null;
|
|
6942
|
+
const text = parseTextContent(event.message.content);
|
|
6943
|
+
if (!text) return null;
|
|
6944
|
+
const chatType = normalizeChatType2(event.message.chat_type);
|
|
6945
|
+
return {
|
|
6946
|
+
channel: "lark",
|
|
6947
|
+
channelInstallationId: installationId,
|
|
6948
|
+
tenantId,
|
|
6949
|
+
sender: { id: openId, displayName: void 0 },
|
|
6950
|
+
content: { text, metadata: { chatId, chatType, messageId } },
|
|
6951
|
+
conversation: { id: chatId, type: chatType },
|
|
6952
|
+
replyTarget: {
|
|
6953
|
+
adapterChannel: "lark",
|
|
6954
|
+
channelInstallationId: installationId,
|
|
6955
|
+
rawTarget: { chatId, messageId, chatType }
|
|
6956
|
+
}
|
|
6957
|
+
};
|
|
6958
|
+
}
|
|
6959
|
+
var larkConfigSchema = import_zod.z.object({
|
|
6960
|
+
appId: import_zod.z.string(),
|
|
6961
|
+
appSecret: import_zod.z.string(),
|
|
6962
|
+
verificationToken: import_zod.z.string().optional(),
|
|
6963
|
+
encryptKey: import_zod.z.string().optional()
|
|
6964
|
+
});
|
|
6965
|
+
var larkChannelAdapter = {
|
|
6966
|
+
channel: "lark",
|
|
6967
|
+
configSchema: larkConfigSchema,
|
|
6968
|
+
async receive(rawPayload, installation) {
|
|
6969
|
+
const event = parseLarkMessageEvent(rawPayload);
|
|
6970
|
+
if (!event) return null;
|
|
6971
|
+
return {
|
|
6972
|
+
channel: "lark",
|
|
6973
|
+
channelInstallationId: installation.id,
|
|
6974
|
+
tenantId: installation.tenantId,
|
|
6975
|
+
sender: { id: event.openId, displayName: void 0 },
|
|
6976
|
+
content: {
|
|
6977
|
+
text: event.text,
|
|
6978
|
+
metadata: { chatId: event.chatId, chatType: event.chatType, messageId: event.messageId }
|
|
6979
|
+
},
|
|
6980
|
+
conversation: { id: event.chatId, type: event.chatType },
|
|
6981
|
+
replyTarget: {
|
|
6982
|
+
adapterChannel: "lark",
|
|
6983
|
+
channelInstallationId: installation.id,
|
|
6984
|
+
rawTarget: { chatId: event.chatId, messageId: event.messageId, chatType: event.chatType }
|
|
6985
|
+
}
|
|
6986
|
+
};
|
|
6987
|
+
},
|
|
6988
|
+
async sendReply(replyTarget, message, installation) {
|
|
6989
|
+
const { createLarkSender: createLarkSender2 } = await Promise.resolve().then(() => (init_sender(), sender_exports));
|
|
6990
|
+
const sender = await createLarkSender2(installation.config);
|
|
6991
|
+
await sender.sendTextReply({
|
|
6992
|
+
chatId: replyTarget.rawTarget.chatId,
|
|
6993
|
+
text: message.text
|
|
6994
|
+
});
|
|
6995
|
+
},
|
|
6996
|
+
resolveThreadId(message, binding) {
|
|
6997
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
6998
|
+
const chatType = message.conversation?.type === "direct" ? "dm" : "group";
|
|
6999
|
+
const agentId = binding.agentId;
|
|
7000
|
+
if (chatType === "dm") {
|
|
7001
|
+
return `lark:dm:${message.sender.id}:${agentId}:${date}`;
|
|
7002
|
+
}
|
|
7003
|
+
return `lark:group:${message.conversation?.id ?? "unknown"}:${agentId}:${date}`;
|
|
7004
|
+
},
|
|
7005
|
+
async connect(installation, deps) {
|
|
7006
|
+
const { id: installationId, tenantId, config } = installation;
|
|
7007
|
+
if (!config.appId || !config.appSecret) {
|
|
7008
|
+
logger.warn("Lark installation missing credentials, skipping", { installationId });
|
|
7009
|
+
return;
|
|
7010
|
+
}
|
|
7011
|
+
if (activeConnections.has(installationId)) {
|
|
7012
|
+
logger.warn("Lark WS already connected for installation, skipping", { installationId });
|
|
7013
|
+
return;
|
|
7014
|
+
}
|
|
7015
|
+
logger.info("Lark WS client starting", { installationId, tenantId });
|
|
7016
|
+
const router = deps?.router;
|
|
7017
|
+
const eventDispatcher = new Lark.EventDispatcher({}).register({
|
|
7018
|
+
"im.message.receive_v1": async (data) => {
|
|
7019
|
+
try {
|
|
7020
|
+
const inbound = wsEventToInbound(data, installationId, tenantId);
|
|
7021
|
+
if (!inbound) return;
|
|
7022
|
+
logger.info("Lark WS message received", {
|
|
7023
|
+
installationId,
|
|
7024
|
+
senderId: inbound.sender.id,
|
|
7025
|
+
chatId: data.message?.chat_id
|
|
7026
|
+
});
|
|
7027
|
+
if (router) {
|
|
7028
|
+
const result = await router.dispatch(inbound);
|
|
7029
|
+
if (!result.success) {
|
|
7030
|
+
logger.warn("Lark WS dispatch failed", {
|
|
7031
|
+
installationId,
|
|
7032
|
+
error: result.error?.message
|
|
7033
|
+
});
|
|
7034
|
+
}
|
|
7035
|
+
}
|
|
7036
|
+
} catch (err) {
|
|
7037
|
+
logger.error("Lark WS event handler error", {
|
|
7038
|
+
installationId,
|
|
7039
|
+
error: err instanceof Error ? err.message : String(err)
|
|
7040
|
+
});
|
|
7041
|
+
}
|
|
7042
|
+
}
|
|
7043
|
+
});
|
|
7044
|
+
const client = new Lark.WSClient({
|
|
7045
|
+
appId: config.appId,
|
|
7046
|
+
appSecret: config.appSecret,
|
|
7047
|
+
loggerLevel: Lark.LoggerLevel.info
|
|
7048
|
+
});
|
|
7049
|
+
await client.start({ eventDispatcher });
|
|
7050
|
+
activeConnections.set(installationId, client);
|
|
7051
|
+
logger.info("Lark WS client connected", { installationId });
|
|
7052
|
+
}
|
|
7053
|
+
};
|
|
7054
|
+
|
|
7055
|
+
// src/channels/lark/verification.ts
|
|
7056
|
+
var import_crypto7 = __toESM(require("crypto"));
|
|
7057
|
+
function parseLarkRequestBody(body, encryptKey) {
|
|
7058
|
+
const parsed = body || {};
|
|
7059
|
+
if (encryptKey && typeof parsed.encrypt === "string") {
|
|
7060
|
+
return decryptLarkPayload(encryptKey, parsed.encrypt);
|
|
7061
|
+
}
|
|
7062
|
+
return parsed;
|
|
7063
|
+
}
|
|
7064
|
+
function decryptLarkPayload(encryptKey, encryptedPayload) {
|
|
7065
|
+
const key = import_crypto7.default.createHash("sha256").update(encryptKey).digest();
|
|
7066
|
+
const buffer = Buffer.from(encryptedPayload, "base64");
|
|
7067
|
+
const iv = buffer.subarray(0, 16);
|
|
7068
|
+
const ciphertext = buffer.subarray(16);
|
|
7069
|
+
const decipher = import_crypto7.default.createDecipheriv("aes-256-cbc", key, iv);
|
|
7070
|
+
const plaintext = Buffer.concat([
|
|
7071
|
+
decipher.update(ciphertext),
|
|
7072
|
+
decipher.final()
|
|
7073
|
+
]).toString("utf8");
|
|
7074
|
+
return JSON.parse(plaintext);
|
|
7075
|
+
}
|
|
7076
|
+
|
|
7077
|
+
// src/channels/lark/controller.ts
|
|
7078
|
+
var logger2 = new Logger({ serviceName: "lattice/gateway/lark" });
|
|
6685
7079
|
function createLarkEventHandler(deps) {
|
|
6686
7080
|
return async function handleLarkEvent(request, reply) {
|
|
6687
7081
|
const { installationId } = request.params;
|
|
@@ -6702,7 +7096,7 @@ function createLarkEventHandler(deps) {
|
|
|
6702
7096
|
return;
|
|
6703
7097
|
}
|
|
6704
7098
|
deps.router.dispatch(inboundMessage).catch((error) => {
|
|
6705
|
-
|
|
7099
|
+
logger2.error("Lark message dispatch error", {
|
|
6706
7100
|
error: error instanceof Error ? error.message : String(error)
|
|
6707
7101
|
});
|
|
6708
7102
|
});
|
|
@@ -6734,8 +7128,8 @@ function registerChannelRoutes(app2, dependencies) {
|
|
|
6734
7128
|
}
|
|
6735
7129
|
|
|
6736
7130
|
// src/controllers/channel-installations.ts
|
|
6737
|
-
var
|
|
6738
|
-
function
|
|
7131
|
+
var import_crypto8 = require("crypto");
|
|
7132
|
+
function getTenantId13(request) {
|
|
6739
7133
|
const userTenantId = request.user?.tenantId;
|
|
6740
7134
|
if (userTenantId) {
|
|
6741
7135
|
return userTenantId;
|
|
@@ -6743,8 +7137,8 @@ function getTenantId11(request) {
|
|
|
6743
7137
|
return request.headers["x-tenant-id"] || "default";
|
|
6744
7138
|
}
|
|
6745
7139
|
async function getInstallationStore() {
|
|
6746
|
-
const { getStoreLattice:
|
|
6747
|
-
const store =
|
|
7140
|
+
const { getStoreLattice: getStoreLattice18 } = await import("@axiom-lattice/core");
|
|
7141
|
+
const store = getStoreLattice18("default", "channelInstallation").store;
|
|
6748
7142
|
if (store) return store;
|
|
6749
7143
|
const { PostgreSQLChannelInstallationStore } = await import("@axiom-lattice/pg-stores");
|
|
6750
7144
|
const databaseUrl = process.env.DATABASE_URL;
|
|
@@ -6756,7 +7150,7 @@ async function getInstallationStore() {
|
|
|
6756
7150
|
});
|
|
6757
7151
|
}
|
|
6758
7152
|
async function getChannelInstallationList(request, reply) {
|
|
6759
|
-
const tenantId =
|
|
7153
|
+
const tenantId = getTenantId13(request);
|
|
6760
7154
|
const { channel } = request.query;
|
|
6761
7155
|
try {
|
|
6762
7156
|
const store = await getInstallationStore();
|
|
@@ -6782,7 +7176,7 @@ async function getChannelInstallationList(request, reply) {
|
|
|
6782
7176
|
}
|
|
6783
7177
|
}
|
|
6784
7178
|
async function getChannelInstallation(request, reply) {
|
|
6785
|
-
const tenantId =
|
|
7179
|
+
const tenantId = getTenantId13(request);
|
|
6786
7180
|
const { installationId } = request.params;
|
|
6787
7181
|
try {
|
|
6788
7182
|
const store = await getInstallationStore();
|
|
@@ -6815,7 +7209,7 @@ async function getChannelInstallation(request, reply) {
|
|
|
6815
7209
|
}
|
|
6816
7210
|
}
|
|
6817
7211
|
async function createChannelInstallation(request, reply) {
|
|
6818
|
-
const tenantId =
|
|
7212
|
+
const tenantId = getTenantId13(request);
|
|
6819
7213
|
const body = request.body;
|
|
6820
7214
|
try {
|
|
6821
7215
|
if (!body.channel) {
|
|
@@ -6850,7 +7244,7 @@ async function createChannelInstallation(request, reply) {
|
|
|
6850
7244
|
}
|
|
6851
7245
|
}
|
|
6852
7246
|
const store = await getInstallationStore();
|
|
6853
|
-
const installationId = body.id || (0,
|
|
7247
|
+
const installationId = body.id || (0, import_crypto8.randomUUID)();
|
|
6854
7248
|
const installation = await store.createInstallation(
|
|
6855
7249
|
tenantId,
|
|
6856
7250
|
installationId,
|
|
@@ -6878,7 +7272,7 @@ async function createChannelInstallation(request, reply) {
|
|
|
6878
7272
|
}
|
|
6879
7273
|
}
|
|
6880
7274
|
async function updateChannelInstallation(request, reply) {
|
|
6881
|
-
const tenantId =
|
|
7275
|
+
const tenantId = getTenantId13(request);
|
|
6882
7276
|
const { installationId } = request.params;
|
|
6883
7277
|
const body = request.body;
|
|
6884
7278
|
try {
|
|
@@ -6924,7 +7318,7 @@ async function updateChannelInstallation(request, reply) {
|
|
|
6924
7318
|
}
|
|
6925
7319
|
}
|
|
6926
7320
|
async function deleteChannelInstallation(request, reply) {
|
|
6927
|
-
const tenantId =
|
|
7321
|
+
const tenantId = getTenantId13(request);
|
|
6928
7322
|
const { installationId } = request.params;
|
|
6929
7323
|
try {
|
|
6930
7324
|
const store = await getInstallationStore();
|
|
@@ -6974,17 +7368,17 @@ function registerChannelInstallationRoutes(app2) {
|
|
|
6974
7368
|
}
|
|
6975
7369
|
|
|
6976
7370
|
// src/controllers/channel-bindings.ts
|
|
6977
|
-
var
|
|
6978
|
-
function
|
|
7371
|
+
var import_core30 = require("@axiom-lattice/core");
|
|
7372
|
+
function getTenantId14(request) {
|
|
6979
7373
|
const userTenantId = request.user?.tenantId;
|
|
6980
7374
|
if (userTenantId) return userTenantId;
|
|
6981
7375
|
return request.headers["x-tenant-id"] || "default";
|
|
6982
7376
|
}
|
|
6983
7377
|
async function getBindingList(request, _reply) {
|
|
6984
|
-
const tenantId =
|
|
7378
|
+
const tenantId = getTenantId14(request);
|
|
6985
7379
|
const { channel, agentId, channelInstallationId, limit, offset } = request.query;
|
|
6986
7380
|
try {
|
|
6987
|
-
const registry = (0,
|
|
7381
|
+
const registry = (0, import_core30.getBindingRegistry)();
|
|
6988
7382
|
const bindings = await registry.list({ channel, agentId, tenantId, channelInstallationId, limit, offset });
|
|
6989
7383
|
return { success: true, message: "Bindings retrieved", data: { records: bindings, total: bindings.length } };
|
|
6990
7384
|
} catch (error) {
|
|
@@ -6993,9 +7387,9 @@ async function getBindingList(request, _reply) {
|
|
|
6993
7387
|
}
|
|
6994
7388
|
}
|
|
6995
7389
|
async function getBinding(request, reply) {
|
|
6996
|
-
const tenantId =
|
|
7390
|
+
const tenantId = getTenantId14(request);
|
|
6997
7391
|
try {
|
|
6998
|
-
const registry = (0,
|
|
7392
|
+
const registry = (0, import_core30.getBindingRegistry)();
|
|
6999
7393
|
const bindings = await registry.list({ tenantId });
|
|
7000
7394
|
const binding = bindings.find((b) => b.id === request.params.id);
|
|
7001
7395
|
if (!binding || binding.tenantId !== tenantId) {
|
|
@@ -7009,9 +7403,9 @@ async function getBinding(request, reply) {
|
|
|
7009
7403
|
}
|
|
7010
7404
|
}
|
|
7011
7405
|
async function createBinding(request, reply) {
|
|
7012
|
-
const tenantId =
|
|
7406
|
+
const tenantId = getTenantId14(request);
|
|
7013
7407
|
try {
|
|
7014
|
-
const registry = (0,
|
|
7408
|
+
const registry = (0, import_core30.getBindingRegistry)();
|
|
7015
7409
|
const binding = await registry.create({ ...request.body, tenantId });
|
|
7016
7410
|
reply.status(201);
|
|
7017
7411
|
return { success: true, message: "Binding created", data: binding };
|
|
@@ -7023,8 +7417,8 @@ async function createBinding(request, reply) {
|
|
|
7023
7417
|
}
|
|
7024
7418
|
async function updateBinding(request, reply) {
|
|
7025
7419
|
try {
|
|
7026
|
-
const tenantId =
|
|
7027
|
-
const registry = (0,
|
|
7420
|
+
const tenantId = getTenantId14(request);
|
|
7421
|
+
const registry = (0, import_core30.getBindingRegistry)();
|
|
7028
7422
|
const bindings = await registry.list({ tenantId });
|
|
7029
7423
|
const existing = bindings.find((b) => b.id === request.params.id);
|
|
7030
7424
|
if (!existing || existing.tenantId !== tenantId) {
|
|
@@ -7041,8 +7435,8 @@ async function updateBinding(request, reply) {
|
|
|
7041
7435
|
}
|
|
7042
7436
|
async function deleteBinding(request, reply) {
|
|
7043
7437
|
try {
|
|
7044
|
-
const tenantId =
|
|
7045
|
-
const registry = (0,
|
|
7438
|
+
const tenantId = getTenantId14(request);
|
|
7439
|
+
const registry = (0, import_core30.getBindingRegistry)();
|
|
7046
7440
|
const bindings = await registry.list({ tenantId });
|
|
7047
7441
|
const existing = bindings.find((b) => b.id === request.params.id);
|
|
7048
7442
|
if (!existing || existing.tenantId !== tenantId) {
|
|
@@ -7058,10 +7452,10 @@ async function deleteBinding(request, reply) {
|
|
|
7058
7452
|
}
|
|
7059
7453
|
}
|
|
7060
7454
|
async function resolveBinding(request, _reply) {
|
|
7061
|
-
const tenantId =
|
|
7455
|
+
const tenantId = getTenantId14(request);
|
|
7062
7456
|
const { channel, senderId, channelInstallationId } = request.query;
|
|
7063
7457
|
try {
|
|
7064
|
-
const registry = (0,
|
|
7458
|
+
const registry = (0, import_core30.getBindingRegistry)();
|
|
7065
7459
|
const binding = await registry.resolve({ channel, senderId, channelInstallationId, tenantId });
|
|
7066
7460
|
if (!binding) {
|
|
7067
7461
|
return { success: false, message: "No binding found", data: null };
|
|
@@ -7083,6 +7477,105 @@ function registerChannelBindingRoutes(app2) {
|
|
|
7083
7477
|
app2.delete("/api/channel-bindings/:id", deleteBinding);
|
|
7084
7478
|
}
|
|
7085
7479
|
|
|
7480
|
+
// src/controllers/menu-items.ts
|
|
7481
|
+
var import_core31 = require("@axiom-lattice/core");
|
|
7482
|
+
function getTenantId15(request) {
|
|
7483
|
+
const userTenantId = request.user?.tenantId;
|
|
7484
|
+
if (userTenantId) return userTenantId;
|
|
7485
|
+
return request.headers["x-tenant-id"] || "default";
|
|
7486
|
+
}
|
|
7487
|
+
function errorMessage(err) {
|
|
7488
|
+
return err instanceof Error ? err.message : "Unexpected error";
|
|
7489
|
+
}
|
|
7490
|
+
async function getMenuItemList(request, _reply) {
|
|
7491
|
+
const tenantId = getTenantId15(request);
|
|
7492
|
+
try {
|
|
7493
|
+
const registry = (0, import_core31.getMenuRegistry)();
|
|
7494
|
+
const items = await registry.list({ tenantId, menuTarget: request.query.menuTarget });
|
|
7495
|
+
return { success: true, message: "Menu items retrieved", data: { records: items, total: items.length } };
|
|
7496
|
+
} catch (error) {
|
|
7497
|
+
const msg = errorMessage(error);
|
|
7498
|
+
console.error("Failed to get menu items:", msg);
|
|
7499
|
+
return { success: false, message: msg, data: { records: [], total: 0 } };
|
|
7500
|
+
}
|
|
7501
|
+
}
|
|
7502
|
+
async function getMenuItem(request, reply) {
|
|
7503
|
+
const tenantId = getTenantId15(request);
|
|
7504
|
+
try {
|
|
7505
|
+
const registry = (0, import_core31.getMenuRegistry)();
|
|
7506
|
+
const item = await registry.getById(request.params.id);
|
|
7507
|
+
if (!item || item.tenantId !== tenantId) {
|
|
7508
|
+
reply.status(404);
|
|
7509
|
+
return { success: false, message: "Menu item not found" };
|
|
7510
|
+
}
|
|
7511
|
+
return { success: true, message: "Menu item retrieved", data: item };
|
|
7512
|
+
} catch (error) {
|
|
7513
|
+
const msg = errorMessage(error);
|
|
7514
|
+
console.error("Failed to get menu item:", msg);
|
|
7515
|
+
reply.status(500);
|
|
7516
|
+
return { success: false, message: msg };
|
|
7517
|
+
}
|
|
7518
|
+
}
|
|
7519
|
+
async function createMenuItem(request, reply) {
|
|
7520
|
+
const tenantId = getTenantId15(request);
|
|
7521
|
+
try {
|
|
7522
|
+
const registry = (0, import_core31.getMenuRegistry)();
|
|
7523
|
+
const item = await registry.create({ ...request.body, tenantId });
|
|
7524
|
+
reply.status(201);
|
|
7525
|
+
return { success: true, message: "Menu item created", data: item };
|
|
7526
|
+
} catch (error) {
|
|
7527
|
+
const msg = errorMessage(error);
|
|
7528
|
+
console.error("Failed to create menu item:", msg);
|
|
7529
|
+
reply.status(500);
|
|
7530
|
+
return { success: false, message: msg };
|
|
7531
|
+
}
|
|
7532
|
+
}
|
|
7533
|
+
async function updateMenuItem(request, reply) {
|
|
7534
|
+
try {
|
|
7535
|
+
const tenantId = getTenantId15(request);
|
|
7536
|
+
const registry = (0, import_core31.getMenuRegistry)();
|
|
7537
|
+
const existing = await registry.getById(request.params.id);
|
|
7538
|
+
if (!existing || existing.tenantId !== tenantId) {
|
|
7539
|
+
reply.status(404);
|
|
7540
|
+
return { success: false, message: "Menu item not found" };
|
|
7541
|
+
}
|
|
7542
|
+
const item = await registry.update(request.params.id, request.body);
|
|
7543
|
+
return { success: true, message: "Menu item updated", data: item };
|
|
7544
|
+
} catch (error) {
|
|
7545
|
+
const msg = errorMessage(error);
|
|
7546
|
+
console.error("Failed to update menu item:", msg);
|
|
7547
|
+
reply.status(500);
|
|
7548
|
+
return { success: false, message: msg };
|
|
7549
|
+
}
|
|
7550
|
+
}
|
|
7551
|
+
async function deleteMenuItem(request, reply) {
|
|
7552
|
+
try {
|
|
7553
|
+
const tenantId = getTenantId15(request);
|
|
7554
|
+
const registry = (0, import_core31.getMenuRegistry)();
|
|
7555
|
+
const existing = await registry.getById(request.params.id);
|
|
7556
|
+
if (!existing || existing.tenantId !== tenantId) {
|
|
7557
|
+
reply.status(404);
|
|
7558
|
+
return { success: false, message: "Menu item not found" };
|
|
7559
|
+
}
|
|
7560
|
+
await registry.delete(request.params.id);
|
|
7561
|
+
return { success: true, message: "Menu item deleted" };
|
|
7562
|
+
} catch (error) {
|
|
7563
|
+
const msg = errorMessage(error);
|
|
7564
|
+
console.error("Failed to delete menu item:", msg);
|
|
7565
|
+
reply.status(500);
|
|
7566
|
+
return { success: false, message: msg };
|
|
7567
|
+
}
|
|
7568
|
+
}
|
|
7569
|
+
|
|
7570
|
+
// src/routes/menu-items.ts
|
|
7571
|
+
function registerMenuItemRoutes(app2) {
|
|
7572
|
+
app2.get("/api/menu-items", getMenuItemList);
|
|
7573
|
+
app2.post("/api/menu-items", createMenuItem);
|
|
7574
|
+
app2.get("/api/menu-items/:id", getMenuItem);
|
|
7575
|
+
app2.put("/api/menu-items/:id", updateMenuItem);
|
|
7576
|
+
app2.delete("/api/menu-items/:id", deleteMenuItem);
|
|
7577
|
+
}
|
|
7578
|
+
|
|
7086
7579
|
// src/routes/a2a-bridge.ts
|
|
7087
7580
|
var import_uuid8 = require("uuid");
|
|
7088
7581
|
var log = {
|
|
@@ -7263,6 +7756,7 @@ var registerLatticeRoutes = (app2, channelDeps) => {
|
|
|
7263
7756
|
app2.post("/api/runs", createRun);
|
|
7264
7757
|
app2.post("/api/resume_stream", resumeStream);
|
|
7265
7758
|
app2.post("/api/assistants/:assistantId/threads/:threadId/abort", abortRun);
|
|
7759
|
+
app2.post("/api/assistants/:assistantId/threads/:threadId/recover", recoverRun);
|
|
7266
7760
|
app2.get(
|
|
7267
7761
|
"/api/assistants/:assistantId/:thread_id/memory",
|
|
7268
7762
|
{ schema: getAllMemoryItemsSchema },
|
|
@@ -7298,6 +7792,15 @@ var registerLatticeRoutes = (app2, channelDeps) => {
|
|
|
7298
7792
|
app2.post("/api/assistants", createAssistant);
|
|
7299
7793
|
app2.put("/api/assistants/:id", updateAssistant);
|
|
7300
7794
|
app2.delete("/api/assistants/:id", deleteAssistant);
|
|
7795
|
+
app2.post("/api/personal-assistant", createPersonalAssistant);
|
|
7796
|
+
app2.get("/api/personal-assistant", getPersonalAssistant);
|
|
7797
|
+
app2.delete("/api/personal-assistant", deletePersonalAssistant);
|
|
7798
|
+
app2.get("/api/tasks", listTasks);
|
|
7799
|
+
app2.get("/api/tasks/:id", getTask);
|
|
7800
|
+
app2.post("/api/tasks", createTask);
|
|
7801
|
+
app2.put("/api/tasks/:id", updateTask);
|
|
7802
|
+
app2.delete("/api/tasks/:id", deleteTask);
|
|
7803
|
+
app2.patch("/api/tasks/:id/complete", completeTask);
|
|
7301
7804
|
app2.get(
|
|
7302
7805
|
"/api/assistants/:assistantId/graph",
|
|
7303
7806
|
{ schema: getAgentGraphSchema },
|
|
@@ -7396,6 +7899,7 @@ var registerLatticeRoutes = (app2, channelDeps) => {
|
|
|
7396
7899
|
});
|
|
7397
7900
|
registerChannelRoutes(app2, channelDeps);
|
|
7398
7901
|
registerChannelInstallationRoutes(app2);
|
|
7902
|
+
registerMenuItemRoutes(app2);
|
|
7399
7903
|
if (channelDeps) {
|
|
7400
7904
|
registerChannelBindingRoutes(app2);
|
|
7401
7905
|
}
|
|
@@ -7473,8 +7977,8 @@ var registerLatticeRoutes = (app2, channelDeps) => {
|
|
|
7473
7977
|
};
|
|
7474
7978
|
|
|
7475
7979
|
// src/router/MessageRouter.ts
|
|
7476
|
-
var
|
|
7477
|
-
var
|
|
7980
|
+
var import_core32 = require("@axiom-lattice/core");
|
|
7981
|
+
var import_crypto9 = require("crypto");
|
|
7478
7982
|
var BindingNotFoundError = class extends Error {
|
|
7479
7983
|
constructor(message) {
|
|
7480
7984
|
super(message);
|
|
@@ -7521,6 +8025,9 @@ var MessageRouter = class {
|
|
|
7521
8025
|
inboundMessage: message,
|
|
7522
8026
|
metadata: {}
|
|
7523
8027
|
};
|
|
8028
|
+
let binding = null;
|
|
8029
|
+
let threadId;
|
|
8030
|
+
let agentId;
|
|
7524
8031
|
try {
|
|
7525
8032
|
await this.runMiddlewares(ctx, async () => {
|
|
7526
8033
|
const tenantId = message.tenantId || (await this.installationStore.getInstallationById(message.channelInstallationId))?.tenantId;
|
|
@@ -7537,16 +8044,18 @@ var MessageRouter = class {
|
|
|
7537
8044
|
);
|
|
7538
8045
|
}
|
|
7539
8046
|
console.log({ event: "dispatch:start", channel: message.channel, senderId: message.sender.id, tenantId }, "Message dispatch started");
|
|
7540
|
-
|
|
8047
|
+
const adapter = this.adapterRegistry.get(message.channel);
|
|
8048
|
+
const hasAdapterThreadStrategy = !!adapter?.resolveThreadId;
|
|
8049
|
+
binding = await this.bindingRegistry.resolve({
|
|
7541
8050
|
channel: message.channel,
|
|
7542
8051
|
senderId: message.sender.id,
|
|
7543
8052
|
channelInstallationId: message.channelInstallationId,
|
|
7544
8053
|
tenantId
|
|
7545
8054
|
});
|
|
8055
|
+
const installation = await this.installationStore.getInstallationById(
|
|
8056
|
+
message.channelInstallationId
|
|
8057
|
+
);
|
|
7546
8058
|
if (!binding) {
|
|
7547
|
-
const installation = await this.installationStore.getInstallationById(
|
|
7548
|
-
message.channelInstallationId
|
|
7549
|
-
);
|
|
7550
8059
|
if (installation?.rejectWhenNoBinding) {
|
|
7551
8060
|
console.warn({
|
|
7552
8061
|
event: "dispatch:no_binding",
|
|
@@ -7579,7 +8088,7 @@ var MessageRouter = class {
|
|
|
7579
8088
|
createdAt: /* @__PURE__ */ new Date(),
|
|
7580
8089
|
updatedAt: /* @__PURE__ */ new Date()
|
|
7581
8090
|
};
|
|
7582
|
-
} else {
|
|
8091
|
+
} else if (!hasAdapterThreadStrategy) {
|
|
7583
8092
|
console.error({
|
|
7584
8093
|
event: "dispatch:no_fallback",
|
|
7585
8094
|
channel: message.channel,
|
|
@@ -7591,47 +8100,99 @@ var MessageRouter = class {
|
|
|
7591
8100
|
);
|
|
7592
8101
|
}
|
|
7593
8102
|
}
|
|
7594
|
-
ctx.binding = binding;
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
agentId: binding.agentId,
|
|
7599
|
-
threadId: binding.threadId,
|
|
7600
|
-
threadMode: binding.threadMode,
|
|
7601
|
-
workspaceId: binding.workspaceId,
|
|
7602
|
-
projectId: binding.projectId
|
|
7603
|
-
}, "Binding resolved");
|
|
7604
|
-
if (!binding.enabled) {
|
|
7605
|
-
console.warn({
|
|
7606
|
-
event: "dispatch:binding_disabled",
|
|
8103
|
+
ctx.binding = binding ?? void 0;
|
|
8104
|
+
if (binding) {
|
|
8105
|
+
console.log({
|
|
8106
|
+
event: "dispatch:binding",
|
|
7607
8107
|
bindingId: binding.id,
|
|
7608
8108
|
agentId: binding.agentId,
|
|
7609
|
-
|
|
7610
|
-
|
|
8109
|
+
threadId: binding.threadId,
|
|
8110
|
+
threadMode: binding.threadMode,
|
|
8111
|
+
workspaceId: binding.workspaceId,
|
|
8112
|
+
projectId: binding.projectId
|
|
8113
|
+
}, "Binding resolved");
|
|
8114
|
+
if (!binding.enabled) {
|
|
8115
|
+
console.warn({
|
|
8116
|
+
event: "dispatch:binding_disabled",
|
|
8117
|
+
bindingId: binding.id,
|
|
8118
|
+
agentId: binding.agentId,
|
|
8119
|
+
senderId: message.sender.id
|
|
8120
|
+
}, "Binding is disabled, rejecting message");
|
|
8121
|
+
throw new BindingNotFoundError(
|
|
8122
|
+
`Binding for sender "${message.sender.id}" is disabled`
|
|
8123
|
+
);
|
|
8124
|
+
}
|
|
8125
|
+
}
|
|
8126
|
+
agentId = binding?.agentId ?? installation?.fallbackAgentId;
|
|
8127
|
+
if (!agentId) {
|
|
7611
8128
|
throw new BindingNotFoundError(
|
|
7612
|
-
`
|
|
8129
|
+
`No agent configured for sender "${message.sender.id}"`
|
|
7613
8130
|
);
|
|
7614
8131
|
}
|
|
7615
|
-
|
|
8132
|
+
if (hasAdapterThreadStrategy) {
|
|
8133
|
+
const resolvedThreadId = await adapter.resolveThreadId(message, binding);
|
|
8134
|
+
threadId = resolvedThreadId;
|
|
8135
|
+
console.log({
|
|
8136
|
+
event: "dispatch:thread:adapter",
|
|
8137
|
+
threadId,
|
|
8138
|
+
channel: message.channel,
|
|
8139
|
+
adapterChannel: adapter.channel
|
|
8140
|
+
}, "Thread resolved by adapter strategy");
|
|
8141
|
+
const threadStore = (0, import_core32.getStoreLattice)("default", "thread").store;
|
|
8142
|
+
try {
|
|
8143
|
+
await threadStore.createThread(
|
|
8144
|
+
tenantId,
|
|
8145
|
+
agentId,
|
|
8146
|
+
threadId,
|
|
8147
|
+
{
|
|
8148
|
+
metadata: {
|
|
8149
|
+
channel: message.channel,
|
|
8150
|
+
channelInstallationId: message.channelInstallationId,
|
|
8151
|
+
senderId: message.sender.id,
|
|
8152
|
+
bindingId: binding?.id,
|
|
8153
|
+
...message.conversation ? {
|
|
8154
|
+
conversationId: message.conversation.id,
|
|
8155
|
+
conversationType: message.conversation.type
|
|
8156
|
+
} : {}
|
|
8157
|
+
}
|
|
8158
|
+
}
|
|
8159
|
+
);
|
|
8160
|
+
console.log({
|
|
8161
|
+
event: "dispatch:thread:adapter:created",
|
|
8162
|
+
threadId
|
|
8163
|
+
}, "Thread created by adapter strategy");
|
|
8164
|
+
} catch {
|
|
8165
|
+
console.log({
|
|
8166
|
+
event: "dispatch:thread:adapter:reuse",
|
|
8167
|
+
threadId
|
|
8168
|
+
}, "Thread already exists, reusing");
|
|
8169
|
+
}
|
|
8170
|
+
} else if (binding) {
|
|
8171
|
+
if (binding.threadMode === "per_conversation") {
|
|
8172
|
+
threadId = void 0;
|
|
8173
|
+
} else {
|
|
8174
|
+
threadId = binding.threadId;
|
|
8175
|
+
}
|
|
8176
|
+
}
|
|
7616
8177
|
if (!threadId) {
|
|
7617
|
-
const threadStore = (0,
|
|
7618
|
-
const newThreadId = (0,
|
|
8178
|
+
const threadStore = (0, import_core32.getStoreLattice)("default", "thread").store;
|
|
8179
|
+
const newThreadId = (0, import_crypto9.randomUUID)();
|
|
7619
8180
|
console.log({
|
|
7620
8181
|
event: "dispatch:thread:create",
|
|
7621
|
-
agentId
|
|
8182
|
+
agentId,
|
|
7622
8183
|
newThreadId,
|
|
7623
8184
|
tenantId
|
|
7624
8185
|
}, "Creating new thread for binding");
|
|
7625
8186
|
const newThread = await threadStore.createThread(
|
|
7626
8187
|
tenantId,
|
|
7627
|
-
|
|
8188
|
+
agentId,
|
|
7628
8189
|
newThreadId,
|
|
7629
8190
|
{
|
|
7630
8191
|
metadata: {
|
|
7631
8192
|
channel: message.channel,
|
|
7632
8193
|
channelInstallationId: message.channelInstallationId,
|
|
7633
8194
|
senderId: message.sender.id,
|
|
7634
|
-
bindingId:
|
|
8195
|
+
bindingId: binding?.id,
|
|
7635
8196
|
...message.conversation ? {
|
|
7636
8197
|
conversationId: message.conversation.id,
|
|
7637
8198
|
conversationType: message.conversation.type
|
|
@@ -7640,36 +8201,35 @@ var MessageRouter = class {
|
|
|
7640
8201
|
}
|
|
7641
8202
|
);
|
|
7642
8203
|
threadId = newThread.id;
|
|
7643
|
-
if (
|
|
7644
|
-
await this.bindingRegistry.update(
|
|
7645
|
-
|
|
7646
|
-
} else {
|
|
7647
|
-
|
|
8204
|
+
if (binding && binding.id !== "fallback") {
|
|
8205
|
+
await this.bindingRegistry.update(binding.id, { threadId });
|
|
8206
|
+
binding.threadId = threadId;
|
|
8207
|
+
} else if (binding) {
|
|
8208
|
+
binding.threadId = threadId;
|
|
7648
8209
|
}
|
|
7649
8210
|
}
|
|
7650
8211
|
console.log({
|
|
7651
8212
|
event: "dispatch:agent",
|
|
7652
|
-
agentId
|
|
8213
|
+
agentId,
|
|
7653
8214
|
threadId,
|
|
7654
|
-
threadMode: ctx.binding.threadMode,
|
|
7655
8215
|
senderId: message.sender.id,
|
|
7656
8216
|
contentLength: message.content.text.length
|
|
7657
8217
|
}, "Dispatching to agent");
|
|
7658
|
-
const agent =
|
|
8218
|
+
const agent = import_core32.agentInstanceManager.getAgent({
|
|
7659
8219
|
tenant_id: tenantId,
|
|
7660
|
-
assistant_id:
|
|
8220
|
+
assistant_id: agentId,
|
|
7661
8221
|
thread_id: threadId,
|
|
7662
|
-
workspace_id:
|
|
7663
|
-
project_id:
|
|
8222
|
+
workspace_id: binding?.workspaceId || "",
|
|
8223
|
+
project_id: binding?.projectId || ""
|
|
7664
8224
|
});
|
|
7665
8225
|
if (message.replyTarget) {
|
|
7666
8226
|
const replySubKey = `${threadId}:${message.replyTarget.adapterChannel}:reply`;
|
|
7667
|
-
const
|
|
7668
|
-
if (
|
|
7669
|
-
const
|
|
8227
|
+
const adapter2 = this.adapterRegistry.get(message.replyTarget.adapterChannel);
|
|
8228
|
+
if (adapter2) {
|
|
8229
|
+
const installation2 = await this.installationStore.getInstallationById(
|
|
7670
8230
|
message.channelInstallationId
|
|
7671
8231
|
);
|
|
7672
|
-
if (
|
|
8232
|
+
if (installation2) {
|
|
7673
8233
|
const existing = this._replySubs.get(replySubKey);
|
|
7674
8234
|
if (!existing || existing.count === 0) {
|
|
7675
8235
|
const timer = setTimeout(() => {
|
|
@@ -7709,7 +8269,7 @@ var MessageRouter = class {
|
|
|
7709
8269
|
channel: message.replyTarget.adapterChannel,
|
|
7710
8270
|
replyLength: replyText.length
|
|
7711
8271
|
}, "Sending channel reply");
|
|
7712
|
-
|
|
8272
|
+
adapter2.sendReply(message.replyTarget, { text: replyText }, installation2).then(() => {
|
|
7713
8273
|
console.log({
|
|
7714
8274
|
event: "dispatch:reply:sent",
|
|
7715
8275
|
threadId,
|
|
@@ -7747,7 +8307,7 @@ var MessageRouter = class {
|
|
|
7747
8307
|
});
|
|
7748
8308
|
console.log({
|
|
7749
8309
|
event: "dispatch:complete",
|
|
7750
|
-
agentId
|
|
8310
|
+
agentId,
|
|
7751
8311
|
threadId,
|
|
7752
8312
|
messageId: addResult?.messageId,
|
|
7753
8313
|
result: JSON.stringify(addResult)
|
|
@@ -7756,7 +8316,7 @@ var MessageRouter = class {
|
|
|
7756
8316
|
return {
|
|
7757
8317
|
success: true,
|
|
7758
8318
|
bindingId: ctx.binding?.id,
|
|
7759
|
-
threadId
|
|
8319
|
+
threadId,
|
|
7760
8320
|
result: ctx.result
|
|
7761
8321
|
};
|
|
7762
8322
|
} catch (error) {
|
|
@@ -7867,13 +8427,13 @@ function createRateLimitMiddleware(maxRequests = 10, windowMs = 60 * 1e3, maxEnt
|
|
|
7867
8427
|
}
|
|
7868
8428
|
|
|
7869
8429
|
// src/router/middlewares/auditLogger.ts
|
|
7870
|
-
var
|
|
8430
|
+
var logger3 = new Logger({ serviceName: "lattice/gateway/audit" });
|
|
7871
8431
|
function createAuditLoggerMiddleware() {
|
|
7872
8432
|
return async (ctx, next) => {
|
|
7873
8433
|
const start2 = Date.now();
|
|
7874
8434
|
try {
|
|
7875
8435
|
await next();
|
|
7876
|
-
|
|
8436
|
+
logger3.info("message routed", {
|
|
7877
8437
|
event: "message:routed",
|
|
7878
8438
|
channel: ctx.inboundMessage.channel,
|
|
7879
8439
|
senderId: ctx.inboundMessage.sender.id,
|
|
@@ -7883,7 +8443,7 @@ function createAuditLoggerMiddleware() {
|
|
|
7883
8443
|
status: "success"
|
|
7884
8444
|
});
|
|
7885
8445
|
} catch (error) {
|
|
7886
|
-
|
|
8446
|
+
logger3.error(
|
|
7887
8447
|
error instanceof Error ? error.message : String(error),
|
|
7888
8448
|
{
|
|
7889
8449
|
event: "message:error",
|
|
@@ -7899,7 +8459,7 @@ function createAuditLoggerMiddleware() {
|
|
|
7899
8459
|
}
|
|
7900
8460
|
|
|
7901
8461
|
// src/index.ts
|
|
7902
|
-
var
|
|
8462
|
+
var import_core35 = require("@axiom-lattice/core");
|
|
7903
8463
|
|
|
7904
8464
|
// src/swagger.ts
|
|
7905
8465
|
var import_swagger = __toESM(require("@fastify/swagger"));
|
|
@@ -7964,7 +8524,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
|
|
|
7964
8524
|
};
|
|
7965
8525
|
|
|
7966
8526
|
// src/services/agent_task_consumer.ts
|
|
7967
|
-
var
|
|
8527
|
+
var import_core33 = require("@axiom-lattice/core");
|
|
7968
8528
|
var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
7969
8529
|
const {
|
|
7970
8530
|
assistant_id,
|
|
@@ -7982,21 +8542,22 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
7982
8542
|
console.log(
|
|
7983
8543
|
`\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
7984
8544
|
);
|
|
7985
|
-
const agent =
|
|
7986
|
-
await agent.addMessage({ input, command, custom_run_config: runConfig },
|
|
8545
|
+
const agent = import_core33.agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
|
|
8546
|
+
await agent.addMessage({ input, command, custom_run_config: runConfig }, import_core33.QueueMode.STEER);
|
|
7987
8547
|
if (callback_event) {
|
|
7988
8548
|
agent.subscribeOnce("message:completed", (evt) => {
|
|
7989
|
-
|
|
8549
|
+
import_core33.eventBus.publish(callback_event, {
|
|
7990
8550
|
success: true,
|
|
7991
|
-
state: evt.state
|
|
7992
|
-
config: { assistant_id, thread_id, tenant_id }
|
|
8551
|
+
state: evt.state
|
|
7993
8552
|
});
|
|
7994
8553
|
if (main_thread_id && main_tenant_id) {
|
|
7995
8554
|
try {
|
|
7996
|
-
const mainAgent =
|
|
8555
|
+
const mainAgent = import_core33.agentInstanceManager.getAgent({
|
|
7997
8556
|
assistant_id: main_assistant_id ?? assistant_id,
|
|
7998
8557
|
thread_id: main_thread_id,
|
|
7999
|
-
tenant_id: main_tenant_id
|
|
8558
|
+
tenant_id: main_tenant_id,
|
|
8559
|
+
workspace_id: runConfig?.workspaceId,
|
|
8560
|
+
project_id: runConfig?.projectId
|
|
8000
8561
|
});
|
|
8001
8562
|
if (mainAgent) {
|
|
8002
8563
|
const messages = evt.state?.values?.messages;
|
|
@@ -8021,10 +8582,9 @@ ${summary}`
|
|
|
8021
8582
|
}
|
|
8022
8583
|
});
|
|
8023
8584
|
agent.subscribeOnce("message:interrupted", (evt) => {
|
|
8024
|
-
|
|
8585
|
+
import_core33.eventBus.publish(callback_event, {
|
|
8025
8586
|
success: true,
|
|
8026
|
-
state: evt.state
|
|
8027
|
-
config: { assistant_id, thread_id, tenant_id }
|
|
8587
|
+
state: evt.state
|
|
8028
8588
|
});
|
|
8029
8589
|
});
|
|
8030
8590
|
}
|
|
@@ -8045,10 +8605,9 @@ ${summary}`
|
|
|
8045
8605
|
return handleAgentTask(taskRequest, nextRetryCount);
|
|
8046
8606
|
}
|
|
8047
8607
|
if (callback_event) {
|
|
8048
|
-
|
|
8608
|
+
import_core33.eventBus.publish(callback_event, {
|
|
8049
8609
|
success: false,
|
|
8050
|
-
error: error instanceof Error ? error.message : String(error)
|
|
8051
|
-
config: { assistant_id, thread_id, tenant_id }
|
|
8610
|
+
error: error instanceof Error ? error.message : String(error)
|
|
8052
8611
|
});
|
|
8053
8612
|
}
|
|
8054
8613
|
console.error(
|
|
@@ -8083,7 +8642,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
8083
8642
|
* 初始化事件监听和队列轮询
|
|
8084
8643
|
*/
|
|
8085
8644
|
initialize() {
|
|
8086
|
-
|
|
8645
|
+
import_core33.eventBus.subscribe(import_core33.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
|
|
8087
8646
|
this.startPollingQueue();
|
|
8088
8647
|
console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
|
|
8089
8648
|
}
|
|
@@ -8202,14 +8761,9 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
8202
8761
|
handleAgentTask(taskRequest).catch((error) => {
|
|
8203
8762
|
console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
|
|
8204
8763
|
if (taskRequest.callback_event) {
|
|
8205
|
-
|
|
8764
|
+
import_core33.eventBus.publish(taskRequest.callback_event, {
|
|
8206
8765
|
success: false,
|
|
8207
|
-
error: error instanceof Error ? error.message : String(error)
|
|
8208
|
-
config: {
|
|
8209
|
-
assistant_id: taskRequest.assistant_id,
|
|
8210
|
-
thread_id: taskRequest.thread_id,
|
|
8211
|
-
tenant_id: taskRequest["x-tenant-id"]
|
|
8212
|
-
}
|
|
8766
|
+
error: error instanceof Error ? error.message : String(error)
|
|
8213
8767
|
});
|
|
8214
8768
|
}
|
|
8215
8769
|
});
|
|
@@ -8222,7 +8776,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
|
|
|
8222
8776
|
var AgentTaskConsumer = _AgentTaskConsumer;
|
|
8223
8777
|
|
|
8224
8778
|
// src/index.ts
|
|
8225
|
-
var
|
|
8779
|
+
var import_core36 = require("@axiom-lattice/core");
|
|
8226
8780
|
var import_protocols5 = require("@axiom-lattice/protocols");
|
|
8227
8781
|
var import_meta = {};
|
|
8228
8782
|
process.on("unhandledRejection", (reason, promise) => {
|
|
@@ -8236,13 +8790,13 @@ var DEFAULT_LOGGER_CONFIG = {
|
|
|
8236
8790
|
loggerName: "lattice/gateway"
|
|
8237
8791
|
};
|
|
8238
8792
|
var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
|
|
8239
|
-
var
|
|
8793
|
+
var logger4 = loggerLattice.client;
|
|
8240
8794
|
function initializeLogger(config) {
|
|
8241
|
-
if (
|
|
8242
|
-
|
|
8795
|
+
if (import_core36.loggerLatticeManager.hasLattice("default")) {
|
|
8796
|
+
import_core36.loggerLatticeManager.removeLattice("default");
|
|
8243
8797
|
}
|
|
8244
|
-
(0,
|
|
8245
|
-
return (0,
|
|
8798
|
+
(0, import_core36.registerLoggerLattice)("default", config);
|
|
8799
|
+
return (0, import_core36.getLoggerLattice)("default");
|
|
8246
8800
|
}
|
|
8247
8801
|
var app = (0, import_fastify.default)({
|
|
8248
8802
|
logger: false,
|
|
@@ -8335,7 +8889,7 @@ app.setErrorHandler((error, request, reply) => {
|
|
|
8335
8889
|
"x-request-id": getHeaderValue(request.headers["x-request-id"]),
|
|
8336
8890
|
"x-user-id": getHeaderValue(request.headers["x-user-id"])
|
|
8337
8891
|
};
|
|
8338
|
-
|
|
8892
|
+
logger4.error(
|
|
8339
8893
|
`\u8BF7\u6C42\u9519\u8BEF: ${request.method} ${request.url} error:${error.message}`,
|
|
8340
8894
|
{
|
|
8341
8895
|
...context,
|
|
@@ -8351,7 +8905,7 @@ app.setErrorHandler((error, request, reply) => {
|
|
|
8351
8905
|
});
|
|
8352
8906
|
function getConfiguredSandboxProvider() {
|
|
8353
8907
|
const sandboxProviderType = process.env.SANDBOX_PROVIDER_TYPE || "microsandbox-remote";
|
|
8354
|
-
return (0,
|
|
8908
|
+
return (0, import_core36.createSandboxProvider)({
|
|
8355
8909
|
type: sandboxProviderType,
|
|
8356
8910
|
remoteBaseURL: process.env.SANDBOX_BASE_URL,
|
|
8357
8911
|
microsandboxServiceBaseURL: process.env.MICROSANDBOX_SERVICE_BASE_URL,
|
|
@@ -8375,17 +8929,19 @@ var start = async (config) => {
|
|
|
8375
8929
|
file: config.loggerConfig.file || DEFAULT_LOGGER_CONFIG.file
|
|
8376
8930
|
};
|
|
8377
8931
|
loggerLattice = initializeLogger(loggerConfig);
|
|
8378
|
-
|
|
8932
|
+
logger4 = loggerLattice.client;
|
|
8379
8933
|
}
|
|
8380
8934
|
app.decorate("loggerLattice", loggerLattice);
|
|
8381
8935
|
let channelDeps;
|
|
8936
|
+
const adapterRegistry = new ChannelAdapterRegistry();
|
|
8937
|
+
adapterRegistry.register(larkChannelAdapter);
|
|
8382
8938
|
try {
|
|
8383
|
-
const { getStoreLattice:
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
(
|
|
8387
|
-
|
|
8388
|
-
|
|
8939
|
+
const { getStoreLattice: getStore2 } = await import("@axiom-lattice/core");
|
|
8940
|
+
let bindingStore;
|
|
8941
|
+
let installationStore;
|
|
8942
|
+
bindingStore = getStore2("default", "channelBinding").store;
|
|
8943
|
+
installationStore = getStore2("default", "channelInstallation").store;
|
|
8944
|
+
(0, import_core35.setBindingRegistry)(bindingStore);
|
|
8389
8945
|
const router = new MessageRouter({
|
|
8390
8946
|
middlewares: [
|
|
8391
8947
|
createDeduplicationMiddleware(),
|
|
@@ -8398,27 +8954,49 @@ var start = async (config) => {
|
|
|
8398
8954
|
});
|
|
8399
8955
|
channelDeps = { router, installationStore };
|
|
8400
8956
|
try {
|
|
8401
|
-
const a2aKeyStore =
|
|
8957
|
+
const a2aKeyStore = getStore2("default", "a2aApiKey").store;
|
|
8402
8958
|
const a2a = await Promise.resolve().then(() => (init_a2a(), a2a_exports));
|
|
8403
8959
|
a2a.setA2AKeyStore(a2aKeyStore);
|
|
8404
8960
|
await a2a.refreshStoreKeyMap();
|
|
8405
|
-
|
|
8961
|
+
logger4.info("A2A key store initialized");
|
|
8406
8962
|
} catch {
|
|
8407
8963
|
}
|
|
8964
|
+
} catch (err) {
|
|
8965
|
+
logger4.warn("Channel infrastructure unavailable", {
|
|
8966
|
+
error: err instanceof Error ? err.message : String(err)
|
|
8967
|
+
});
|
|
8968
|
+
}
|
|
8969
|
+
try {
|
|
8970
|
+
const menuStore = (0, import_core36.getStoreLattice)("default", "menu").store;
|
|
8971
|
+
(0, import_core35.setMenuRegistry)(menuStore);
|
|
8972
|
+
logger4.info("Menu registry initialized");
|
|
8408
8973
|
} catch {
|
|
8409
8974
|
}
|
|
8410
8975
|
registerLatticeRoutes(app, channelDeps);
|
|
8411
|
-
if (!
|
|
8412
|
-
|
|
8413
|
-
|
|
8976
|
+
if (!import_core36.sandboxLatticeManager.hasLattice("default")) {
|
|
8977
|
+
import_core36.sandboxLatticeManager.registerLattice("default", getConfiguredSandboxProvider());
|
|
8978
|
+
logger4.info("Registered sandbox manager from env configuration");
|
|
8979
|
+
}
|
|
8980
|
+
if (channelDeps && process.env.CHANNELS_ENABLED !== "false") {
|
|
8981
|
+
const { connectAllChannels } = await import("@axiom-lattice/core");
|
|
8982
|
+
try {
|
|
8983
|
+
await connectAllChannels(
|
|
8984
|
+
(channel) => adapterRegistry.get(channel),
|
|
8985
|
+
{ deps: { router: channelDeps.router } }
|
|
8986
|
+
);
|
|
8987
|
+
} catch (err) {
|
|
8988
|
+
logger4.error("Failed to start channel connections", {
|
|
8989
|
+
error: err instanceof Error ? err.message : String(err)
|
|
8990
|
+
});
|
|
8991
|
+
}
|
|
8414
8992
|
}
|
|
8415
8993
|
const target_port = config?.port || Number(process.env.PORT) || 4001;
|
|
8416
8994
|
await app.listen({ port: target_port, host: "0.0.0.0" });
|
|
8417
|
-
|
|
8995
|
+
logger4.info(`Lattice Gateway is running on port: ${target_port}`);
|
|
8418
8996
|
try {
|
|
8419
|
-
|
|
8997
|
+
logger4.info("AgentLifecycleManager initialized");
|
|
8420
8998
|
} catch (error) {
|
|
8421
|
-
|
|
8999
|
+
logger4.warn("Failed to initialize AgentLifecycleManager", { error });
|
|
8422
9000
|
}
|
|
8423
9001
|
const queueServiceConfig = config?.queueServiceConfig;
|
|
8424
9002
|
if (queueServiceConfig) {
|
|
@@ -8428,15 +9006,13 @@ var start = async (config) => {
|
|
|
8428
9006
|
agentTaskConsumer.startPollingQueue();
|
|
8429
9007
|
}
|
|
8430
9008
|
}
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
}
|
|
8436
|
-
logger3.error("Agent recovery failed", { error });
|
|
8437
|
-
}
|
|
9009
|
+
import_core36.agentInstanceManager.restore().then((stats) => {
|
|
9010
|
+
logger4.info(`Agent recovery complete: ${stats.restored} threads restored, ${stats.errors} errors`);
|
|
9011
|
+
}).catch((error) => {
|
|
9012
|
+
logger4.error("Agent recovery failed", { error });
|
|
9013
|
+
});
|
|
8438
9014
|
} catch (err) {
|
|
8439
|
-
|
|
9015
|
+
logger4.error("Server start failed", { error: err });
|
|
8440
9016
|
process.exit(1);
|
|
8441
9017
|
}
|
|
8442
9018
|
};
|