@axiom-lattice/gateway 2.1.92 → 2.1.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +22 -0
- package/dist/index.js +972 -385
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +876 -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/controllers/workspace.ts +12 -0
- package/src/index.ts +55 -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.mjs
CHANGED
|
@@ -19,6 +19,11 @@ function getTenantId(request) {
|
|
|
19
19
|
}
|
|
20
20
|
return request.headers["x-tenant-id"] || "default";
|
|
21
21
|
}
|
|
22
|
+
function getUserId(request) {
|
|
23
|
+
const userId = request.user?.id;
|
|
24
|
+
if (userId) return userId;
|
|
25
|
+
return request.headers["x-user-id"] || void 0;
|
|
26
|
+
}
|
|
22
27
|
function convertAgentConfigToAssistant(config) {
|
|
23
28
|
return {
|
|
24
29
|
id: config.key,
|
|
@@ -51,12 +56,17 @@ async function getAssistantList(request, reply) {
|
|
|
51
56
|
assistantMap.set(assistant.id, assistant);
|
|
52
57
|
});
|
|
53
58
|
const allAssistants = Array.from(assistantMap.values());
|
|
59
|
+
const userId = getUserId(request);
|
|
60
|
+
const filtered = allAssistants.filter((a) => {
|
|
61
|
+
if (!a.ownerUserId) return true;
|
|
62
|
+
return a.ownerUserId === userId;
|
|
63
|
+
});
|
|
54
64
|
return {
|
|
55
65
|
success: true,
|
|
56
66
|
message: "Successfully retrieved assistant list",
|
|
57
67
|
data: {
|
|
58
|
-
records:
|
|
59
|
-
total:
|
|
68
|
+
records: filtered,
|
|
69
|
+
total: filtered.length
|
|
60
70
|
}
|
|
61
71
|
};
|
|
62
72
|
}
|
|
@@ -204,7 +214,7 @@ import {
|
|
|
204
214
|
agentInstanceManager as agentInstanceManager2
|
|
205
215
|
} from "@axiom-lattice/core";
|
|
206
216
|
import { MessageChunkTypes } from "@axiom-lattice/protocols";
|
|
207
|
-
function
|
|
217
|
+
function getUserId2(request) {
|
|
208
218
|
const authUser = request.user;
|
|
209
219
|
if (authUser?.id) return authUser.id;
|
|
210
220
|
return request.headers["x-user-id"] || void 0;
|
|
@@ -226,7 +236,7 @@ var createRun = async (request, reply) => {
|
|
|
226
236
|
const workspace_id = request.headers["x-workspace-id"];
|
|
227
237
|
const project_id = request.headers["x-project-id"];
|
|
228
238
|
const x_request_id = request.headers["x-request-id"] || v4();
|
|
229
|
-
const user_id =
|
|
239
|
+
const user_id = getUserId2(request);
|
|
230
240
|
const mergedConfig = user_id ? { ...custom_run_config, user_id } : custom_run_config;
|
|
231
241
|
if (!assistant_id) {
|
|
232
242
|
reply.status(400).send({
|
|
@@ -380,6 +390,33 @@ var abortRun = async (request, reply) => {
|
|
|
380
390
|
});
|
|
381
391
|
}
|
|
382
392
|
};
|
|
393
|
+
var recoverRun = async (request, reply) => {
|
|
394
|
+
try {
|
|
395
|
+
const { assistantId, threadId } = request.params;
|
|
396
|
+
const tenant_id = request.headers["x-tenant-id"];
|
|
397
|
+
const workspace_id = request.headers["x-workspace-id"] || "default";
|
|
398
|
+
const project_id = request.headers["x-project-id"] || "default";
|
|
399
|
+
const agent = agentInstanceManager2.getAgent({
|
|
400
|
+
assistant_id: assistantId,
|
|
401
|
+
thread_id: threadId,
|
|
402
|
+
tenant_id,
|
|
403
|
+
workspace_id,
|
|
404
|
+
project_id
|
|
405
|
+
});
|
|
406
|
+
await agent.resumeTask();
|
|
407
|
+
const status = await agent.getRunStatus();
|
|
408
|
+
reply.status(200).send({
|
|
409
|
+
success: true,
|
|
410
|
+
threadId,
|
|
411
|
+
status
|
|
412
|
+
});
|
|
413
|
+
} catch (error) {
|
|
414
|
+
reply.status(500).send({
|
|
415
|
+
success: false,
|
|
416
|
+
error: `Recover failed: ${error.message}`
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
};
|
|
383
420
|
|
|
384
421
|
// src/controllers/memory.ts
|
|
385
422
|
import { agentInstanceManager as agentInstanceManager3 } from "@axiom-lattice/core";
|
|
@@ -552,6 +589,8 @@ var triggerAgentTask = async (request, reply) => {
|
|
|
552
589
|
try {
|
|
553
590
|
const { assistant_id, thread_id, input, command } = request.body;
|
|
554
591
|
const tenant_id = request.headers["x-tenant-id"];
|
|
592
|
+
const workspace_id = request.headers["x-workspace-id"];
|
|
593
|
+
const project_id = request.headers["x-project-id"];
|
|
555
594
|
if (!assistant_id) {
|
|
556
595
|
reply.status(400).send({
|
|
557
596
|
success: false,
|
|
@@ -572,7 +611,12 @@ var triggerAgentTask = async (request, reply) => {
|
|
|
572
611
|
thread_id,
|
|
573
612
|
input,
|
|
574
613
|
command,
|
|
575
|
-
"x-tenant-id": tenant_id
|
|
614
|
+
"x-tenant-id": tenant_id,
|
|
615
|
+
runConfig: {
|
|
616
|
+
workspaceId: workspace_id,
|
|
617
|
+
projectId: project_id,
|
|
618
|
+
user_id: request.user?.id
|
|
619
|
+
}
|
|
576
620
|
});
|
|
577
621
|
reply.status(200).send({
|
|
578
622
|
success: true
|
|
@@ -2167,6 +2211,268 @@ async function replyInboxTask(request, reply) {
|
|
|
2167
2211
|
}
|
|
2168
2212
|
}
|
|
2169
2213
|
|
|
2214
|
+
// src/controllers/personal-assistant.ts
|
|
2215
|
+
import { getStoreLattice as getStoreLattice5, PersonalAssistantConfig } from "@axiom-lattice/core";
|
|
2216
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
2217
|
+
function getWorkspaceId2(request) {
|
|
2218
|
+
return request.headers["x-workspace-id"] || "default";
|
|
2219
|
+
}
|
|
2220
|
+
function getTenantId7(request) {
|
|
2221
|
+
const userTenantId = request.user?.tenantId;
|
|
2222
|
+
if (userTenantId) return userTenantId;
|
|
2223
|
+
return request.headers["x-tenant-id"] || "default";
|
|
2224
|
+
}
|
|
2225
|
+
function getUserId3(request) {
|
|
2226
|
+
const userId = request.user?.id || request.headers["x-user-id"];
|
|
2227
|
+
if (!userId) throw new Error("User ID is required");
|
|
2228
|
+
return userId;
|
|
2229
|
+
}
|
|
2230
|
+
function getLinkStore() {
|
|
2231
|
+
return getStoreLattice5("default", "userTenantLink").store;
|
|
2232
|
+
}
|
|
2233
|
+
function getAssistantStore() {
|
|
2234
|
+
return getStoreLattice5("default", "assistant").store;
|
|
2235
|
+
}
|
|
2236
|
+
function getProjectStore() {
|
|
2237
|
+
return getStoreLattice5("default", "project").store;
|
|
2238
|
+
}
|
|
2239
|
+
async function getLinkMeta(userId, tenantId) {
|
|
2240
|
+
const link = await getLinkStore().getLink(userId, tenantId);
|
|
2241
|
+
return link?.metadata || {};
|
|
2242
|
+
}
|
|
2243
|
+
async function updateLinkMeta(userId, tenantId, meta) {
|
|
2244
|
+
await getLinkStore().updateLink(userId, tenantId, { metadata: meta });
|
|
2245
|
+
}
|
|
2246
|
+
async function createPersonalAssistant(request, reply) {
|
|
2247
|
+
const tenantId = getTenantId7(request);
|
|
2248
|
+
const userId = getUserId3(request);
|
|
2249
|
+
const { name, personality } = request.body;
|
|
2250
|
+
if (!name || !personality) {
|
|
2251
|
+
return reply.status(400).send({ success: false, message: "name and personality are required" });
|
|
2252
|
+
}
|
|
2253
|
+
const store = getAssistantStore();
|
|
2254
|
+
const existing = await store.getByOwner(tenantId, userId);
|
|
2255
|
+
if (existing) {
|
|
2256
|
+
return reply.status(409).send({ success: false, message: "You already have a personal assistant" });
|
|
2257
|
+
}
|
|
2258
|
+
const assistantId = randomUUID3();
|
|
2259
|
+
const projectStore = getProjectStore();
|
|
2260
|
+
const projectId = randomUUID3();
|
|
2261
|
+
const wsId = getWorkspaceId2(request);
|
|
2262
|
+
await projectStore.createProject(tenantId, wsId, projectId, {
|
|
2263
|
+
name: `${name}'s Space`,
|
|
2264
|
+
description: "Personal workspace for your assistant"
|
|
2265
|
+
});
|
|
2266
|
+
const config = PersonalAssistantConfig.get();
|
|
2267
|
+
config.key = assistantId;
|
|
2268
|
+
PersonalAssistantConfig.render(config, name, personality);
|
|
2269
|
+
const data = { name, graphDefinition: config, ownerUserId: userId };
|
|
2270
|
+
const assistant = await store.createAssistant(tenantId, assistantId, data);
|
|
2271
|
+
const meta = await getLinkMeta(userId, tenantId);
|
|
2272
|
+
meta.personalAssistantId = assistantId;
|
|
2273
|
+
meta.personalProjectId = projectId;
|
|
2274
|
+
meta.personalWorkspaceId = wsId;
|
|
2275
|
+
await updateLinkMeta(userId, tenantId, meta);
|
|
2276
|
+
return reply.status(201).send({
|
|
2277
|
+
success: true,
|
|
2278
|
+
message: "Personal assistant created",
|
|
2279
|
+
data: { id: assistant.id, name: assistant.name, projectId, workspaceId: wsId, createdAt: assistant.createdAt }
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
async function getPersonalAssistant(request, reply) {
|
|
2283
|
+
const tenantId = getTenantId7(request);
|
|
2284
|
+
const userId = getUserId3(request);
|
|
2285
|
+
const store = getAssistantStore();
|
|
2286
|
+
const assistant = await store.getByOwner(tenantId, userId);
|
|
2287
|
+
if (!assistant) {
|
|
2288
|
+
return reply.status(404).send({ success: false, message: "No personal assistant found" });
|
|
2289
|
+
}
|
|
2290
|
+
const meta = await getLinkMeta(userId, tenantId);
|
|
2291
|
+
const projectId = meta.personalProjectId || "default";
|
|
2292
|
+
const workspaceId = meta.personalWorkspaceId || "default";
|
|
2293
|
+
return {
|
|
2294
|
+
success: true,
|
|
2295
|
+
message: "Personal assistant found",
|
|
2296
|
+
data: { id: assistant.id, name: assistant.name, projectId, workspaceId, createdAt: assistant.createdAt }
|
|
2297
|
+
};
|
|
2298
|
+
}
|
|
2299
|
+
async function deletePersonalAssistant(request, reply) {
|
|
2300
|
+
const tenantId = getTenantId7(request);
|
|
2301
|
+
const userId = getUserId3(request);
|
|
2302
|
+
const store = getAssistantStore();
|
|
2303
|
+
const assistant = await store.getByOwner(tenantId, userId);
|
|
2304
|
+
if (!assistant) {
|
|
2305
|
+
return reply.status(404).send({ success: false, message: "No personal assistant found" });
|
|
2306
|
+
}
|
|
2307
|
+
const deleted = await store.deleteAssistant(tenantId, assistant.id);
|
|
2308
|
+
if (!deleted) {
|
|
2309
|
+
return reply.status(500).send({ success: false, message: "Failed to delete personal assistant" });
|
|
2310
|
+
}
|
|
2311
|
+
const threadStore = getStoreLattice5("default", "thread").store;
|
|
2312
|
+
try {
|
|
2313
|
+
const threads = await threadStore.getThreadsByAssistantId(tenantId, assistant.id);
|
|
2314
|
+
for (const t of threads) {
|
|
2315
|
+
await threadStore.deleteThread(tenantId, t.id);
|
|
2316
|
+
}
|
|
2317
|
+
} catch {
|
|
2318
|
+
}
|
|
2319
|
+
const meta = await getLinkMeta(userId, tenantId);
|
|
2320
|
+
const projectId = meta.personalProjectId;
|
|
2321
|
+
const wsId = meta.personalWorkspaceId;
|
|
2322
|
+
if (projectId && wsId) {
|
|
2323
|
+
try {
|
|
2324
|
+
await getProjectStore().deleteProject(tenantId, projectId);
|
|
2325
|
+
} catch {
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
delete meta.personalAssistantId;
|
|
2329
|
+
delete meta.personalProjectId;
|
|
2330
|
+
delete meta.personalWorkspaceId;
|
|
2331
|
+
await updateLinkMeta(userId, tenantId, meta);
|
|
2332
|
+
return { success: true, message: "Personal assistant deleted" };
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
// src/controllers/tasks.ts
|
|
2336
|
+
import { getStoreLattice as getStoreLattice6 } from "@axiom-lattice/core";
|
|
2337
|
+
function getTenantId8(request) {
|
|
2338
|
+
const userTenantId = request.user?.tenantId;
|
|
2339
|
+
if (userTenantId) return userTenantId;
|
|
2340
|
+
return request.headers["x-tenant-id"] || "default";
|
|
2341
|
+
}
|
|
2342
|
+
function getUserId4(request) {
|
|
2343
|
+
const userId = request.user?.id || request.headers["x-user-id"];
|
|
2344
|
+
if (!userId) throw new Error("User ID is required");
|
|
2345
|
+
return userId;
|
|
2346
|
+
}
|
|
2347
|
+
function getStore() {
|
|
2348
|
+
return getStoreLattice6("default", "task").store;
|
|
2349
|
+
}
|
|
2350
|
+
async function listTasks(request, reply) {
|
|
2351
|
+
try {
|
|
2352
|
+
const tenantId = getTenantId8(request);
|
|
2353
|
+
const userId = getUserId4(request);
|
|
2354
|
+
const query = request.query;
|
|
2355
|
+
const store = getStore();
|
|
2356
|
+
const tasks = await store.list({
|
|
2357
|
+
tenantId,
|
|
2358
|
+
ownerId: query.ownerId || userId,
|
|
2359
|
+
status: query.status,
|
|
2360
|
+
priority: query.priority,
|
|
2361
|
+
ownerType: query.ownerType,
|
|
2362
|
+
metadata: query.metadata ? JSON.parse(query.metadata) : void 0,
|
|
2363
|
+
limit: query.limit ? parseInt(query.limit) : void 0,
|
|
2364
|
+
offset: query.offset ? parseInt(query.offset) : void 0
|
|
2365
|
+
});
|
|
2366
|
+
return { success: true, data: tasks, count: tasks.length };
|
|
2367
|
+
} catch (error) {
|
|
2368
|
+
return { success: false, error: error.message };
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
async function getTask(request, reply) {
|
|
2372
|
+
try {
|
|
2373
|
+
const tenantId = getTenantId8(request);
|
|
2374
|
+
const userId = getUserId4(request);
|
|
2375
|
+
const { id } = request.params;
|
|
2376
|
+
const store = getStore();
|
|
2377
|
+
const task = await store.getById(tenantId, id);
|
|
2378
|
+
if (!task) {
|
|
2379
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
2380
|
+
}
|
|
2381
|
+
if (task.ownerType === "user" && task.ownerId !== userId) {
|
|
2382
|
+
return reply.status(403).send({ success: false, error: "Access denied" });
|
|
2383
|
+
}
|
|
2384
|
+
return { success: true, data: task };
|
|
2385
|
+
} catch (error) {
|
|
2386
|
+
return { success: false, error: error.message };
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
async function createTask(request, reply) {
|
|
2390
|
+
try {
|
|
2391
|
+
const tenantId = getTenantId8(request);
|
|
2392
|
+
const userId = getUserId4(request);
|
|
2393
|
+
const body = request.body;
|
|
2394
|
+
if (!body.title) {
|
|
2395
|
+
return reply.status(400).send({ success: false, error: "title is required" });
|
|
2396
|
+
}
|
|
2397
|
+
const store = getStore();
|
|
2398
|
+
const task = await store.create({
|
|
2399
|
+
...body,
|
|
2400
|
+
tenantId,
|
|
2401
|
+
ownerType: body.ownerType || "user",
|
|
2402
|
+
ownerId: body.ownerId || userId
|
|
2403
|
+
});
|
|
2404
|
+
return reply.status(201).send({ success: true, data: task });
|
|
2405
|
+
} catch (error) {
|
|
2406
|
+
return reply.status(500).send({ success: false, error: error.message });
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
async function updateTask(request, reply) {
|
|
2410
|
+
try {
|
|
2411
|
+
const tenantId = getTenantId8(request);
|
|
2412
|
+
const userId = getUserId4(request);
|
|
2413
|
+
const { id } = request.params;
|
|
2414
|
+
const store = getStore();
|
|
2415
|
+
const existing = await store.getById(tenantId, id);
|
|
2416
|
+
if (!existing) {
|
|
2417
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
2418
|
+
}
|
|
2419
|
+
if (existing.ownerType === "user" && existing.ownerId !== userId) {
|
|
2420
|
+
return reply.status(403).send({ success: false, error: "Access denied" });
|
|
2421
|
+
}
|
|
2422
|
+
const task = await store.update(tenantId, id, request.body);
|
|
2423
|
+
if (!task) {
|
|
2424
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
2425
|
+
}
|
|
2426
|
+
return { success: true, data: task };
|
|
2427
|
+
} catch (error) {
|
|
2428
|
+
return reply.status(500).send({ success: false, error: error.message });
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
async function deleteTask(request, reply) {
|
|
2432
|
+
try {
|
|
2433
|
+
const tenantId = getTenantId8(request);
|
|
2434
|
+
const userId = getUserId4(request);
|
|
2435
|
+
const { id } = request.params;
|
|
2436
|
+
const store = getStore();
|
|
2437
|
+
const existing = await store.getById(tenantId, id);
|
|
2438
|
+
if (!existing) {
|
|
2439
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
2440
|
+
}
|
|
2441
|
+
if (existing.ownerType === "user" && existing.ownerId !== userId) {
|
|
2442
|
+
return reply.status(403).send({ success: false, error: "Access denied" });
|
|
2443
|
+
}
|
|
2444
|
+
const deleted = await store.delete(tenantId, id);
|
|
2445
|
+
if (!deleted) {
|
|
2446
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
2447
|
+
}
|
|
2448
|
+
return { success: true, message: "Task deleted" };
|
|
2449
|
+
} catch (error) {
|
|
2450
|
+
return reply.status(500).send({ success: false, error: error.message });
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
async function completeTask(request, reply) {
|
|
2454
|
+
try {
|
|
2455
|
+
const tenantId = getTenantId8(request);
|
|
2456
|
+
const userId = getUserId4(request);
|
|
2457
|
+
const { id } = request.params;
|
|
2458
|
+
const store = getStore();
|
|
2459
|
+
const existing = await store.getById(tenantId, id);
|
|
2460
|
+
if (!existing) {
|
|
2461
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
2462
|
+
}
|
|
2463
|
+
if (existing.ownerType === "user" && existing.ownerId !== userId) {
|
|
2464
|
+
return reply.status(403).send({ success: false, error: "Access denied" });
|
|
2465
|
+
}
|
|
2466
|
+
const task = await store.update(tenantId, id, { status: "completed" });
|
|
2467
|
+
if (!task) {
|
|
2468
|
+
return reply.status(404).send({ success: false, error: "Task not found" });
|
|
2469
|
+
}
|
|
2470
|
+
return { success: true, data: task };
|
|
2471
|
+
} catch (error) {
|
|
2472
|
+
return reply.status(500).send({ success: false, error: error.message });
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2170
2476
|
// src/schemas/data-query.ts
|
|
2171
2477
|
var dataQuerySchema = {
|
|
2172
2478
|
description: "Execute data query (semantic or SQL)",
|
|
@@ -2731,9 +3037,9 @@ var SandboxService = class {
|
|
|
2731
3037
|
);
|
|
2732
3038
|
return rewritten;
|
|
2733
3039
|
}
|
|
2734
|
-
generateErrorHtml(assistantId, threadId, vmIsolation,
|
|
2735
|
-
const encodedError = encodeURIComponent(
|
|
2736
|
-
return ERROR_HTML.replace("{assistantId}", assistantId).replace("{threadId}", threadId).replace("{vmIsolation}", vmIsolation).replace("{errorMessage}",
|
|
3040
|
+
generateErrorHtml(assistantId, threadId, vmIsolation, errorMessage2) {
|
|
3041
|
+
const encodedError = encodeURIComponent(errorMessage2);
|
|
3042
|
+
return ERROR_HTML.replace("{assistantId}", assistantId).replace("{threadId}", threadId).replace("{vmIsolation}", vmIsolation).replace("{errorMessage}", errorMessage2);
|
|
2737
3043
|
}
|
|
2738
3044
|
};
|
|
2739
3045
|
var sandboxService = new SandboxService();
|
|
@@ -2859,14 +3165,14 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2859
3165
|
// src/controllers/workspace.ts
|
|
2860
3166
|
import * as fs from "fs/promises";
|
|
2861
3167
|
import * as path from "path";
|
|
2862
|
-
import { getStoreLattice as
|
|
3168
|
+
import { getStoreLattice as getStoreLattice7 } from "@axiom-lattice/core";
|
|
2863
3169
|
import { SandboxFilesystem, FilesystemBackend } from "@axiom-lattice/core";
|
|
2864
3170
|
import { getSandBoxManager as getSandBoxManager3 } from "@axiom-lattice/core";
|
|
2865
3171
|
import { v4 as uuidv4 } from "uuid";
|
|
2866
3172
|
var WorkspaceController = class {
|
|
2867
3173
|
constructor() {
|
|
2868
|
-
this.workspaceStore =
|
|
2869
|
-
this.projectStore =
|
|
3174
|
+
this.workspaceStore = getStoreLattice7("default", "workspace").store;
|
|
3175
|
+
this.projectStore = getStoreLattice7("default", "project").store;
|
|
2870
3176
|
}
|
|
2871
3177
|
getTenantId(request) {
|
|
2872
3178
|
const userTenantId = request.user?.tenantId;
|
|
@@ -2998,6 +3304,7 @@ var WorkspaceController = class {
|
|
|
2998
3304
|
if (!workspace) {
|
|
2999
3305
|
throw new Error("Workspace not found");
|
|
3000
3306
|
}
|
|
3307
|
+
console.log(`[getBackend] storageType=${workspace.storageType} filePath=${filePath}`);
|
|
3001
3308
|
if (workspace.storageType === "sandbox") {
|
|
3002
3309
|
const sandboxManager = getSandBoxManager3();
|
|
3003
3310
|
const volumeConfig = {
|
|
@@ -3007,11 +3314,15 @@ var WorkspaceController = class {
|
|
|
3007
3314
|
workspaceId,
|
|
3008
3315
|
projectId
|
|
3009
3316
|
};
|
|
3317
|
+
console.log(`[getBackend] trying volume backend for path=${filePath} assistant_id=${assistantId}`);
|
|
3010
3318
|
const volumeBackend = await sandboxManager.getVolumeBackendForPath(volumeConfig, filePath || "/project");
|
|
3011
3319
|
if (volumeBackend) {
|
|
3320
|
+
console.log(`[getBackend] using VolumeFilesystem`);
|
|
3012
3321
|
return { backend: volumeBackend, workspace };
|
|
3013
3322
|
}
|
|
3323
|
+
console.log(`[getBackend] volume not found, falling back to SandboxFilesystem`);
|
|
3014
3324
|
const sandbox = await sandboxManager.getSandboxFromConfig(volumeConfig);
|
|
3325
|
+
console.log(`[getBackend] sandbox acquired, name=${sandbox.name || "unknown"}`);
|
|
3015
3326
|
return {
|
|
3016
3327
|
backend: new SandboxFilesystem({
|
|
3017
3328
|
sandboxInstance: sandbox
|
|
@@ -3019,6 +3330,7 @@ var WorkspaceController = class {
|
|
|
3019
3330
|
workspace
|
|
3020
3331
|
};
|
|
3021
3332
|
} else {
|
|
3333
|
+
console.log(`[getBackend] using FilesystemBackend rootDir=/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`);
|
|
3022
3334
|
return {
|
|
3023
3335
|
backend: new FilesystemBackend({
|
|
3024
3336
|
rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
|
|
@@ -3235,8 +3547,11 @@ var WorkspaceController = class {
|
|
|
3235
3547
|
const { workspaceId, projectId } = request.params;
|
|
3236
3548
|
const path3 = request.query.path || "/";
|
|
3237
3549
|
const assistantId = request.query.assistantId;
|
|
3550
|
+
console.log(`[listPath] tenantId=${tenantId} workspaceId=${workspaceId} projectId=${projectId} path=${path3} assistantId=${assistantId}`);
|
|
3238
3551
|
const { backend } = await this.getBackend(tenantId, workspaceId, projectId, assistantId, path3);
|
|
3552
|
+
console.log(`[listPath] backend type=${backend.constructor.name} calling lsInfo(${path3})`);
|
|
3239
3553
|
const files = await backend.lsInfo(path3);
|
|
3554
|
+
console.log(`[listPath] result count=${files.length}`);
|
|
3240
3555
|
return { success: true, data: files };
|
|
3241
3556
|
}
|
|
3242
3557
|
async readFile(request) {
|
|
@@ -3391,11 +3706,11 @@ function registerWorkspaceRoutes(app2) {
|
|
|
3391
3706
|
|
|
3392
3707
|
// src/controllers/database-configs.ts
|
|
3393
3708
|
import {
|
|
3394
|
-
getStoreLattice as
|
|
3709
|
+
getStoreLattice as getStoreLattice8,
|
|
3395
3710
|
sqlDatabaseManager
|
|
3396
3711
|
} from "@axiom-lattice/core";
|
|
3397
|
-
import { randomUUID as
|
|
3398
|
-
function
|
|
3712
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
3713
|
+
function getTenantId9(request) {
|
|
3399
3714
|
const userTenantId = request.user?.tenantId;
|
|
3400
3715
|
if (userTenantId) {
|
|
3401
3716
|
return userTenantId;
|
|
@@ -3403,9 +3718,9 @@ function getTenantId7(request) {
|
|
|
3403
3718
|
return request.headers["x-tenant-id"] || "default";
|
|
3404
3719
|
}
|
|
3405
3720
|
async function getDatabaseConfigList(request, reply) {
|
|
3406
|
-
const tenantId =
|
|
3721
|
+
const tenantId = getTenantId9(request);
|
|
3407
3722
|
try {
|
|
3408
|
-
const storeLattice =
|
|
3723
|
+
const storeLattice = getStoreLattice8("default", "database");
|
|
3409
3724
|
const store = storeLattice.store;
|
|
3410
3725
|
const configs = await store.getAllConfigs(tenantId);
|
|
3411
3726
|
console.log("Backend: getAllConfigs returned:", configs);
|
|
@@ -3433,10 +3748,10 @@ async function getDatabaseConfigList(request, reply) {
|
|
|
3433
3748
|
}
|
|
3434
3749
|
}
|
|
3435
3750
|
async function getDatabaseConfig(request, reply) {
|
|
3436
|
-
const tenantId =
|
|
3751
|
+
const tenantId = getTenantId9(request);
|
|
3437
3752
|
const { key } = request.params;
|
|
3438
3753
|
try {
|
|
3439
|
-
const storeLattice =
|
|
3754
|
+
const storeLattice = getStoreLattice8("default", "database");
|
|
3440
3755
|
const store = storeLattice.store;
|
|
3441
3756
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3442
3757
|
if (!config) {
|
|
@@ -3459,10 +3774,10 @@ async function getDatabaseConfig(request, reply) {
|
|
|
3459
3774
|
}
|
|
3460
3775
|
}
|
|
3461
3776
|
async function createDatabaseConfig(request, reply) {
|
|
3462
|
-
const tenantId =
|
|
3777
|
+
const tenantId = getTenantId9(request);
|
|
3463
3778
|
const body = request.body;
|
|
3464
3779
|
try {
|
|
3465
|
-
const storeLattice =
|
|
3780
|
+
const storeLattice = getStoreLattice8("default", "database");
|
|
3466
3781
|
const store = storeLattice.store;
|
|
3467
3782
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3468
3783
|
if (existing) {
|
|
@@ -3472,7 +3787,7 @@ async function createDatabaseConfig(request, reply) {
|
|
|
3472
3787
|
message: "Database configuration with this key already exists"
|
|
3473
3788
|
};
|
|
3474
3789
|
}
|
|
3475
|
-
const id = body.id ||
|
|
3790
|
+
const id = body.id || randomUUID4();
|
|
3476
3791
|
const config = await store.createConfig(tenantId, id, body);
|
|
3477
3792
|
try {
|
|
3478
3793
|
sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
|
|
@@ -3494,11 +3809,11 @@ async function createDatabaseConfig(request, reply) {
|
|
|
3494
3809
|
}
|
|
3495
3810
|
}
|
|
3496
3811
|
async function updateDatabaseConfig(request, reply) {
|
|
3497
|
-
const tenantId =
|
|
3812
|
+
const tenantId = getTenantId9(request);
|
|
3498
3813
|
const { key } = request.params;
|
|
3499
3814
|
const updates = request.body;
|
|
3500
3815
|
try {
|
|
3501
|
-
const storeLattice =
|
|
3816
|
+
const storeLattice = getStoreLattice8("default", "database");
|
|
3502
3817
|
const store = storeLattice.store;
|
|
3503
3818
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3504
3819
|
if (!existing) {
|
|
@@ -3536,10 +3851,10 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
3536
3851
|
}
|
|
3537
3852
|
}
|
|
3538
3853
|
async function deleteDatabaseConfig(request, reply) {
|
|
3539
|
-
const tenantId =
|
|
3854
|
+
const tenantId = getTenantId9(request);
|
|
3540
3855
|
const { keyOrId } = request.params;
|
|
3541
3856
|
try {
|
|
3542
|
-
const storeLattice =
|
|
3857
|
+
const storeLattice = getStoreLattice8("default", "database");
|
|
3543
3858
|
const store = storeLattice.store;
|
|
3544
3859
|
console.log("Delete request - keyOrId:", keyOrId);
|
|
3545
3860
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
@@ -3585,10 +3900,10 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
3585
3900
|
}
|
|
3586
3901
|
}
|
|
3587
3902
|
async function testDatabaseConnection(request, reply) {
|
|
3588
|
-
const tenantId =
|
|
3903
|
+
const tenantId = getTenantId9(request);
|
|
3589
3904
|
const { key } = request.params;
|
|
3590
3905
|
try {
|
|
3591
|
-
const storeLattice =
|
|
3906
|
+
const storeLattice = getStoreLattice8("default", "database");
|
|
3592
3907
|
const store = storeLattice.store;
|
|
3593
3908
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3594
3909
|
if (!config) {
|
|
@@ -3673,12 +3988,12 @@ function registerDatabaseConfigRoutes(app2) {
|
|
|
3673
3988
|
|
|
3674
3989
|
// src/controllers/metrics-configs.ts
|
|
3675
3990
|
import {
|
|
3676
|
-
getStoreLattice as
|
|
3991
|
+
getStoreLattice as getStoreLattice9,
|
|
3677
3992
|
metricsServerManager as metricsServerManager2,
|
|
3678
3993
|
SemanticMetricsClient as SemanticMetricsClient2
|
|
3679
3994
|
} from "@axiom-lattice/core";
|
|
3680
|
-
import { randomUUID as
|
|
3681
|
-
function
|
|
3995
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
3996
|
+
function getTenantId10(request) {
|
|
3682
3997
|
const userTenantId = request.user?.tenantId;
|
|
3683
3998
|
if (userTenantId) {
|
|
3684
3999
|
return userTenantId;
|
|
@@ -3686,9 +4001,9 @@ function getTenantId8(request) {
|
|
|
3686
4001
|
return request.headers["x-tenant-id"] || "default";
|
|
3687
4002
|
}
|
|
3688
4003
|
async function getMetricsServerConfigList(request, reply) {
|
|
3689
|
-
const tenantId =
|
|
4004
|
+
const tenantId = getTenantId10(request);
|
|
3690
4005
|
try {
|
|
3691
|
-
const storeLattice =
|
|
4006
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
3692
4007
|
const store = storeLattice.store;
|
|
3693
4008
|
const configs = await store.getAllConfigs(tenantId);
|
|
3694
4009
|
return {
|
|
@@ -3712,10 +4027,10 @@ async function getMetricsServerConfigList(request, reply) {
|
|
|
3712
4027
|
}
|
|
3713
4028
|
}
|
|
3714
4029
|
async function getMetricsServerConfig(request, reply) {
|
|
3715
|
-
const tenantId =
|
|
4030
|
+
const tenantId = getTenantId10(request);
|
|
3716
4031
|
const { key } = request.params;
|
|
3717
4032
|
try {
|
|
3718
|
-
const storeLattice =
|
|
4033
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
3719
4034
|
const store = storeLattice.store;
|
|
3720
4035
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3721
4036
|
if (!config) {
|
|
@@ -3738,10 +4053,10 @@ async function getMetricsServerConfig(request, reply) {
|
|
|
3738
4053
|
}
|
|
3739
4054
|
}
|
|
3740
4055
|
async function createMetricsServerConfig(request, reply) {
|
|
3741
|
-
const tenantId =
|
|
4056
|
+
const tenantId = getTenantId10(request);
|
|
3742
4057
|
const body = request.body;
|
|
3743
4058
|
try {
|
|
3744
|
-
const storeLattice =
|
|
4059
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
3745
4060
|
const store = storeLattice.store;
|
|
3746
4061
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3747
4062
|
if (existing) {
|
|
@@ -3758,7 +4073,7 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
3758
4073
|
message: "selectedDataSources is required for semantic metrics servers"
|
|
3759
4074
|
};
|
|
3760
4075
|
}
|
|
3761
|
-
const id = body.id ||
|
|
4076
|
+
const id = body.id || randomUUID5();
|
|
3762
4077
|
const configData = {
|
|
3763
4078
|
key: body.key,
|
|
3764
4079
|
name: body.name,
|
|
@@ -3789,11 +4104,11 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
3789
4104
|
}
|
|
3790
4105
|
}
|
|
3791
4106
|
async function updateMetricsServerConfig(request, reply) {
|
|
3792
|
-
const tenantId =
|
|
4107
|
+
const tenantId = getTenantId10(request);
|
|
3793
4108
|
const { key } = request.params;
|
|
3794
4109
|
const updates = request.body;
|
|
3795
4110
|
try {
|
|
3796
|
-
const storeLattice =
|
|
4111
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
3797
4112
|
const store = storeLattice.store;
|
|
3798
4113
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3799
4114
|
if (!existing) {
|
|
@@ -3840,10 +4155,10 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
3840
4155
|
}
|
|
3841
4156
|
}
|
|
3842
4157
|
async function deleteMetricsServerConfig(request, reply) {
|
|
3843
|
-
const tenantId =
|
|
4158
|
+
const tenantId = getTenantId10(request);
|
|
3844
4159
|
const { keyOrId } = request.params;
|
|
3845
4160
|
try {
|
|
3846
|
-
const storeLattice =
|
|
4161
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
3847
4162
|
const store = storeLattice.store;
|
|
3848
4163
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
3849
4164
|
let configKey = keyOrId;
|
|
@@ -3887,10 +4202,10 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
3887
4202
|
}
|
|
3888
4203
|
}
|
|
3889
4204
|
async function testMetricsServerConnection(request, reply) {
|
|
3890
|
-
const tenantId =
|
|
4205
|
+
const tenantId = getTenantId10(request);
|
|
3891
4206
|
const { key } = request.params;
|
|
3892
4207
|
try {
|
|
3893
|
-
const storeLattice =
|
|
4208
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
3894
4209
|
const store = storeLattice.store;
|
|
3895
4210
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3896
4211
|
if (!config) {
|
|
@@ -3938,10 +4253,10 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3938
4253
|
}
|
|
3939
4254
|
}
|
|
3940
4255
|
async function listAvailableMetrics(request, reply) {
|
|
3941
|
-
const tenantId =
|
|
4256
|
+
const tenantId = getTenantId10(request);
|
|
3942
4257
|
const { key } = request.params;
|
|
3943
4258
|
try {
|
|
3944
|
-
const storeLattice =
|
|
4259
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
3945
4260
|
const store = storeLattice.store;
|
|
3946
4261
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3947
4262
|
if (!config) {
|
|
@@ -3976,11 +4291,11 @@ async function listAvailableMetrics(request, reply) {
|
|
|
3976
4291
|
}
|
|
3977
4292
|
}
|
|
3978
4293
|
async function queryMetricsData(request, reply) {
|
|
3979
|
-
const tenantId =
|
|
4294
|
+
const tenantId = getTenantId10(request);
|
|
3980
4295
|
const { key } = request.params;
|
|
3981
4296
|
const { metricName, startTime, endTime, step, labels } = request.body;
|
|
3982
4297
|
try {
|
|
3983
|
-
const storeLattice =
|
|
4298
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
3984
4299
|
const store = storeLattice.store;
|
|
3985
4300
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3986
4301
|
if (!config) {
|
|
@@ -4024,10 +4339,10 @@ async function queryMetricsData(request, reply) {
|
|
|
4024
4339
|
}
|
|
4025
4340
|
}
|
|
4026
4341
|
async function getDataSources(request, reply) {
|
|
4027
|
-
const tenantId =
|
|
4342
|
+
const tenantId = getTenantId10(request);
|
|
4028
4343
|
const { key } = request.params;
|
|
4029
4344
|
try {
|
|
4030
|
-
const storeLattice =
|
|
4345
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
4031
4346
|
const store = storeLattice.store;
|
|
4032
4347
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4033
4348
|
if (!config) {
|
|
@@ -4065,10 +4380,10 @@ async function getDataSources(request, reply) {
|
|
|
4065
4380
|
}
|
|
4066
4381
|
}
|
|
4067
4382
|
async function getDatasourceMetrics(request, reply) {
|
|
4068
|
-
const tenantId =
|
|
4383
|
+
const tenantId = getTenantId10(request);
|
|
4069
4384
|
const { key, datasourceId } = request.params;
|
|
4070
4385
|
try {
|
|
4071
|
-
const storeLattice =
|
|
4386
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
4072
4387
|
const store = storeLattice.store;
|
|
4073
4388
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4074
4389
|
if (!config) {
|
|
@@ -4102,11 +4417,11 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
4102
4417
|
}
|
|
4103
4418
|
}
|
|
4104
4419
|
async function querySemanticMetrics(request, reply) {
|
|
4105
|
-
const tenantId =
|
|
4420
|
+
const tenantId = getTenantId10(request);
|
|
4106
4421
|
const { key } = request.params;
|
|
4107
4422
|
const body = request.body;
|
|
4108
4423
|
try {
|
|
4109
|
-
const storeLattice =
|
|
4424
|
+
const storeLattice = getStoreLattice9("default", "metrics");
|
|
4110
4425
|
const store = storeLattice.store;
|
|
4111
4426
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4112
4427
|
if (!config) {
|
|
@@ -4260,12 +4575,12 @@ function registerMetricsServerConfigRoutes(app2) {
|
|
|
4260
4575
|
|
|
4261
4576
|
// src/controllers/mcp-configs.ts
|
|
4262
4577
|
import {
|
|
4263
|
-
getStoreLattice as
|
|
4578
|
+
getStoreLattice as getStoreLattice10,
|
|
4264
4579
|
mcpManager,
|
|
4265
4580
|
toolLatticeManager as toolLatticeManager2
|
|
4266
4581
|
} from "@axiom-lattice/core";
|
|
4267
|
-
import { randomUUID as
|
|
4268
|
-
function
|
|
4582
|
+
import { randomUUID as randomUUID6 } from "crypto";
|
|
4583
|
+
function getTenantId11(request) {
|
|
4269
4584
|
const userTenantId = request.user?.tenantId;
|
|
4270
4585
|
if (userTenantId) {
|
|
4271
4586
|
return userTenantId;
|
|
@@ -4273,9 +4588,9 @@ function getTenantId9(request) {
|
|
|
4273
4588
|
return request.headers["x-tenant-id"] || "default";
|
|
4274
4589
|
}
|
|
4275
4590
|
async function getMcpServerConfigList(request, reply) {
|
|
4276
|
-
const tenantId =
|
|
4591
|
+
const tenantId = getTenantId11(request);
|
|
4277
4592
|
try {
|
|
4278
|
-
const storeLattice =
|
|
4593
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4279
4594
|
const store = storeLattice.store;
|
|
4280
4595
|
const configs = await store.getAllConfigs(tenantId);
|
|
4281
4596
|
return {
|
|
@@ -4299,10 +4614,10 @@ async function getMcpServerConfigList(request, reply) {
|
|
|
4299
4614
|
}
|
|
4300
4615
|
}
|
|
4301
4616
|
async function getMcpServerConfig(request, reply) {
|
|
4302
|
-
const tenantId =
|
|
4617
|
+
const tenantId = getTenantId11(request);
|
|
4303
4618
|
const { key } = request.params;
|
|
4304
4619
|
try {
|
|
4305
|
-
const storeLattice =
|
|
4620
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4306
4621
|
const store = storeLattice.store;
|
|
4307
4622
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4308
4623
|
if (!config) {
|
|
@@ -4325,10 +4640,10 @@ async function getMcpServerConfig(request, reply) {
|
|
|
4325
4640
|
}
|
|
4326
4641
|
}
|
|
4327
4642
|
async function createMcpServerConfig(request, reply) {
|
|
4328
|
-
const tenantId =
|
|
4643
|
+
const tenantId = getTenantId11(request);
|
|
4329
4644
|
const body = request.body;
|
|
4330
4645
|
try {
|
|
4331
|
-
const storeLattice =
|
|
4646
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4332
4647
|
const store = storeLattice.store;
|
|
4333
4648
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
4334
4649
|
if (existing) {
|
|
@@ -4338,7 +4653,7 @@ async function createMcpServerConfig(request, reply) {
|
|
|
4338
4653
|
message: "MCP server configuration with this key already exists"
|
|
4339
4654
|
};
|
|
4340
4655
|
}
|
|
4341
|
-
const id = body.id ||
|
|
4656
|
+
const id = body.id || randomUUID6();
|
|
4342
4657
|
const config = await store.createConfig(tenantId, id, body);
|
|
4343
4658
|
try {
|
|
4344
4659
|
await connectAndRegisterTools(config);
|
|
@@ -4364,11 +4679,11 @@ async function createMcpServerConfig(request, reply) {
|
|
|
4364
4679
|
}
|
|
4365
4680
|
}
|
|
4366
4681
|
async function updateMcpServerConfig(request, reply) {
|
|
4367
|
-
const tenantId =
|
|
4682
|
+
const tenantId = getTenantId11(request);
|
|
4368
4683
|
const { key } = request.params;
|
|
4369
4684
|
const updates = request.body;
|
|
4370
4685
|
try {
|
|
4371
|
-
const storeLattice =
|
|
4686
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4372
4687
|
const store = storeLattice.store;
|
|
4373
4688
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
4374
4689
|
if (!existing) {
|
|
@@ -4414,10 +4729,10 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
4414
4729
|
}
|
|
4415
4730
|
}
|
|
4416
4731
|
async function deleteMcpServerConfig(request, reply) {
|
|
4417
|
-
const tenantId =
|
|
4732
|
+
const tenantId = getTenantId11(request);
|
|
4418
4733
|
const { keyOrId } = request.params;
|
|
4419
4734
|
try {
|
|
4420
|
-
const storeLattice =
|
|
4735
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4421
4736
|
const store = storeLattice.store;
|
|
4422
4737
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
4423
4738
|
let configKey = keyOrId;
|
|
@@ -4461,10 +4776,10 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
4461
4776
|
}
|
|
4462
4777
|
}
|
|
4463
4778
|
async function testMcpServerConnection(request, reply) {
|
|
4464
|
-
const tenantId =
|
|
4779
|
+
const tenantId = getTenantId11(request);
|
|
4465
4780
|
const { key } = request.params;
|
|
4466
4781
|
try {
|
|
4467
|
-
const storeLattice =
|
|
4782
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4468
4783
|
const store = storeLattice.store;
|
|
4469
4784
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4470
4785
|
if (!config) {
|
|
@@ -4514,10 +4829,10 @@ async function testMcpServerConnection(request, reply) {
|
|
|
4514
4829
|
}
|
|
4515
4830
|
}
|
|
4516
4831
|
async function listMcpServerTools(request, reply) {
|
|
4517
|
-
const tenantId =
|
|
4832
|
+
const tenantId = getTenantId11(request);
|
|
4518
4833
|
const { key } = request.params;
|
|
4519
4834
|
try {
|
|
4520
|
-
const storeLattice =
|
|
4835
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4521
4836
|
const store = storeLattice.store;
|
|
4522
4837
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4523
4838
|
if (!config) {
|
|
@@ -4547,10 +4862,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
4547
4862
|
}
|
|
4548
4863
|
}
|
|
4549
4864
|
async function connectMcpServer(request, reply) {
|
|
4550
|
-
const tenantId =
|
|
4865
|
+
const tenantId = getTenantId11(request);
|
|
4551
4866
|
const { key } = request.params;
|
|
4552
4867
|
try {
|
|
4553
|
-
const storeLattice =
|
|
4868
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4554
4869
|
const store = storeLattice.store;
|
|
4555
4870
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4556
4871
|
if (!config) {
|
|
@@ -4571,7 +4886,7 @@ async function connectMcpServer(request, reply) {
|
|
|
4571
4886
|
};
|
|
4572
4887
|
} catch (error) {
|
|
4573
4888
|
console.error("Failed to connect MCP server:", error);
|
|
4574
|
-
const storeLattice =
|
|
4889
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4575
4890
|
const store = storeLattice.store;
|
|
4576
4891
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4577
4892
|
if (config) {
|
|
@@ -4584,10 +4899,10 @@ async function connectMcpServer(request, reply) {
|
|
|
4584
4899
|
}
|
|
4585
4900
|
}
|
|
4586
4901
|
async function disconnectMcpServer(request, reply) {
|
|
4587
|
-
const tenantId =
|
|
4902
|
+
const tenantId = getTenantId11(request);
|
|
4588
4903
|
const { key } = request.params;
|
|
4589
4904
|
try {
|
|
4590
|
-
const storeLattice =
|
|
4905
|
+
const storeLattice = getStoreLattice10("default", "mcp");
|
|
4591
4906
|
const store = storeLattice.store;
|
|
4592
4907
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4593
4908
|
if (!config) {
|
|
@@ -4692,12 +5007,12 @@ function registerMcpServerConfigRoutes(app2) {
|
|
|
4692
5007
|
}
|
|
4693
5008
|
|
|
4694
5009
|
// src/controllers/eval.ts
|
|
4695
|
-
import { getStoreLattice as
|
|
5010
|
+
import { getStoreLattice as getStoreLattice12 } from "@axiom-lattice/core";
|
|
4696
5011
|
import { v4 as uuidv43 } from "uuid";
|
|
4697
5012
|
|
|
4698
5013
|
// src/services/eval-runner.ts
|
|
4699
5014
|
import { EventEmitter } from "events";
|
|
4700
|
-
import { getStoreLattice as
|
|
5015
|
+
import { getStoreLattice as getStoreLattice11, modelLatticeManager as modelLatticeManager2 } from "@axiom-lattice/core";
|
|
4701
5016
|
import { LatticeEvalProject } from "@axiom-lattice/agent-eval";
|
|
4702
5017
|
import { v4 as uuidv42 } from "uuid";
|
|
4703
5018
|
function mapLogs(logs) {
|
|
@@ -4870,13 +5185,13 @@ var EvalRunner = class {
|
|
|
4870
5185
|
return this.runs.has(runId);
|
|
4871
5186
|
}
|
|
4872
5187
|
getEvalStore() {
|
|
4873
|
-
return
|
|
5188
|
+
return getStoreLattice11("default", "eval").store;
|
|
4874
5189
|
}
|
|
4875
5190
|
};
|
|
4876
5191
|
var evalRunner = new EvalRunner();
|
|
4877
5192
|
|
|
4878
5193
|
// src/controllers/eval.ts
|
|
4879
|
-
function
|
|
5194
|
+
function getTenantId12(request) {
|
|
4880
5195
|
const userTenantId = request.user?.tenantId;
|
|
4881
5196
|
if (userTenantId) {
|
|
4882
5197
|
return userTenantId;
|
|
@@ -4884,11 +5199,11 @@ function getTenantId10(request) {
|
|
|
4884
5199
|
return request.headers["x-tenant-id"] || "default";
|
|
4885
5200
|
}
|
|
4886
5201
|
function getEvalStore() {
|
|
4887
|
-
return
|
|
5202
|
+
return getStoreLattice12("default", "eval").store;
|
|
4888
5203
|
}
|
|
4889
5204
|
async function createProject(request, reply) {
|
|
4890
5205
|
try {
|
|
4891
|
-
const tenantId =
|
|
5206
|
+
const tenantId = getTenantId12(request);
|
|
4892
5207
|
const store = getEvalStore();
|
|
4893
5208
|
const id = uuidv43();
|
|
4894
5209
|
const data = request.body;
|
|
@@ -4913,7 +5228,7 @@ async function createProject(request, reply) {
|
|
|
4913
5228
|
}
|
|
4914
5229
|
async function listProjects(request, reply) {
|
|
4915
5230
|
try {
|
|
4916
|
-
const tenantId =
|
|
5231
|
+
const tenantId = getTenantId12(request);
|
|
4917
5232
|
const store = getEvalStore();
|
|
4918
5233
|
let projects = await store.getProjectsByTenant(tenantId);
|
|
4919
5234
|
if (projects.length === 0) {
|
|
@@ -4947,7 +5262,7 @@ async function listProjects(request, reply) {
|
|
|
4947
5262
|
}
|
|
4948
5263
|
async function getProject(request, reply) {
|
|
4949
5264
|
try {
|
|
4950
|
-
const tenantId =
|
|
5265
|
+
const tenantId = getTenantId12(request);
|
|
4951
5266
|
const store = getEvalStore();
|
|
4952
5267
|
const { pid } = request.params;
|
|
4953
5268
|
const project = await store.getProjectById(tenantId, pid);
|
|
@@ -4967,7 +5282,7 @@ async function getProject(request, reply) {
|
|
|
4967
5282
|
}
|
|
4968
5283
|
async function updateProject(request, reply) {
|
|
4969
5284
|
try {
|
|
4970
|
-
const tenantId =
|
|
5285
|
+
const tenantId = getTenantId12(request);
|
|
4971
5286
|
const store = getEvalStore();
|
|
4972
5287
|
const { pid } = request.params;
|
|
4973
5288
|
const existing = await store.getProjectById(tenantId, pid);
|
|
@@ -4987,7 +5302,7 @@ async function updateProject(request, reply) {
|
|
|
4987
5302
|
}
|
|
4988
5303
|
async function deleteProject(request, reply) {
|
|
4989
5304
|
try {
|
|
4990
|
-
const tenantId =
|
|
5305
|
+
const tenantId = getTenantId12(request);
|
|
4991
5306
|
const store = getEvalStore();
|
|
4992
5307
|
const { pid } = request.params;
|
|
4993
5308
|
const existing = await store.getProjectById(tenantId, pid);
|
|
@@ -5006,7 +5321,7 @@ async function deleteProject(request, reply) {
|
|
|
5006
5321
|
}
|
|
5007
5322
|
async function createSuite(request, reply) {
|
|
5008
5323
|
try {
|
|
5009
|
-
const tenantId =
|
|
5324
|
+
const tenantId = getTenantId12(request);
|
|
5010
5325
|
const store = getEvalStore();
|
|
5011
5326
|
const { pid } = request.params;
|
|
5012
5327
|
const project = await store.getProjectById(tenantId, pid);
|
|
@@ -5028,7 +5343,7 @@ async function createSuite(request, reply) {
|
|
|
5028
5343
|
}
|
|
5029
5344
|
async function updateSuite(request, reply) {
|
|
5030
5345
|
try {
|
|
5031
|
-
const tenantId =
|
|
5346
|
+
const tenantId = getTenantId12(request);
|
|
5032
5347
|
const store = getEvalStore();
|
|
5033
5348
|
const { sid } = request.params;
|
|
5034
5349
|
const existing = await store.getSuiteById(tenantId, sid);
|
|
@@ -5048,7 +5363,7 @@ async function updateSuite(request, reply) {
|
|
|
5048
5363
|
}
|
|
5049
5364
|
async function deleteSuite(request, reply) {
|
|
5050
5365
|
try {
|
|
5051
|
-
const tenantId =
|
|
5366
|
+
const tenantId = getTenantId12(request);
|
|
5052
5367
|
const store = getEvalStore();
|
|
5053
5368
|
const { sid } = request.params;
|
|
5054
5369
|
const existing = await store.getSuiteById(tenantId, sid);
|
|
@@ -5067,7 +5382,7 @@ async function deleteSuite(request, reply) {
|
|
|
5067
5382
|
}
|
|
5068
5383
|
async function createCase(request, reply) {
|
|
5069
5384
|
try {
|
|
5070
|
-
const tenantId =
|
|
5385
|
+
const tenantId = getTenantId12(request);
|
|
5071
5386
|
const store = getEvalStore();
|
|
5072
5387
|
const { sid } = request.params;
|
|
5073
5388
|
const suite = await store.getSuiteById(tenantId, sid);
|
|
@@ -5096,7 +5411,7 @@ async function createCase(request, reply) {
|
|
|
5096
5411
|
}
|
|
5097
5412
|
async function listCasesForSuite(request, reply) {
|
|
5098
5413
|
try {
|
|
5099
|
-
const tenantId =
|
|
5414
|
+
const tenantId = getTenantId12(request);
|
|
5100
5415
|
const store = getEvalStore();
|
|
5101
5416
|
const { sid } = request.params;
|
|
5102
5417
|
const cases = await store.getCasesBySuite(tenantId, sid);
|
|
@@ -5112,7 +5427,7 @@ async function listCasesForSuite(request, reply) {
|
|
|
5112
5427
|
}
|
|
5113
5428
|
async function updateCase(request, reply) {
|
|
5114
5429
|
try {
|
|
5115
|
-
const tenantId =
|
|
5430
|
+
const tenantId = getTenantId12(request);
|
|
5116
5431
|
const store = getEvalStore();
|
|
5117
5432
|
const { cid } = request.params;
|
|
5118
5433
|
const existing = await store.getCaseById(tenantId, cid);
|
|
@@ -5132,7 +5447,7 @@ async function updateCase(request, reply) {
|
|
|
5132
5447
|
}
|
|
5133
5448
|
async function deleteCase(request, reply) {
|
|
5134
5449
|
try {
|
|
5135
|
-
const tenantId =
|
|
5450
|
+
const tenantId = getTenantId12(request);
|
|
5136
5451
|
const store = getEvalStore();
|
|
5137
5452
|
const { cid } = request.params;
|
|
5138
5453
|
const existing = await store.getCaseById(tenantId, cid);
|
|
@@ -5164,7 +5479,7 @@ function registerEvalRoutes(app2) {
|
|
|
5164
5479
|
app2.delete("/api/eval/projects/:pid/suites/:sid/cases/:cid", deleteCase);
|
|
5165
5480
|
app2.post("/api/eval/projects/:pid/runs", async (request, reply) => {
|
|
5166
5481
|
try {
|
|
5167
|
-
const tenantId =
|
|
5482
|
+
const tenantId = getTenantId12(request);
|
|
5168
5483
|
const { pid } = request.params;
|
|
5169
5484
|
const runId = await evalRunner.startRun(tenantId, pid);
|
|
5170
5485
|
reply.status(202).send({ success: true, message: "Run started", data: { run_id: runId } });
|
|
@@ -5176,7 +5491,7 @@ function registerEvalRoutes(app2) {
|
|
|
5176
5491
|
});
|
|
5177
5492
|
app2.get("/api/eval/runs", async (request, reply) => {
|
|
5178
5493
|
try {
|
|
5179
|
-
const tenantId =
|
|
5494
|
+
const tenantId = getTenantId12(request);
|
|
5180
5495
|
const query = request.query;
|
|
5181
5496
|
const runs = await getEvalStore().getRunsByTenant(tenantId, { projectId: query.project_id, status: query.status });
|
|
5182
5497
|
reply.send({ success: true, message: "Ok", data: { records: runs, total: runs.length } });
|
|
@@ -5186,7 +5501,7 @@ function registerEvalRoutes(app2) {
|
|
|
5186
5501
|
});
|
|
5187
5502
|
app2.get("/api/eval/runs/:rid", async (request, reply) => {
|
|
5188
5503
|
try {
|
|
5189
|
-
const tenantId =
|
|
5504
|
+
const tenantId = getTenantId12(request);
|
|
5190
5505
|
const { rid } = request.params;
|
|
5191
5506
|
const run = await getEvalStore().getRunById(tenantId, rid);
|
|
5192
5507
|
if (!run) return reply.status(404).send({ success: false, message: "Run not found" });
|
|
@@ -5208,7 +5523,7 @@ function registerEvalRoutes(app2) {
|
|
|
5208
5523
|
const emitter = evalRunner.getEventEmitter();
|
|
5209
5524
|
const eventKey = `run:${rid}`;
|
|
5210
5525
|
if (!evalRunner.isRunning(rid)) {
|
|
5211
|
-
const tenantId =
|
|
5526
|
+
const tenantId = getTenantId12(request);
|
|
5212
5527
|
const run = await getEvalStore().getRunById(tenantId, rid);
|
|
5213
5528
|
if (run) {
|
|
5214
5529
|
const eventType = run.status === "completed" ? "completed" : "error";
|
|
@@ -5247,7 +5562,7 @@ data: ${JSON.stringify(event.data)}
|
|
|
5247
5562
|
});
|
|
5248
5563
|
app2.delete("/api/eval/runs/:rid", async (request, reply) => {
|
|
5249
5564
|
try {
|
|
5250
|
-
const tenantId =
|
|
5565
|
+
const tenantId = getTenantId12(request);
|
|
5251
5566
|
const { rid } = request.params;
|
|
5252
5567
|
const deleted = await getEvalStore().deleteRun(tenantId, rid);
|
|
5253
5568
|
if (!deleted) return reply.status(404).send({ success: false, message: "Run not found" });
|
|
@@ -5258,7 +5573,7 @@ data: ${JSON.stringify(event.data)}
|
|
|
5258
5573
|
});
|
|
5259
5574
|
app2.get("/api/eval/reports/projects/:pid", async (request, reply) => {
|
|
5260
5575
|
try {
|
|
5261
|
-
const tenantId =
|
|
5576
|
+
const tenantId = getTenantId12(request);
|
|
5262
5577
|
const { pid } = request.params;
|
|
5263
5578
|
const report = await getEvalStore().getProjectReport(tenantId, pid);
|
|
5264
5579
|
if (!report) return reply.status(404).send({ success: false, message: "Project not found" });
|
|
@@ -5270,11 +5585,11 @@ data: ${JSON.stringify(event.data)}
|
|
|
5270
5585
|
}
|
|
5271
5586
|
|
|
5272
5587
|
// src/controllers/users.ts
|
|
5273
|
-
import { getStoreLattice as
|
|
5588
|
+
import { getStoreLattice as getStoreLattice13 } from "@axiom-lattice/core";
|
|
5274
5589
|
import { v4 as uuidv44 } from "uuid";
|
|
5275
5590
|
var UsersController = class {
|
|
5276
5591
|
constructor() {
|
|
5277
|
-
this.userStore =
|
|
5592
|
+
this.userStore = getStoreLattice13("default", "user").store;
|
|
5278
5593
|
}
|
|
5279
5594
|
async listUsers(request, reply) {
|
|
5280
5595
|
const { email } = request.query;
|
|
@@ -5352,11 +5667,11 @@ function registerUserRoutes(app2) {
|
|
|
5352
5667
|
}
|
|
5353
5668
|
|
|
5354
5669
|
// src/controllers/tenants.ts
|
|
5355
|
-
import { getStoreLattice as
|
|
5670
|
+
import { getStoreLattice as getStoreLattice14 } from "@axiom-lattice/core";
|
|
5356
5671
|
import { v4 as uuidv45 } from "uuid";
|
|
5357
5672
|
var TenantsController = class {
|
|
5358
5673
|
constructor() {
|
|
5359
|
-
this.tenantStore =
|
|
5674
|
+
this.tenantStore = getStoreLattice14("default", "tenant").store;
|
|
5360
5675
|
}
|
|
5361
5676
|
// ==================== Tenant CRUD ====================
|
|
5362
5677
|
async listTenants(request, reply) {
|
|
@@ -5420,7 +5735,7 @@ function registerTenantRoutes(app2) {
|
|
|
5420
5735
|
}
|
|
5421
5736
|
|
|
5422
5737
|
// src/controllers/auth.ts
|
|
5423
|
-
import { getStoreLattice as
|
|
5738
|
+
import { getStoreLattice as getStoreLattice15 } from "@axiom-lattice/core";
|
|
5424
5739
|
import { v4 as uuidv46 } from "uuid";
|
|
5425
5740
|
var defaultAuthConfig = {
|
|
5426
5741
|
autoApproveUsers: true,
|
|
@@ -5429,9 +5744,9 @@ var defaultAuthConfig = {
|
|
|
5429
5744
|
};
|
|
5430
5745
|
var AuthController = class {
|
|
5431
5746
|
constructor(config = {}) {
|
|
5432
|
-
this.userStore =
|
|
5433
|
-
this.tenantStore =
|
|
5434
|
-
this.userTenantLinkStore =
|
|
5747
|
+
this.userStore = getStoreLattice15("default", "user").store;
|
|
5748
|
+
this.tenantStore = getStoreLattice15("default", "tenant").store;
|
|
5749
|
+
this.userTenantLinkStore = getStoreLattice15("default", "userTenantLink").store;
|
|
5435
5750
|
this.config = { ...defaultAuthConfig, ...config };
|
|
5436
5751
|
}
|
|
5437
5752
|
async register(request, reply) {
|
|
@@ -5585,6 +5900,8 @@ var AuthController = class {
|
|
|
5585
5900
|
});
|
|
5586
5901
|
}
|
|
5587
5902
|
const token = await this.generateToken(userId, tenantId);
|
|
5903
|
+
const link = await this.userTenantLinkStore.getLink(userId, tenantId);
|
|
5904
|
+
const linkMeta = link?.metadata || {};
|
|
5588
5905
|
return {
|
|
5589
5906
|
success: true,
|
|
5590
5907
|
data: {
|
|
@@ -5593,7 +5910,12 @@ var AuthController = class {
|
|
|
5593
5910
|
name: tenant.name,
|
|
5594
5911
|
status: tenant.status
|
|
5595
5912
|
},
|
|
5596
|
-
token
|
|
5913
|
+
token,
|
|
5914
|
+
personalAssistant: linkMeta.personalAssistantId ? {
|
|
5915
|
+
assistantId: linkMeta.personalAssistantId,
|
|
5916
|
+
projectId: linkMeta.personalProjectId || "default",
|
|
5917
|
+
workspaceId: linkMeta.personalWorkspaceId || "default"
|
|
5918
|
+
} : null
|
|
5597
5919
|
}
|
|
5598
5920
|
};
|
|
5599
5921
|
} catch (error) {
|
|
@@ -5839,82 +6161,6 @@ function normalizeChatType(chatType) {
|
|
|
5839
6161
|
return chatType === "p2p" ? "direct" : "group";
|
|
5840
6162
|
}
|
|
5841
6163
|
|
|
5842
|
-
// src/channels/lark/LarkChannelAdapter.ts
|
|
5843
|
-
var larkConfigSchema = z.object({
|
|
5844
|
-
appId: z.string(),
|
|
5845
|
-
appSecret: z.string(),
|
|
5846
|
-
verificationToken: z.string().optional(),
|
|
5847
|
-
encryptKey: z.string().optional()
|
|
5848
|
-
});
|
|
5849
|
-
var larkChannelAdapter = {
|
|
5850
|
-
channel: "lark",
|
|
5851
|
-
configSchema: larkConfigSchema,
|
|
5852
|
-
async receive(rawPayload, installation) {
|
|
5853
|
-
const event = parseLarkMessageEvent(rawPayload);
|
|
5854
|
-
if (!event) return null;
|
|
5855
|
-
return {
|
|
5856
|
-
channel: "lark",
|
|
5857
|
-
channelInstallationId: installation.id,
|
|
5858
|
-
tenantId: installation.tenantId,
|
|
5859
|
-
sender: {
|
|
5860
|
-
id: event.openId,
|
|
5861
|
-
displayName: void 0
|
|
5862
|
-
},
|
|
5863
|
-
content: {
|
|
5864
|
-
text: event.text,
|
|
5865
|
-
metadata: {
|
|
5866
|
-
chatId: event.chatId,
|
|
5867
|
-
chatType: event.chatType,
|
|
5868
|
-
messageId: event.messageId
|
|
5869
|
-
}
|
|
5870
|
-
},
|
|
5871
|
-
conversation: {
|
|
5872
|
-
id: event.chatId,
|
|
5873
|
-
type: event.chatType
|
|
5874
|
-
},
|
|
5875
|
-
replyTarget: {
|
|
5876
|
-
adapterChannel: "lark",
|
|
5877
|
-
channelInstallationId: installation.id,
|
|
5878
|
-
rawTarget: {
|
|
5879
|
-
chatId: event.chatId,
|
|
5880
|
-
messageId: event.messageId,
|
|
5881
|
-
chatType: event.chatType
|
|
5882
|
-
}
|
|
5883
|
-
}
|
|
5884
|
-
};
|
|
5885
|
-
},
|
|
5886
|
-
async sendReply(replyTarget, message, installation) {
|
|
5887
|
-
const { createLarkSender } = await import("./sender-PX32VSHB.mjs");
|
|
5888
|
-
const sender = await createLarkSender(installation.config);
|
|
5889
|
-
await sender.sendTextReply({
|
|
5890
|
-
chatId: replyTarget.rawTarget.chatId,
|
|
5891
|
-
text: message.text
|
|
5892
|
-
});
|
|
5893
|
-
}
|
|
5894
|
-
};
|
|
5895
|
-
|
|
5896
|
-
// src/channels/lark/verification.ts
|
|
5897
|
-
import crypto2 from "crypto";
|
|
5898
|
-
function parseLarkRequestBody(body, encryptKey) {
|
|
5899
|
-
const parsed = body || {};
|
|
5900
|
-
if (encryptKey && typeof parsed.encrypt === "string") {
|
|
5901
|
-
return decryptLarkPayload(encryptKey, parsed.encrypt);
|
|
5902
|
-
}
|
|
5903
|
-
return parsed;
|
|
5904
|
-
}
|
|
5905
|
-
function decryptLarkPayload(encryptKey, encryptedPayload) {
|
|
5906
|
-
const key = crypto2.createHash("sha256").update(encryptKey).digest();
|
|
5907
|
-
const buffer = Buffer.from(encryptedPayload, "base64");
|
|
5908
|
-
const iv = buffer.subarray(0, 16);
|
|
5909
|
-
const ciphertext = buffer.subarray(16);
|
|
5910
|
-
const decipher = crypto2.createDecipheriv("aes-256-cbc", key, iv);
|
|
5911
|
-
const plaintext = Buffer.concat([
|
|
5912
|
-
decipher.update(ciphertext),
|
|
5913
|
-
decipher.final()
|
|
5914
|
-
]).toString("utf8");
|
|
5915
|
-
return JSON.parse(plaintext);
|
|
5916
|
-
}
|
|
5917
|
-
|
|
5918
6164
|
// src/logger/Logger.ts
|
|
5919
6165
|
import pino from "pino";
|
|
5920
6166
|
import "pino-pretty";
|
|
@@ -6053,8 +6299,165 @@ var Logger = class _Logger {
|
|
|
6053
6299
|
}
|
|
6054
6300
|
};
|
|
6055
6301
|
|
|
6056
|
-
// src/channels/lark/
|
|
6302
|
+
// src/channels/lark/LarkChannelAdapter.ts
|
|
6303
|
+
import * as Lark from "@larksuiteoapi/node-sdk";
|
|
6057
6304
|
var logger = new Logger({ serviceName: "lattice/gateway/lark" });
|
|
6305
|
+
var activeConnections = /* @__PURE__ */ new Map();
|
|
6306
|
+
function parseTextContent(content) {
|
|
6307
|
+
if (!content) return null;
|
|
6308
|
+
try {
|
|
6309
|
+
const parsed = JSON.parse(content);
|
|
6310
|
+
return typeof parsed.text === "string" ? parsed.text : null;
|
|
6311
|
+
} catch {
|
|
6312
|
+
return null;
|
|
6313
|
+
}
|
|
6314
|
+
}
|
|
6315
|
+
function normalizeChatType2(chatType) {
|
|
6316
|
+
return chatType === "p2p" ? "direct" : "group";
|
|
6317
|
+
}
|
|
6318
|
+
function wsEventToInbound(event, installationId, tenantId) {
|
|
6319
|
+
const messageId = event.message?.message_id;
|
|
6320
|
+
const chatId = event.message?.chat_id;
|
|
6321
|
+
const openId = event.sender?.sender_id?.open_id;
|
|
6322
|
+
if (!messageId || !chatId || !openId) return null;
|
|
6323
|
+
if (event.message?.message_type !== "text") return null;
|
|
6324
|
+
const text = parseTextContent(event.message.content);
|
|
6325
|
+
if (!text) return null;
|
|
6326
|
+
const chatType = normalizeChatType2(event.message.chat_type);
|
|
6327
|
+
return {
|
|
6328
|
+
channel: "lark",
|
|
6329
|
+
channelInstallationId: installationId,
|
|
6330
|
+
tenantId,
|
|
6331
|
+
sender: { id: openId, displayName: void 0 },
|
|
6332
|
+
content: { text, metadata: { chatId, chatType, messageId } },
|
|
6333
|
+
conversation: { id: chatId, type: chatType },
|
|
6334
|
+
replyTarget: {
|
|
6335
|
+
adapterChannel: "lark",
|
|
6336
|
+
channelInstallationId: installationId,
|
|
6337
|
+
rawTarget: { chatId, messageId, chatType }
|
|
6338
|
+
}
|
|
6339
|
+
};
|
|
6340
|
+
}
|
|
6341
|
+
var larkConfigSchema = z.object({
|
|
6342
|
+
appId: z.string(),
|
|
6343
|
+
appSecret: z.string(),
|
|
6344
|
+
verificationToken: z.string().optional(),
|
|
6345
|
+
encryptKey: z.string().optional()
|
|
6346
|
+
});
|
|
6347
|
+
var larkChannelAdapter = {
|
|
6348
|
+
channel: "lark",
|
|
6349
|
+
configSchema: larkConfigSchema,
|
|
6350
|
+
async receive(rawPayload, installation) {
|
|
6351
|
+
const event = parseLarkMessageEvent(rawPayload);
|
|
6352
|
+
if (!event) return null;
|
|
6353
|
+
return {
|
|
6354
|
+
channel: "lark",
|
|
6355
|
+
channelInstallationId: installation.id,
|
|
6356
|
+
tenantId: installation.tenantId,
|
|
6357
|
+
sender: { id: event.openId, displayName: void 0 },
|
|
6358
|
+
content: {
|
|
6359
|
+
text: event.text,
|
|
6360
|
+
metadata: { chatId: event.chatId, chatType: event.chatType, messageId: event.messageId }
|
|
6361
|
+
},
|
|
6362
|
+
conversation: { id: event.chatId, type: event.chatType },
|
|
6363
|
+
replyTarget: {
|
|
6364
|
+
adapterChannel: "lark",
|
|
6365
|
+
channelInstallationId: installation.id,
|
|
6366
|
+
rawTarget: { chatId: event.chatId, messageId: event.messageId, chatType: event.chatType }
|
|
6367
|
+
}
|
|
6368
|
+
};
|
|
6369
|
+
},
|
|
6370
|
+
async sendReply(replyTarget, message, installation) {
|
|
6371
|
+
const { createLarkSender } = await import("./sender-PX32VSHB.mjs");
|
|
6372
|
+
const sender = await createLarkSender(installation.config);
|
|
6373
|
+
await sender.sendTextReply({
|
|
6374
|
+
chatId: replyTarget.rawTarget.chatId,
|
|
6375
|
+
text: message.text
|
|
6376
|
+
});
|
|
6377
|
+
},
|
|
6378
|
+
resolveThreadId(message, binding) {
|
|
6379
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
6380
|
+
const chatType = message.conversation?.type === "direct" ? "dm" : "group";
|
|
6381
|
+
const agentId = binding.agentId;
|
|
6382
|
+
if (chatType === "dm") {
|
|
6383
|
+
return `lark:dm:${message.sender.id}:${agentId}:${date}`;
|
|
6384
|
+
}
|
|
6385
|
+
return `lark:group:${message.conversation?.id ?? "unknown"}:${agentId}:${date}`;
|
|
6386
|
+
},
|
|
6387
|
+
async connect(installation, deps) {
|
|
6388
|
+
const { id: installationId, tenantId, config } = installation;
|
|
6389
|
+
if (!config.appId || !config.appSecret) {
|
|
6390
|
+
logger.warn("Lark installation missing credentials, skipping", { installationId });
|
|
6391
|
+
return;
|
|
6392
|
+
}
|
|
6393
|
+
if (activeConnections.has(installationId)) {
|
|
6394
|
+
logger.warn("Lark WS already connected for installation, skipping", { installationId });
|
|
6395
|
+
return;
|
|
6396
|
+
}
|
|
6397
|
+
logger.info("Lark WS client starting", { installationId, tenantId });
|
|
6398
|
+
const router = deps?.router;
|
|
6399
|
+
const eventDispatcher = new Lark.EventDispatcher({}).register({
|
|
6400
|
+
"im.message.receive_v1": async (data) => {
|
|
6401
|
+
try {
|
|
6402
|
+
const inbound = wsEventToInbound(data, installationId, tenantId);
|
|
6403
|
+
if (!inbound) return;
|
|
6404
|
+
logger.info("Lark WS message received", {
|
|
6405
|
+
installationId,
|
|
6406
|
+
senderId: inbound.sender.id,
|
|
6407
|
+
chatId: data.message?.chat_id
|
|
6408
|
+
});
|
|
6409
|
+
if (router) {
|
|
6410
|
+
const result = await router.dispatch(inbound);
|
|
6411
|
+
if (!result.success) {
|
|
6412
|
+
logger.warn("Lark WS dispatch failed", {
|
|
6413
|
+
installationId,
|
|
6414
|
+
error: result.error?.message
|
|
6415
|
+
});
|
|
6416
|
+
}
|
|
6417
|
+
}
|
|
6418
|
+
} catch (err) {
|
|
6419
|
+
logger.error("Lark WS event handler error", {
|
|
6420
|
+
installationId,
|
|
6421
|
+
error: err instanceof Error ? err.message : String(err)
|
|
6422
|
+
});
|
|
6423
|
+
}
|
|
6424
|
+
}
|
|
6425
|
+
});
|
|
6426
|
+
const client = new Lark.WSClient({
|
|
6427
|
+
appId: config.appId,
|
|
6428
|
+
appSecret: config.appSecret,
|
|
6429
|
+
loggerLevel: Lark.LoggerLevel.info
|
|
6430
|
+
});
|
|
6431
|
+
await client.start({ eventDispatcher });
|
|
6432
|
+
activeConnections.set(installationId, client);
|
|
6433
|
+
logger.info("Lark WS client connected", { installationId });
|
|
6434
|
+
}
|
|
6435
|
+
};
|
|
6436
|
+
|
|
6437
|
+
// src/channels/lark/verification.ts
|
|
6438
|
+
import crypto2 from "crypto";
|
|
6439
|
+
function parseLarkRequestBody(body, encryptKey) {
|
|
6440
|
+
const parsed = body || {};
|
|
6441
|
+
if (encryptKey && typeof parsed.encrypt === "string") {
|
|
6442
|
+
return decryptLarkPayload(encryptKey, parsed.encrypt);
|
|
6443
|
+
}
|
|
6444
|
+
return parsed;
|
|
6445
|
+
}
|
|
6446
|
+
function decryptLarkPayload(encryptKey, encryptedPayload) {
|
|
6447
|
+
const key = crypto2.createHash("sha256").update(encryptKey).digest();
|
|
6448
|
+
const buffer = Buffer.from(encryptedPayload, "base64");
|
|
6449
|
+
const iv = buffer.subarray(0, 16);
|
|
6450
|
+
const ciphertext = buffer.subarray(16);
|
|
6451
|
+
const decipher = crypto2.createDecipheriv("aes-256-cbc", key, iv);
|
|
6452
|
+
const plaintext = Buffer.concat([
|
|
6453
|
+
decipher.update(ciphertext),
|
|
6454
|
+
decipher.final()
|
|
6455
|
+
]).toString("utf8");
|
|
6456
|
+
return JSON.parse(plaintext);
|
|
6457
|
+
}
|
|
6458
|
+
|
|
6459
|
+
// src/channels/lark/controller.ts
|
|
6460
|
+
var logger2 = new Logger({ serviceName: "lattice/gateway/lark" });
|
|
6058
6461
|
function createLarkEventHandler(deps) {
|
|
6059
6462
|
return async function handleLarkEvent(request, reply) {
|
|
6060
6463
|
const { installationId } = request.params;
|
|
@@ -6075,7 +6478,7 @@ function createLarkEventHandler(deps) {
|
|
|
6075
6478
|
return;
|
|
6076
6479
|
}
|
|
6077
6480
|
deps.router.dispatch(inboundMessage).catch((error) => {
|
|
6078
|
-
|
|
6481
|
+
logger2.error("Lark message dispatch error", {
|
|
6079
6482
|
error: error instanceof Error ? error.message : String(error)
|
|
6080
6483
|
});
|
|
6081
6484
|
});
|
|
@@ -6107,8 +6510,8 @@ function registerChannelRoutes(app2, dependencies) {
|
|
|
6107
6510
|
}
|
|
6108
6511
|
|
|
6109
6512
|
// src/controllers/channel-installations.ts
|
|
6110
|
-
import { randomUUID as
|
|
6111
|
-
function
|
|
6513
|
+
import { randomUUID as randomUUID7 } from "crypto";
|
|
6514
|
+
function getTenantId13(request) {
|
|
6112
6515
|
const userTenantId = request.user?.tenantId;
|
|
6113
6516
|
if (userTenantId) {
|
|
6114
6517
|
return userTenantId;
|
|
@@ -6116,8 +6519,8 @@ function getTenantId11(request) {
|
|
|
6116
6519
|
return request.headers["x-tenant-id"] || "default";
|
|
6117
6520
|
}
|
|
6118
6521
|
async function getInstallationStore() {
|
|
6119
|
-
const { getStoreLattice:
|
|
6120
|
-
const store =
|
|
6522
|
+
const { getStoreLattice: getStoreLattice18 } = await import("@axiom-lattice/core");
|
|
6523
|
+
const store = getStoreLattice18("default", "channelInstallation").store;
|
|
6121
6524
|
if (store) return store;
|
|
6122
6525
|
const { PostgreSQLChannelInstallationStore } = await import("@axiom-lattice/pg-stores");
|
|
6123
6526
|
const databaseUrl = process.env.DATABASE_URL;
|
|
@@ -6129,7 +6532,7 @@ async function getInstallationStore() {
|
|
|
6129
6532
|
});
|
|
6130
6533
|
}
|
|
6131
6534
|
async function getChannelInstallationList(request, reply) {
|
|
6132
|
-
const tenantId =
|
|
6535
|
+
const tenantId = getTenantId13(request);
|
|
6133
6536
|
const { channel } = request.query;
|
|
6134
6537
|
try {
|
|
6135
6538
|
const store = await getInstallationStore();
|
|
@@ -6155,7 +6558,7 @@ async function getChannelInstallationList(request, reply) {
|
|
|
6155
6558
|
}
|
|
6156
6559
|
}
|
|
6157
6560
|
async function getChannelInstallation(request, reply) {
|
|
6158
|
-
const tenantId =
|
|
6561
|
+
const tenantId = getTenantId13(request);
|
|
6159
6562
|
const { installationId } = request.params;
|
|
6160
6563
|
try {
|
|
6161
6564
|
const store = await getInstallationStore();
|
|
@@ -6188,7 +6591,7 @@ async function getChannelInstallation(request, reply) {
|
|
|
6188
6591
|
}
|
|
6189
6592
|
}
|
|
6190
6593
|
async function createChannelInstallation(request, reply) {
|
|
6191
|
-
const tenantId =
|
|
6594
|
+
const tenantId = getTenantId13(request);
|
|
6192
6595
|
const body = request.body;
|
|
6193
6596
|
try {
|
|
6194
6597
|
if (!body.channel) {
|
|
@@ -6223,7 +6626,7 @@ async function createChannelInstallation(request, reply) {
|
|
|
6223
6626
|
}
|
|
6224
6627
|
}
|
|
6225
6628
|
const store = await getInstallationStore();
|
|
6226
|
-
const installationId = body.id ||
|
|
6629
|
+
const installationId = body.id || randomUUID7();
|
|
6227
6630
|
const installation = await store.createInstallation(
|
|
6228
6631
|
tenantId,
|
|
6229
6632
|
installationId,
|
|
@@ -6251,7 +6654,7 @@ async function createChannelInstallation(request, reply) {
|
|
|
6251
6654
|
}
|
|
6252
6655
|
}
|
|
6253
6656
|
async function updateChannelInstallation(request, reply) {
|
|
6254
|
-
const tenantId =
|
|
6657
|
+
const tenantId = getTenantId13(request);
|
|
6255
6658
|
const { installationId } = request.params;
|
|
6256
6659
|
const body = request.body;
|
|
6257
6660
|
try {
|
|
@@ -6297,7 +6700,7 @@ async function updateChannelInstallation(request, reply) {
|
|
|
6297
6700
|
}
|
|
6298
6701
|
}
|
|
6299
6702
|
async function deleteChannelInstallation(request, reply) {
|
|
6300
|
-
const tenantId =
|
|
6703
|
+
const tenantId = getTenantId13(request);
|
|
6301
6704
|
const { installationId } = request.params;
|
|
6302
6705
|
try {
|
|
6303
6706
|
const store = await getInstallationStore();
|
|
@@ -6348,13 +6751,13 @@ function registerChannelInstallationRoutes(app2) {
|
|
|
6348
6751
|
|
|
6349
6752
|
// src/controllers/channel-bindings.ts
|
|
6350
6753
|
import { getBindingRegistry } from "@axiom-lattice/core";
|
|
6351
|
-
function
|
|
6754
|
+
function getTenantId14(request) {
|
|
6352
6755
|
const userTenantId = request.user?.tenantId;
|
|
6353
6756
|
if (userTenantId) return userTenantId;
|
|
6354
6757
|
return request.headers["x-tenant-id"] || "default";
|
|
6355
6758
|
}
|
|
6356
6759
|
async function getBindingList(request, _reply) {
|
|
6357
|
-
const tenantId =
|
|
6760
|
+
const tenantId = getTenantId14(request);
|
|
6358
6761
|
const { channel, agentId, channelInstallationId, limit, offset } = request.query;
|
|
6359
6762
|
try {
|
|
6360
6763
|
const registry = getBindingRegistry();
|
|
@@ -6366,7 +6769,7 @@ async function getBindingList(request, _reply) {
|
|
|
6366
6769
|
}
|
|
6367
6770
|
}
|
|
6368
6771
|
async function getBinding(request, reply) {
|
|
6369
|
-
const tenantId =
|
|
6772
|
+
const tenantId = getTenantId14(request);
|
|
6370
6773
|
try {
|
|
6371
6774
|
const registry = getBindingRegistry();
|
|
6372
6775
|
const bindings = await registry.list({ tenantId });
|
|
@@ -6382,7 +6785,7 @@ async function getBinding(request, reply) {
|
|
|
6382
6785
|
}
|
|
6383
6786
|
}
|
|
6384
6787
|
async function createBinding(request, reply) {
|
|
6385
|
-
const tenantId =
|
|
6788
|
+
const tenantId = getTenantId14(request);
|
|
6386
6789
|
try {
|
|
6387
6790
|
const registry = getBindingRegistry();
|
|
6388
6791
|
const binding = await registry.create({ ...request.body, tenantId });
|
|
@@ -6396,7 +6799,7 @@ async function createBinding(request, reply) {
|
|
|
6396
6799
|
}
|
|
6397
6800
|
async function updateBinding(request, reply) {
|
|
6398
6801
|
try {
|
|
6399
|
-
const tenantId =
|
|
6802
|
+
const tenantId = getTenantId14(request);
|
|
6400
6803
|
const registry = getBindingRegistry();
|
|
6401
6804
|
const bindings = await registry.list({ tenantId });
|
|
6402
6805
|
const existing = bindings.find((b) => b.id === request.params.id);
|
|
@@ -6414,7 +6817,7 @@ async function updateBinding(request, reply) {
|
|
|
6414
6817
|
}
|
|
6415
6818
|
async function deleteBinding(request, reply) {
|
|
6416
6819
|
try {
|
|
6417
|
-
const tenantId =
|
|
6820
|
+
const tenantId = getTenantId14(request);
|
|
6418
6821
|
const registry = getBindingRegistry();
|
|
6419
6822
|
const bindings = await registry.list({ tenantId });
|
|
6420
6823
|
const existing = bindings.find((b) => b.id === request.params.id);
|
|
@@ -6431,7 +6834,7 @@ async function deleteBinding(request, reply) {
|
|
|
6431
6834
|
}
|
|
6432
6835
|
}
|
|
6433
6836
|
async function resolveBinding(request, _reply) {
|
|
6434
|
-
const tenantId =
|
|
6837
|
+
const tenantId = getTenantId14(request);
|
|
6435
6838
|
const { channel, senderId, channelInstallationId } = request.query;
|
|
6436
6839
|
try {
|
|
6437
6840
|
const registry = getBindingRegistry();
|
|
@@ -6456,6 +6859,105 @@ function registerChannelBindingRoutes(app2) {
|
|
|
6456
6859
|
app2.delete("/api/channel-bindings/:id", deleteBinding);
|
|
6457
6860
|
}
|
|
6458
6861
|
|
|
6862
|
+
// src/controllers/menu-items.ts
|
|
6863
|
+
import { getMenuRegistry } from "@axiom-lattice/core";
|
|
6864
|
+
function getTenantId15(request) {
|
|
6865
|
+
const userTenantId = request.user?.tenantId;
|
|
6866
|
+
if (userTenantId) return userTenantId;
|
|
6867
|
+
return request.headers["x-tenant-id"] || "default";
|
|
6868
|
+
}
|
|
6869
|
+
function errorMessage(err) {
|
|
6870
|
+
return err instanceof Error ? err.message : "Unexpected error";
|
|
6871
|
+
}
|
|
6872
|
+
async function getMenuItemList(request, _reply) {
|
|
6873
|
+
const tenantId = getTenantId15(request);
|
|
6874
|
+
try {
|
|
6875
|
+
const registry = getMenuRegistry();
|
|
6876
|
+
const items = await registry.list({ tenantId, menuTarget: request.query.menuTarget });
|
|
6877
|
+
return { success: true, message: "Menu items retrieved", data: { records: items, total: items.length } };
|
|
6878
|
+
} catch (error) {
|
|
6879
|
+
const msg = errorMessage(error);
|
|
6880
|
+
console.error("Failed to get menu items:", msg);
|
|
6881
|
+
return { success: false, message: msg, data: { records: [], total: 0 } };
|
|
6882
|
+
}
|
|
6883
|
+
}
|
|
6884
|
+
async function getMenuItem(request, reply) {
|
|
6885
|
+
const tenantId = getTenantId15(request);
|
|
6886
|
+
try {
|
|
6887
|
+
const registry = getMenuRegistry();
|
|
6888
|
+
const item = await registry.getById(request.params.id);
|
|
6889
|
+
if (!item || item.tenantId !== tenantId) {
|
|
6890
|
+
reply.status(404);
|
|
6891
|
+
return { success: false, message: "Menu item not found" };
|
|
6892
|
+
}
|
|
6893
|
+
return { success: true, message: "Menu item retrieved", data: item };
|
|
6894
|
+
} catch (error) {
|
|
6895
|
+
const msg = errorMessage(error);
|
|
6896
|
+
console.error("Failed to get menu item:", msg);
|
|
6897
|
+
reply.status(500);
|
|
6898
|
+
return { success: false, message: msg };
|
|
6899
|
+
}
|
|
6900
|
+
}
|
|
6901
|
+
async function createMenuItem(request, reply) {
|
|
6902
|
+
const tenantId = getTenantId15(request);
|
|
6903
|
+
try {
|
|
6904
|
+
const registry = getMenuRegistry();
|
|
6905
|
+
const item = await registry.create({ ...request.body, tenantId });
|
|
6906
|
+
reply.status(201);
|
|
6907
|
+
return { success: true, message: "Menu item created", data: item };
|
|
6908
|
+
} catch (error) {
|
|
6909
|
+
const msg = errorMessage(error);
|
|
6910
|
+
console.error("Failed to create menu item:", msg);
|
|
6911
|
+
reply.status(500);
|
|
6912
|
+
return { success: false, message: msg };
|
|
6913
|
+
}
|
|
6914
|
+
}
|
|
6915
|
+
async function updateMenuItem(request, reply) {
|
|
6916
|
+
try {
|
|
6917
|
+
const tenantId = getTenantId15(request);
|
|
6918
|
+
const registry = getMenuRegistry();
|
|
6919
|
+
const existing = await registry.getById(request.params.id);
|
|
6920
|
+
if (!existing || existing.tenantId !== tenantId) {
|
|
6921
|
+
reply.status(404);
|
|
6922
|
+
return { success: false, message: "Menu item not found" };
|
|
6923
|
+
}
|
|
6924
|
+
const item = await registry.update(request.params.id, request.body);
|
|
6925
|
+
return { success: true, message: "Menu item updated", data: item };
|
|
6926
|
+
} catch (error) {
|
|
6927
|
+
const msg = errorMessage(error);
|
|
6928
|
+
console.error("Failed to update menu item:", msg);
|
|
6929
|
+
reply.status(500);
|
|
6930
|
+
return { success: false, message: msg };
|
|
6931
|
+
}
|
|
6932
|
+
}
|
|
6933
|
+
async function deleteMenuItem(request, reply) {
|
|
6934
|
+
try {
|
|
6935
|
+
const tenantId = getTenantId15(request);
|
|
6936
|
+
const registry = getMenuRegistry();
|
|
6937
|
+
const existing = await registry.getById(request.params.id);
|
|
6938
|
+
if (!existing || existing.tenantId !== tenantId) {
|
|
6939
|
+
reply.status(404);
|
|
6940
|
+
return { success: false, message: "Menu item not found" };
|
|
6941
|
+
}
|
|
6942
|
+
await registry.delete(request.params.id);
|
|
6943
|
+
return { success: true, message: "Menu item deleted" };
|
|
6944
|
+
} catch (error) {
|
|
6945
|
+
const msg = errorMessage(error);
|
|
6946
|
+
console.error("Failed to delete menu item:", msg);
|
|
6947
|
+
reply.status(500);
|
|
6948
|
+
return { success: false, message: msg };
|
|
6949
|
+
}
|
|
6950
|
+
}
|
|
6951
|
+
|
|
6952
|
+
// src/routes/menu-items.ts
|
|
6953
|
+
function registerMenuItemRoutes(app2) {
|
|
6954
|
+
app2.get("/api/menu-items", getMenuItemList);
|
|
6955
|
+
app2.post("/api/menu-items", createMenuItem);
|
|
6956
|
+
app2.get("/api/menu-items/:id", getMenuItem);
|
|
6957
|
+
app2.put("/api/menu-items/:id", updateMenuItem);
|
|
6958
|
+
app2.delete("/api/menu-items/:id", deleteMenuItem);
|
|
6959
|
+
}
|
|
6960
|
+
|
|
6459
6961
|
// src/routes/a2a-bridge.ts
|
|
6460
6962
|
import { v4 as v42 } from "uuid";
|
|
6461
6963
|
var log = {
|
|
@@ -6636,6 +7138,7 @@ var registerLatticeRoutes = (app2, channelDeps) => {
|
|
|
6636
7138
|
app2.post("/api/runs", createRun);
|
|
6637
7139
|
app2.post("/api/resume_stream", resumeStream);
|
|
6638
7140
|
app2.post("/api/assistants/:assistantId/threads/:threadId/abort", abortRun);
|
|
7141
|
+
app2.post("/api/assistants/:assistantId/threads/:threadId/recover", recoverRun);
|
|
6639
7142
|
app2.get(
|
|
6640
7143
|
"/api/assistants/:assistantId/:thread_id/memory",
|
|
6641
7144
|
{ schema: getAllMemoryItemsSchema },
|
|
@@ -6671,6 +7174,15 @@ var registerLatticeRoutes = (app2, channelDeps) => {
|
|
|
6671
7174
|
app2.post("/api/assistants", createAssistant);
|
|
6672
7175
|
app2.put("/api/assistants/:id", updateAssistant);
|
|
6673
7176
|
app2.delete("/api/assistants/:id", deleteAssistant);
|
|
7177
|
+
app2.post("/api/personal-assistant", createPersonalAssistant);
|
|
7178
|
+
app2.get("/api/personal-assistant", getPersonalAssistant);
|
|
7179
|
+
app2.delete("/api/personal-assistant", deletePersonalAssistant);
|
|
7180
|
+
app2.get("/api/tasks", listTasks);
|
|
7181
|
+
app2.get("/api/tasks/:id", getTask);
|
|
7182
|
+
app2.post("/api/tasks", createTask);
|
|
7183
|
+
app2.put("/api/tasks/:id", updateTask);
|
|
7184
|
+
app2.delete("/api/tasks/:id", deleteTask);
|
|
7185
|
+
app2.patch("/api/tasks/:id/complete", completeTask);
|
|
6674
7186
|
app2.get(
|
|
6675
7187
|
"/api/assistants/:assistantId/graph",
|
|
6676
7188
|
{ schema: getAgentGraphSchema },
|
|
@@ -6769,6 +7281,7 @@ var registerLatticeRoutes = (app2, channelDeps) => {
|
|
|
6769
7281
|
});
|
|
6770
7282
|
registerChannelRoutes(app2, channelDeps);
|
|
6771
7283
|
registerChannelInstallationRoutes(app2);
|
|
7284
|
+
registerMenuItemRoutes(app2);
|
|
6772
7285
|
if (channelDeps) {
|
|
6773
7286
|
registerChannelBindingRoutes(app2);
|
|
6774
7287
|
}
|
|
@@ -6847,10 +7360,10 @@ var registerLatticeRoutes = (app2, channelDeps) => {
|
|
|
6847
7360
|
|
|
6848
7361
|
// src/router/MessageRouter.ts
|
|
6849
7362
|
import {
|
|
6850
|
-
getStoreLattice as
|
|
7363
|
+
getStoreLattice as getStoreLattice16,
|
|
6851
7364
|
agentInstanceManager as agentInstanceManager6
|
|
6852
7365
|
} from "@axiom-lattice/core";
|
|
6853
|
-
import { randomUUID as
|
|
7366
|
+
import { randomUUID as randomUUID8 } from "crypto";
|
|
6854
7367
|
var BindingNotFoundError = class extends Error {
|
|
6855
7368
|
constructor(message) {
|
|
6856
7369
|
super(message);
|
|
@@ -6897,6 +7410,9 @@ var MessageRouter = class {
|
|
|
6897
7410
|
inboundMessage: message,
|
|
6898
7411
|
metadata: {}
|
|
6899
7412
|
};
|
|
7413
|
+
let binding = null;
|
|
7414
|
+
let threadId;
|
|
7415
|
+
let agentId;
|
|
6900
7416
|
try {
|
|
6901
7417
|
await this.runMiddlewares(ctx, async () => {
|
|
6902
7418
|
const tenantId = message.tenantId || (await this.installationStore.getInstallationById(message.channelInstallationId))?.tenantId;
|
|
@@ -6913,16 +7429,18 @@ var MessageRouter = class {
|
|
|
6913
7429
|
);
|
|
6914
7430
|
}
|
|
6915
7431
|
console.log({ event: "dispatch:start", channel: message.channel, senderId: message.sender.id, tenantId }, "Message dispatch started");
|
|
6916
|
-
|
|
7432
|
+
const adapter = this.adapterRegistry.get(message.channel);
|
|
7433
|
+
const hasAdapterThreadStrategy = !!adapter?.resolveThreadId;
|
|
7434
|
+
binding = await this.bindingRegistry.resolve({
|
|
6917
7435
|
channel: message.channel,
|
|
6918
7436
|
senderId: message.sender.id,
|
|
6919
7437
|
channelInstallationId: message.channelInstallationId,
|
|
6920
7438
|
tenantId
|
|
6921
7439
|
});
|
|
7440
|
+
const installation = await this.installationStore.getInstallationById(
|
|
7441
|
+
message.channelInstallationId
|
|
7442
|
+
);
|
|
6922
7443
|
if (!binding) {
|
|
6923
|
-
const installation = await this.installationStore.getInstallationById(
|
|
6924
|
-
message.channelInstallationId
|
|
6925
|
-
);
|
|
6926
7444
|
if (installation?.rejectWhenNoBinding) {
|
|
6927
7445
|
console.warn({
|
|
6928
7446
|
event: "dispatch:no_binding",
|
|
@@ -6955,7 +7473,7 @@ var MessageRouter = class {
|
|
|
6955
7473
|
createdAt: /* @__PURE__ */ new Date(),
|
|
6956
7474
|
updatedAt: /* @__PURE__ */ new Date()
|
|
6957
7475
|
};
|
|
6958
|
-
} else {
|
|
7476
|
+
} else if (!hasAdapterThreadStrategy) {
|
|
6959
7477
|
console.error({
|
|
6960
7478
|
event: "dispatch:no_fallback",
|
|
6961
7479
|
channel: message.channel,
|
|
@@ -6967,47 +7485,99 @@ var MessageRouter = class {
|
|
|
6967
7485
|
);
|
|
6968
7486
|
}
|
|
6969
7487
|
}
|
|
6970
|
-
ctx.binding = binding;
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
agentId: binding.agentId,
|
|
6975
|
-
threadId: binding.threadId,
|
|
6976
|
-
threadMode: binding.threadMode,
|
|
6977
|
-
workspaceId: binding.workspaceId,
|
|
6978
|
-
projectId: binding.projectId
|
|
6979
|
-
}, "Binding resolved");
|
|
6980
|
-
if (!binding.enabled) {
|
|
6981
|
-
console.warn({
|
|
6982
|
-
event: "dispatch:binding_disabled",
|
|
7488
|
+
ctx.binding = binding ?? void 0;
|
|
7489
|
+
if (binding) {
|
|
7490
|
+
console.log({
|
|
7491
|
+
event: "dispatch:binding",
|
|
6983
7492
|
bindingId: binding.id,
|
|
6984
7493
|
agentId: binding.agentId,
|
|
6985
|
-
|
|
6986
|
-
|
|
7494
|
+
threadId: binding.threadId,
|
|
7495
|
+
threadMode: binding.threadMode,
|
|
7496
|
+
workspaceId: binding.workspaceId,
|
|
7497
|
+
projectId: binding.projectId
|
|
7498
|
+
}, "Binding resolved");
|
|
7499
|
+
if (!binding.enabled) {
|
|
7500
|
+
console.warn({
|
|
7501
|
+
event: "dispatch:binding_disabled",
|
|
7502
|
+
bindingId: binding.id,
|
|
7503
|
+
agentId: binding.agentId,
|
|
7504
|
+
senderId: message.sender.id
|
|
7505
|
+
}, "Binding is disabled, rejecting message");
|
|
7506
|
+
throw new BindingNotFoundError(
|
|
7507
|
+
`Binding for sender "${message.sender.id}" is disabled`
|
|
7508
|
+
);
|
|
7509
|
+
}
|
|
7510
|
+
}
|
|
7511
|
+
agentId = binding?.agentId ?? installation?.fallbackAgentId;
|
|
7512
|
+
if (!agentId) {
|
|
6987
7513
|
throw new BindingNotFoundError(
|
|
6988
|
-
`
|
|
7514
|
+
`No agent configured for sender "${message.sender.id}"`
|
|
6989
7515
|
);
|
|
6990
7516
|
}
|
|
6991
|
-
|
|
7517
|
+
if (hasAdapterThreadStrategy) {
|
|
7518
|
+
const resolvedThreadId = await adapter.resolveThreadId(message, binding);
|
|
7519
|
+
threadId = resolvedThreadId;
|
|
7520
|
+
console.log({
|
|
7521
|
+
event: "dispatch:thread:adapter",
|
|
7522
|
+
threadId,
|
|
7523
|
+
channel: message.channel,
|
|
7524
|
+
adapterChannel: adapter.channel
|
|
7525
|
+
}, "Thread resolved by adapter strategy");
|
|
7526
|
+
const threadStore = getStoreLattice16("default", "thread").store;
|
|
7527
|
+
try {
|
|
7528
|
+
await threadStore.createThread(
|
|
7529
|
+
tenantId,
|
|
7530
|
+
agentId,
|
|
7531
|
+
threadId,
|
|
7532
|
+
{
|
|
7533
|
+
metadata: {
|
|
7534
|
+
channel: message.channel,
|
|
7535
|
+
channelInstallationId: message.channelInstallationId,
|
|
7536
|
+
senderId: message.sender.id,
|
|
7537
|
+
bindingId: binding?.id,
|
|
7538
|
+
...message.conversation ? {
|
|
7539
|
+
conversationId: message.conversation.id,
|
|
7540
|
+
conversationType: message.conversation.type
|
|
7541
|
+
} : {}
|
|
7542
|
+
}
|
|
7543
|
+
}
|
|
7544
|
+
);
|
|
7545
|
+
console.log({
|
|
7546
|
+
event: "dispatch:thread:adapter:created",
|
|
7547
|
+
threadId
|
|
7548
|
+
}, "Thread created by adapter strategy");
|
|
7549
|
+
} catch {
|
|
7550
|
+
console.log({
|
|
7551
|
+
event: "dispatch:thread:adapter:reuse",
|
|
7552
|
+
threadId
|
|
7553
|
+
}, "Thread already exists, reusing");
|
|
7554
|
+
}
|
|
7555
|
+
} else if (binding) {
|
|
7556
|
+
if (binding.threadMode === "per_conversation") {
|
|
7557
|
+
threadId = void 0;
|
|
7558
|
+
} else {
|
|
7559
|
+
threadId = binding.threadId;
|
|
7560
|
+
}
|
|
7561
|
+
}
|
|
6992
7562
|
if (!threadId) {
|
|
6993
|
-
const threadStore =
|
|
6994
|
-
const newThreadId =
|
|
7563
|
+
const threadStore = getStoreLattice16("default", "thread").store;
|
|
7564
|
+
const newThreadId = randomUUID8();
|
|
6995
7565
|
console.log({
|
|
6996
7566
|
event: "dispatch:thread:create",
|
|
6997
|
-
agentId
|
|
7567
|
+
agentId,
|
|
6998
7568
|
newThreadId,
|
|
6999
7569
|
tenantId
|
|
7000
7570
|
}, "Creating new thread for binding");
|
|
7001
7571
|
const newThread = await threadStore.createThread(
|
|
7002
7572
|
tenantId,
|
|
7003
|
-
|
|
7573
|
+
agentId,
|
|
7004
7574
|
newThreadId,
|
|
7005
7575
|
{
|
|
7006
7576
|
metadata: {
|
|
7007
7577
|
channel: message.channel,
|
|
7008
7578
|
channelInstallationId: message.channelInstallationId,
|
|
7009
7579
|
senderId: message.sender.id,
|
|
7010
|
-
bindingId:
|
|
7580
|
+
bindingId: binding?.id,
|
|
7011
7581
|
...message.conversation ? {
|
|
7012
7582
|
conversationId: message.conversation.id,
|
|
7013
7583
|
conversationType: message.conversation.type
|
|
@@ -7016,36 +7586,35 @@ var MessageRouter = class {
|
|
|
7016
7586
|
}
|
|
7017
7587
|
);
|
|
7018
7588
|
threadId = newThread.id;
|
|
7019
|
-
if (
|
|
7020
|
-
await this.bindingRegistry.update(
|
|
7021
|
-
|
|
7022
|
-
} else {
|
|
7023
|
-
|
|
7589
|
+
if (binding && binding.id !== "fallback") {
|
|
7590
|
+
await this.bindingRegistry.update(binding.id, { threadId });
|
|
7591
|
+
binding.threadId = threadId;
|
|
7592
|
+
} else if (binding) {
|
|
7593
|
+
binding.threadId = threadId;
|
|
7024
7594
|
}
|
|
7025
7595
|
}
|
|
7026
7596
|
console.log({
|
|
7027
7597
|
event: "dispatch:agent",
|
|
7028
|
-
agentId
|
|
7598
|
+
agentId,
|
|
7029
7599
|
threadId,
|
|
7030
|
-
threadMode: ctx.binding.threadMode,
|
|
7031
7600
|
senderId: message.sender.id,
|
|
7032
7601
|
contentLength: message.content.text.length
|
|
7033
7602
|
}, "Dispatching to agent");
|
|
7034
7603
|
const agent = agentInstanceManager6.getAgent({
|
|
7035
7604
|
tenant_id: tenantId,
|
|
7036
|
-
assistant_id:
|
|
7605
|
+
assistant_id: agentId,
|
|
7037
7606
|
thread_id: threadId,
|
|
7038
|
-
workspace_id:
|
|
7039
|
-
project_id:
|
|
7607
|
+
workspace_id: binding?.workspaceId || "",
|
|
7608
|
+
project_id: binding?.projectId || ""
|
|
7040
7609
|
});
|
|
7041
7610
|
if (message.replyTarget) {
|
|
7042
7611
|
const replySubKey = `${threadId}:${message.replyTarget.adapterChannel}:reply`;
|
|
7043
|
-
const
|
|
7044
|
-
if (
|
|
7045
|
-
const
|
|
7612
|
+
const adapter2 = this.adapterRegistry.get(message.replyTarget.adapterChannel);
|
|
7613
|
+
if (adapter2) {
|
|
7614
|
+
const installation2 = await this.installationStore.getInstallationById(
|
|
7046
7615
|
message.channelInstallationId
|
|
7047
7616
|
);
|
|
7048
|
-
if (
|
|
7617
|
+
if (installation2) {
|
|
7049
7618
|
const existing = this._replySubs.get(replySubKey);
|
|
7050
7619
|
if (!existing || existing.count === 0) {
|
|
7051
7620
|
const timer = setTimeout(() => {
|
|
@@ -7085,7 +7654,7 @@ var MessageRouter = class {
|
|
|
7085
7654
|
channel: message.replyTarget.adapterChannel,
|
|
7086
7655
|
replyLength: replyText.length
|
|
7087
7656
|
}, "Sending channel reply");
|
|
7088
|
-
|
|
7657
|
+
adapter2.sendReply(message.replyTarget, { text: replyText }, installation2).then(() => {
|
|
7089
7658
|
console.log({
|
|
7090
7659
|
event: "dispatch:reply:sent",
|
|
7091
7660
|
threadId,
|
|
@@ -7123,7 +7692,7 @@ var MessageRouter = class {
|
|
|
7123
7692
|
});
|
|
7124
7693
|
console.log({
|
|
7125
7694
|
event: "dispatch:complete",
|
|
7126
|
-
agentId
|
|
7695
|
+
agentId,
|
|
7127
7696
|
threadId,
|
|
7128
7697
|
messageId: addResult?.messageId,
|
|
7129
7698
|
result: JSON.stringify(addResult)
|
|
@@ -7132,7 +7701,7 @@ var MessageRouter = class {
|
|
|
7132
7701
|
return {
|
|
7133
7702
|
success: true,
|
|
7134
7703
|
bindingId: ctx.binding?.id,
|
|
7135
|
-
threadId
|
|
7704
|
+
threadId,
|
|
7136
7705
|
result: ctx.result
|
|
7137
7706
|
};
|
|
7138
7707
|
} catch (error) {
|
|
@@ -7243,13 +7812,13 @@ function createRateLimitMiddleware(maxRequests = 10, windowMs = 60 * 1e3, maxEnt
|
|
|
7243
7812
|
}
|
|
7244
7813
|
|
|
7245
7814
|
// src/router/middlewares/auditLogger.ts
|
|
7246
|
-
var
|
|
7815
|
+
var logger3 = new Logger({ serviceName: "lattice/gateway/audit" });
|
|
7247
7816
|
function createAuditLoggerMiddleware() {
|
|
7248
7817
|
return async (ctx, next) => {
|
|
7249
7818
|
const start2 = Date.now();
|
|
7250
7819
|
try {
|
|
7251
7820
|
await next();
|
|
7252
|
-
|
|
7821
|
+
logger3.info("message routed", {
|
|
7253
7822
|
event: "message:routed",
|
|
7254
7823
|
channel: ctx.inboundMessage.channel,
|
|
7255
7824
|
senderId: ctx.inboundMessage.sender.id,
|
|
@@ -7259,7 +7828,7 @@ function createAuditLoggerMiddleware() {
|
|
|
7259
7828
|
status: "success"
|
|
7260
7829
|
});
|
|
7261
7830
|
} catch (error) {
|
|
7262
|
-
|
|
7831
|
+
logger3.error(
|
|
7263
7832
|
error instanceof Error ? error.message : String(error),
|
|
7264
7833
|
{
|
|
7265
7834
|
event: "message:error",
|
|
@@ -7275,7 +7844,7 @@ function createAuditLoggerMiddleware() {
|
|
|
7275
7844
|
}
|
|
7276
7845
|
|
|
7277
7846
|
// src/index.ts
|
|
7278
|
-
import { setBindingRegistry } from "@axiom-lattice/core";
|
|
7847
|
+
import { setBindingRegistry, setMenuRegistry } from "@axiom-lattice/core";
|
|
7279
7848
|
|
|
7280
7849
|
// src/swagger.ts
|
|
7281
7850
|
import swagger from "@fastify/swagger";
|
|
@@ -7364,15 +7933,16 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
7364
7933
|
agent.subscribeOnce("message:completed", (evt) => {
|
|
7365
7934
|
eventBus2.publish(callback_event, {
|
|
7366
7935
|
success: true,
|
|
7367
|
-
state: evt.state
|
|
7368
|
-
config: { assistant_id, thread_id, tenant_id }
|
|
7936
|
+
state: evt.state
|
|
7369
7937
|
});
|
|
7370
7938
|
if (main_thread_id && main_tenant_id) {
|
|
7371
7939
|
try {
|
|
7372
7940
|
const mainAgent = agentInstanceManager7.getAgent({
|
|
7373
7941
|
assistant_id: main_assistant_id ?? assistant_id,
|
|
7374
7942
|
thread_id: main_thread_id,
|
|
7375
|
-
tenant_id: main_tenant_id
|
|
7943
|
+
tenant_id: main_tenant_id,
|
|
7944
|
+
workspace_id: runConfig?.workspaceId,
|
|
7945
|
+
project_id: runConfig?.projectId
|
|
7376
7946
|
});
|
|
7377
7947
|
if (mainAgent) {
|
|
7378
7948
|
const messages = evt.state?.values?.messages;
|
|
@@ -7399,8 +7969,7 @@ ${summary}`
|
|
|
7399
7969
|
agent.subscribeOnce("message:interrupted", (evt) => {
|
|
7400
7970
|
eventBus2.publish(callback_event, {
|
|
7401
7971
|
success: true,
|
|
7402
|
-
state: evt.state
|
|
7403
|
-
config: { assistant_id, thread_id, tenant_id }
|
|
7972
|
+
state: evt.state
|
|
7404
7973
|
});
|
|
7405
7974
|
});
|
|
7406
7975
|
}
|
|
@@ -7423,8 +7992,7 @@ ${summary}`
|
|
|
7423
7992
|
if (callback_event) {
|
|
7424
7993
|
eventBus2.publish(callback_event, {
|
|
7425
7994
|
success: false,
|
|
7426
|
-
error: error instanceof Error ? error.message : String(error)
|
|
7427
|
-
config: { assistant_id, thread_id, tenant_id }
|
|
7995
|
+
error: error instanceof Error ? error.message : String(error)
|
|
7428
7996
|
});
|
|
7429
7997
|
}
|
|
7430
7998
|
console.error(
|
|
@@ -7580,12 +8148,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
7580
8148
|
if (taskRequest.callback_event) {
|
|
7581
8149
|
eventBus2.publish(taskRequest.callback_event, {
|
|
7582
8150
|
success: false,
|
|
7583
|
-
error: error instanceof Error ? error.message : String(error)
|
|
7584
|
-
config: {
|
|
7585
|
-
assistant_id: taskRequest.assistant_id,
|
|
7586
|
-
thread_id: taskRequest.thread_id,
|
|
7587
|
-
tenant_id: taskRequest["x-tenant-id"]
|
|
7588
|
-
}
|
|
8151
|
+
error: error instanceof Error ? error.message : String(error)
|
|
7589
8152
|
});
|
|
7590
8153
|
}
|
|
7591
8154
|
});
|
|
@@ -7603,6 +8166,7 @@ import {
|
|
|
7603
8166
|
getLoggerLattice,
|
|
7604
8167
|
loggerLatticeManager,
|
|
7605
8168
|
sandboxLatticeManager as sandboxLatticeManager2,
|
|
8169
|
+
getStoreLattice as getStoreLattice17,
|
|
7606
8170
|
agentInstanceManager as agentInstanceManager8,
|
|
7607
8171
|
createSandboxProvider
|
|
7608
8172
|
} from "@axiom-lattice/core";
|
|
@@ -7620,7 +8184,7 @@ var DEFAULT_LOGGER_CONFIG = {
|
|
|
7620
8184
|
loggerName: "lattice/gateway"
|
|
7621
8185
|
};
|
|
7622
8186
|
var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
|
|
7623
|
-
var
|
|
8187
|
+
var logger4 = loggerLattice.client;
|
|
7624
8188
|
function initializeLogger(config) {
|
|
7625
8189
|
if (loggerLatticeManager.hasLattice("default")) {
|
|
7626
8190
|
loggerLatticeManager.removeLattice("default");
|
|
@@ -7663,6 +8227,8 @@ app.addHook("preHandler", async (request, reply) => {
|
|
|
7663
8227
|
if (!authRequired) return;
|
|
7664
8228
|
if (request.method === "OPTIONS") return;
|
|
7665
8229
|
if (PUBLIC_ROUTES.some((r) => request.url === r)) return;
|
|
8230
|
+
const urlPath = request.url.split("?")[0];
|
|
8231
|
+
if (urlPath.includes("/viewfile") || urlPath.includes("/downloadfile")) return;
|
|
7666
8232
|
return reply.status(401).send({
|
|
7667
8233
|
success: false,
|
|
7668
8234
|
error: "Unauthorized - Missing or invalid token"
|
|
@@ -7719,7 +8285,7 @@ app.setErrorHandler((error, request, reply) => {
|
|
|
7719
8285
|
"x-request-id": getHeaderValue(request.headers["x-request-id"]),
|
|
7720
8286
|
"x-user-id": getHeaderValue(request.headers["x-user-id"])
|
|
7721
8287
|
};
|
|
7722
|
-
|
|
8288
|
+
logger4.error(
|
|
7723
8289
|
`\u8BF7\u6C42\u9519\u8BEF: ${request.method} ${request.url} error:${error.message}`,
|
|
7724
8290
|
{
|
|
7725
8291
|
...context,
|
|
@@ -7759,17 +8325,19 @@ var start = async (config) => {
|
|
|
7759
8325
|
file: config.loggerConfig.file || DEFAULT_LOGGER_CONFIG.file
|
|
7760
8326
|
};
|
|
7761
8327
|
loggerLattice = initializeLogger(loggerConfig);
|
|
7762
|
-
|
|
8328
|
+
logger4 = loggerLattice.client;
|
|
7763
8329
|
}
|
|
7764
8330
|
app.decorate("loggerLattice", loggerLattice);
|
|
7765
8331
|
let channelDeps;
|
|
8332
|
+
const adapterRegistry = new ChannelAdapterRegistry();
|
|
8333
|
+
adapterRegistry.register(larkChannelAdapter);
|
|
7766
8334
|
try {
|
|
7767
|
-
const { getStoreLattice:
|
|
7768
|
-
|
|
7769
|
-
|
|
8335
|
+
const { getStoreLattice: getStore2 } = await import("@axiom-lattice/core");
|
|
8336
|
+
let bindingStore;
|
|
8337
|
+
let installationStore;
|
|
8338
|
+
bindingStore = getStore2("default", "channelBinding").store;
|
|
8339
|
+
installationStore = getStore2("default", "channelInstallation").store;
|
|
7770
8340
|
setBindingRegistry(bindingStore);
|
|
7771
|
-
const adapterRegistry = new ChannelAdapterRegistry();
|
|
7772
|
-
adapterRegistry.register(larkChannelAdapter);
|
|
7773
8341
|
const router = new MessageRouter({
|
|
7774
8342
|
middlewares: [
|
|
7775
8343
|
createDeduplicationMiddleware(),
|
|
@@ -7782,27 +8350,49 @@ var start = async (config) => {
|
|
|
7782
8350
|
});
|
|
7783
8351
|
channelDeps = { router, installationStore };
|
|
7784
8352
|
try {
|
|
7785
|
-
const a2aKeyStore =
|
|
8353
|
+
const a2aKeyStore = getStore2("default", "a2aApiKey").store;
|
|
7786
8354
|
const a2a = await import("./a2a-ERG5RMUW.mjs");
|
|
7787
8355
|
a2a.setA2AKeyStore(a2aKeyStore);
|
|
7788
8356
|
await a2a.refreshStoreKeyMap();
|
|
7789
|
-
|
|
8357
|
+
logger4.info("A2A key store initialized");
|
|
7790
8358
|
} catch {
|
|
7791
8359
|
}
|
|
8360
|
+
} catch (err) {
|
|
8361
|
+
logger4.warn("Channel infrastructure unavailable", {
|
|
8362
|
+
error: err instanceof Error ? err.message : String(err)
|
|
8363
|
+
});
|
|
8364
|
+
}
|
|
8365
|
+
try {
|
|
8366
|
+
const menuStore = getStoreLattice17("default", "menu").store;
|
|
8367
|
+
setMenuRegistry(menuStore);
|
|
8368
|
+
logger4.info("Menu registry initialized");
|
|
7792
8369
|
} catch {
|
|
7793
8370
|
}
|
|
7794
8371
|
registerLatticeRoutes(app, channelDeps);
|
|
7795
8372
|
if (!sandboxLatticeManager2.hasLattice("default")) {
|
|
7796
8373
|
sandboxLatticeManager2.registerLattice("default", getConfiguredSandboxProvider());
|
|
7797
|
-
|
|
8374
|
+
logger4.info("Registered sandbox manager from env configuration");
|
|
8375
|
+
}
|
|
8376
|
+
if (channelDeps && process.env.CHANNELS_ENABLED !== "false") {
|
|
8377
|
+
const { connectAllChannels } = await import("@axiom-lattice/core");
|
|
8378
|
+
try {
|
|
8379
|
+
await connectAllChannels(
|
|
8380
|
+
(channel) => adapterRegistry.get(channel),
|
|
8381
|
+
{ deps: { router: channelDeps.router } }
|
|
8382
|
+
);
|
|
8383
|
+
} catch (err) {
|
|
8384
|
+
logger4.error("Failed to start channel connections", {
|
|
8385
|
+
error: err instanceof Error ? err.message : String(err)
|
|
8386
|
+
});
|
|
8387
|
+
}
|
|
7798
8388
|
}
|
|
7799
8389
|
const target_port = config?.port || Number(process.env.PORT) || 4001;
|
|
7800
8390
|
await app.listen({ port: target_port, host: "0.0.0.0" });
|
|
7801
|
-
|
|
8391
|
+
logger4.info(`Lattice Gateway is running on port: ${target_port}`);
|
|
7802
8392
|
try {
|
|
7803
|
-
|
|
8393
|
+
logger4.info("AgentLifecycleManager initialized");
|
|
7804
8394
|
} catch (error) {
|
|
7805
|
-
|
|
8395
|
+
logger4.warn("Failed to initialize AgentLifecycleManager", { error });
|
|
7806
8396
|
}
|
|
7807
8397
|
const queueServiceConfig = config?.queueServiceConfig;
|
|
7808
8398
|
if (queueServiceConfig) {
|
|
@@ -7812,15 +8402,13 @@ var start = async (config) => {
|
|
|
7812
8402
|
agentTaskConsumer.startPollingQueue();
|
|
7813
8403
|
}
|
|
7814
8404
|
}
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
}
|
|
7820
|
-
logger3.error("Agent recovery failed", { error });
|
|
7821
|
-
}
|
|
8405
|
+
agentInstanceManager8.restore().then((stats) => {
|
|
8406
|
+
logger4.info(`Agent recovery complete: ${stats.restored} threads restored, ${stats.errors} errors`);
|
|
8407
|
+
}).catch((error) => {
|
|
8408
|
+
logger4.error("Agent recovery failed", { error });
|
|
8409
|
+
});
|
|
7822
8410
|
} catch (err) {
|
|
7823
|
-
|
|
8411
|
+
logger4.error("Server start failed", { error: err });
|
|
7824
8412
|
process.exit(1);
|
|
7825
8413
|
}
|
|
7826
8414
|
};
|