@axiom-lattice/gateway 2.1.111 → 2.1.113
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 +13 -13
- package/CHANGELOG.md +20 -0
- package/dist/index.js +2118 -319
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1948 -145
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
- package/src/controllers/__tests__/workflow-tracking.test.ts +113 -0
- package/src/controllers/connections.ts +7 -0
- package/src/controllers/eval.ts +44 -4
- package/src/controllers/export-import.ts +166 -0
- package/src/controllers/run.ts +30 -4
- package/src/controllers/workflow-tracking.ts +105 -11
- package/src/export_registrations/a2a-api-key.registration.ts +89 -0
- package/src/export_registrations/agent.registration.ts +80 -0
- package/src/export_registrations/binding.registration.ts +106 -0
- package/src/export_registrations/channel-installation.registration.ts +88 -0
- package/src/export_registrations/collection.registration.ts +85 -0
- package/src/export_registrations/connection.registration.ts +97 -0
- package/src/export_registrations/database-config.registration.ts +94 -0
- package/src/export_registrations/eval.registration.ts +334 -0
- package/src/export_registrations/index.ts +31 -0
- package/src/export_registrations/mcp-config.registration.ts +97 -0
- package/src/export_registrations/menu.registration.ts +91 -0
- package/src/export_registrations/metrics-config.registration.ts +94 -0
- package/src/export_registrations/skill.registration.ts +88 -0
- package/src/export_registrations/task.registration.ts +99 -0
- package/src/index.ts +18 -8
- package/src/routes/index.ts +42 -1
- package/src/services/ExportImportService.ts +296 -0
- package/src/services/__tests__/ExportImportService.test.ts +130 -0
- package/src/services/eval-runner.ts +63 -55
package/dist/index.js
CHANGED
|
@@ -94,7 +94,7 @@ __export(mcp_configs_exports, {
|
|
|
94
94
|
testMcpServerTools: () => testMcpServerTools,
|
|
95
95
|
updateMcpServerConfig: () => updateMcpServerConfig
|
|
96
96
|
});
|
|
97
|
-
function
|
|
97
|
+
function getTenantId13(request) {
|
|
98
98
|
const userTenantId = request.user?.tenantId;
|
|
99
99
|
if (userTenantId) {
|
|
100
100
|
return userTenantId;
|
|
@@ -102,9 +102,9 @@ function getTenantId12(request) {
|
|
|
102
102
|
return request.headers["x-tenant-id"] || "default";
|
|
103
103
|
}
|
|
104
104
|
async function getMcpServerConfigList(request, reply) {
|
|
105
|
-
const tenantId =
|
|
105
|
+
const tenantId = getTenantId13(request);
|
|
106
106
|
try {
|
|
107
|
-
const storeLattice = (0,
|
|
107
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
108
108
|
const store2 = storeLattice.store;
|
|
109
109
|
const configs = await store2.getAllConfigs(tenantId);
|
|
110
110
|
return {
|
|
@@ -128,10 +128,10 @@ async function getMcpServerConfigList(request, reply) {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
async function getMcpServerConfig(request, reply) {
|
|
131
|
-
const tenantId =
|
|
131
|
+
const tenantId = getTenantId13(request);
|
|
132
132
|
const { key } = request.params;
|
|
133
133
|
try {
|
|
134
|
-
const storeLattice = (0,
|
|
134
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
135
135
|
const store2 = storeLattice.store;
|
|
136
136
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
137
137
|
if (!config) {
|
|
@@ -154,10 +154,10 @@ async function getMcpServerConfig(request, reply) {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
async function createMcpServerConfig(request, reply) {
|
|
157
|
-
const tenantId =
|
|
157
|
+
const tenantId = getTenantId13(request);
|
|
158
158
|
const body = request.body;
|
|
159
159
|
try {
|
|
160
|
-
const storeLattice = (0,
|
|
160
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
161
161
|
const store2 = storeLattice.store;
|
|
162
162
|
const existing = await store2.getConfigByKey(tenantId, body.key);
|
|
163
163
|
if (existing) {
|
|
@@ -167,7 +167,7 @@ async function createMcpServerConfig(request, reply) {
|
|
|
167
167
|
message: "MCP server configuration with this key already exists"
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
|
-
const id = body.id || (0,
|
|
170
|
+
const id = body.id || (0, import_crypto7.randomUUID)();
|
|
171
171
|
const config = await store2.createConfig(tenantId, id, body);
|
|
172
172
|
try {
|
|
173
173
|
await connectAndRegisterTools(config);
|
|
@@ -193,11 +193,11 @@ async function createMcpServerConfig(request, reply) {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
async function updateMcpServerConfig(request, reply) {
|
|
196
|
-
const tenantId =
|
|
196
|
+
const tenantId = getTenantId13(request);
|
|
197
197
|
const { key } = request.params;
|
|
198
198
|
const updates = request.body;
|
|
199
199
|
try {
|
|
200
|
-
const storeLattice = (0,
|
|
200
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
201
201
|
const store2 = storeLattice.store;
|
|
202
202
|
const existing = await store2.getConfigByKey(tenantId, key);
|
|
203
203
|
if (!existing) {
|
|
@@ -217,8 +217,8 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
217
217
|
}
|
|
218
218
|
if (shouldReconnect) {
|
|
219
219
|
try {
|
|
220
|
-
await
|
|
221
|
-
await
|
|
220
|
+
await import_core30.mcpManager.reconnectServer(key);
|
|
221
|
+
await import_core30.mcpManager.registerToolsToToolLattice(key, updated.selectedTools);
|
|
222
222
|
await store2.updateConfig(tenantId, existing.id, { status: "connected" });
|
|
223
223
|
updated.status = "connected";
|
|
224
224
|
} catch (error) {
|
|
@@ -241,10 +241,10 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
async function deleteMcpServerConfig(request, reply) {
|
|
244
|
-
const tenantId =
|
|
244
|
+
const tenantId = getTenantId13(request);
|
|
245
245
|
const { keyOrId } = request.params;
|
|
246
246
|
try {
|
|
247
|
-
const storeLattice = (0,
|
|
247
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
248
248
|
const store2 = storeLattice.store;
|
|
249
249
|
let config = await store2.getConfigByKey(tenantId, keyOrId);
|
|
250
250
|
let configKey = keyOrId;
|
|
@@ -262,8 +262,8 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
264
|
try {
|
|
265
|
-
if (
|
|
266
|
-
await
|
|
265
|
+
if (import_core30.mcpManager.hasServer(configKey)) {
|
|
266
|
+
await import_core30.mcpManager.removeServer(configKey);
|
|
267
267
|
}
|
|
268
268
|
} catch (error) {
|
|
269
269
|
console.warn("Failed to remove from MCP manager:", error);
|
|
@@ -288,10 +288,10 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
async function testMcpServerConnection(request, reply) {
|
|
291
|
-
const tenantId =
|
|
291
|
+
const tenantId = getTenantId13(request);
|
|
292
292
|
const { key } = request.params;
|
|
293
293
|
try {
|
|
294
|
-
const storeLattice = (0,
|
|
294
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
295
295
|
const store2 = storeLattice.store;
|
|
296
296
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
297
297
|
if (!config) {
|
|
@@ -304,7 +304,7 @@ async function testMcpServerConnection(request, reply) {
|
|
|
304
304
|
try {
|
|
305
305
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
306
306
|
const connection = convertToConnection(config.config);
|
|
307
|
-
const { latency } = await
|
|
307
|
+
const { latency } = await import_core30.McpLatticeManager.testConnection(testKey, connection);
|
|
308
308
|
return {
|
|
309
309
|
success: true,
|
|
310
310
|
message: "Connection test successful",
|
|
@@ -336,10 +336,10 @@ async function testMcpServerConnection(request, reply) {
|
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
async function listMcpServerTools(request, reply) {
|
|
339
|
-
const tenantId =
|
|
339
|
+
const tenantId = getTenantId13(request);
|
|
340
340
|
const { key } = request.params;
|
|
341
341
|
try {
|
|
342
|
-
const storeLattice = (0,
|
|
342
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
343
343
|
const store2 = storeLattice.store;
|
|
344
344
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
345
345
|
if (!config) {
|
|
@@ -349,10 +349,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
349
349
|
message: "MCP server configuration not found"
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
352
|
+
if (!import_core30.mcpManager.hasServer(key)) {
|
|
353
353
|
await connectAndRegisterTools(config);
|
|
354
354
|
}
|
|
355
|
-
const tools = await
|
|
355
|
+
const tools = await import_core30.mcpManager.getServerTools(key);
|
|
356
356
|
return {
|
|
357
357
|
success: true,
|
|
358
358
|
message: "Tools retrieved successfully",
|
|
@@ -369,10 +369,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
async function connectMcpServer(request, reply) {
|
|
372
|
-
const tenantId =
|
|
372
|
+
const tenantId = getTenantId13(request);
|
|
373
373
|
const { key } = request.params;
|
|
374
374
|
try {
|
|
375
|
-
const storeLattice = (0,
|
|
375
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
376
376
|
const store2 = storeLattice.store;
|
|
377
377
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
378
378
|
if (!config) {
|
|
@@ -393,7 +393,7 @@ async function connectMcpServer(request, reply) {
|
|
|
393
393
|
};
|
|
394
394
|
} catch (error) {
|
|
395
395
|
console.error("Failed to connect MCP server:", error);
|
|
396
|
-
const storeLattice = (0,
|
|
396
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
397
397
|
const store2 = storeLattice.store;
|
|
398
398
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
399
399
|
if (config) {
|
|
@@ -406,10 +406,10 @@ async function connectMcpServer(request, reply) {
|
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
async function disconnectMcpServer(request, reply) {
|
|
409
|
-
const tenantId =
|
|
409
|
+
const tenantId = getTenantId13(request);
|
|
410
410
|
const { key } = request.params;
|
|
411
411
|
try {
|
|
412
|
-
const storeLattice = (0,
|
|
412
|
+
const storeLattice = (0, import_core30.getStoreLattice)("default", "mcp");
|
|
413
413
|
const store2 = storeLattice.store;
|
|
414
414
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
415
415
|
if (!config) {
|
|
@@ -419,8 +419,8 @@ async function disconnectMcpServer(request, reply) {
|
|
|
419
419
|
message: "MCP server configuration not found"
|
|
420
420
|
};
|
|
421
421
|
}
|
|
422
|
-
if (
|
|
423
|
-
await
|
|
422
|
+
if (import_core30.mcpManager.hasServer(key)) {
|
|
423
|
+
await import_core30.mcpManager.removeServer(key);
|
|
424
424
|
}
|
|
425
425
|
const updated = await store2.updateConfig(tenantId, config.id, {
|
|
426
426
|
status: "disconnected"
|
|
@@ -450,7 +450,7 @@ async function testMcpServerTools(request, reply) {
|
|
|
450
450
|
}
|
|
451
451
|
const testKey = `__test_${Date.now()}`;
|
|
452
452
|
const connection = convertToConnection(body.config);
|
|
453
|
-
const { tools } = await
|
|
453
|
+
const { tools } = await import_core30.McpLatticeManager.testConnection(testKey, connection);
|
|
454
454
|
return {
|
|
455
455
|
success: true,
|
|
456
456
|
message: "Tools retrieved successfully",
|
|
@@ -487,9 +487,9 @@ function convertToConnection(config) {
|
|
|
487
487
|
}
|
|
488
488
|
async function connectAndRegisterTools(config) {
|
|
489
489
|
const connection = convertToConnection(config.config);
|
|
490
|
-
|
|
491
|
-
await
|
|
492
|
-
await
|
|
490
|
+
import_core30.mcpManager.addServer(config.key, connection);
|
|
491
|
+
await import_core30.mcpManager.connect();
|
|
492
|
+
await import_core30.mcpManager.registerToolsToToolLattice(config.key, config.selectedTools);
|
|
493
493
|
}
|
|
494
494
|
function registerMcpServerConfigRoutes(app2) {
|
|
495
495
|
app2.get("/api/mcp-servers", getMcpServerConfigList);
|
|
@@ -503,12 +503,12 @@ function registerMcpServerConfigRoutes(app2) {
|
|
|
503
503
|
app2.post("/api/mcp-servers/:key/disconnect", disconnectMcpServer);
|
|
504
504
|
app2.post("/api/mcp-servers/test-tools", testMcpServerTools);
|
|
505
505
|
}
|
|
506
|
-
var
|
|
506
|
+
var import_core30, import_crypto7;
|
|
507
507
|
var init_mcp_configs = __esm({
|
|
508
508
|
"src/controllers/mcp-configs.ts"() {
|
|
509
509
|
"use strict";
|
|
510
|
-
|
|
511
|
-
|
|
510
|
+
import_core30 = require("@axiom-lattice/core");
|
|
511
|
+
import_crypto7 = require("crypto");
|
|
512
512
|
}
|
|
513
513
|
});
|
|
514
514
|
|
|
@@ -1290,7 +1290,7 @@ async function handleTasksSend(request, reply) {
|
|
|
1290
1290
|
taskStore.set(taskId, record);
|
|
1291
1291
|
let agent;
|
|
1292
1292
|
try {
|
|
1293
|
-
agent =
|
|
1293
|
+
agent = import_core54.agentInstanceManager.getAgent({
|
|
1294
1294
|
assistant_id: assistantId,
|
|
1295
1295
|
thread_id: threadId,
|
|
1296
1296
|
tenant_id: tenantId,
|
|
@@ -1382,7 +1382,7 @@ async function handleTasksCancel(request, reply) {
|
|
|
1382
1382
|
return;
|
|
1383
1383
|
}
|
|
1384
1384
|
try {
|
|
1385
|
-
const agent =
|
|
1385
|
+
const agent = import_core54.agentInstanceManager.getAgent({
|
|
1386
1386
|
assistant_id: record.assistantId,
|
|
1387
1387
|
thread_id: record.threadId,
|
|
1388
1388
|
tenant_id: record.tenantId,
|
|
@@ -1419,7 +1419,7 @@ async function handleTasksStream(request, reply) {
|
|
|
1419
1419
|
}
|
|
1420
1420
|
let agent;
|
|
1421
1421
|
try {
|
|
1422
|
-
agent =
|
|
1422
|
+
agent = import_core54.agentInstanceManager.getAgent({
|
|
1423
1423
|
assistant_id: record.assistantId,
|
|
1424
1424
|
thread_id: record.threadId,
|
|
1425
1425
|
tenant_id: record.tenantId,
|
|
@@ -1614,12 +1614,12 @@ function registerA2ARoutes(app2) {
|
|
|
1614
1614
|
handleApiKeyRotate
|
|
1615
1615
|
);
|
|
1616
1616
|
}
|
|
1617
|
-
var import_uuid10,
|
|
1617
|
+
var import_uuid10, import_core54, import_protocols4, taskStore, _a2aKeyStore, _storeKeyMap;
|
|
1618
1618
|
var init_a2a = __esm({
|
|
1619
1619
|
"src/routes/a2a.ts"() {
|
|
1620
1620
|
"use strict";
|
|
1621
1621
|
import_uuid10 = require("uuid");
|
|
1622
|
-
|
|
1622
|
+
import_core54 = require("@axiom-lattice/core");
|
|
1623
1623
|
import_protocols4 = require("@axiom-lattice/protocols");
|
|
1624
1624
|
taskStore = /* @__PURE__ */ new Map();
|
|
1625
1625
|
_a2aKeyStore = null;
|
|
@@ -1632,12 +1632,12 @@ var resources_exports = {};
|
|
|
1632
1632
|
__export(resources_exports, {
|
|
1633
1633
|
ResourceController: () => ResourceController
|
|
1634
1634
|
});
|
|
1635
|
-
var import_bcryptjs,
|
|
1635
|
+
var import_bcryptjs, import_core55, ResourceController;
|
|
1636
1636
|
var init_resources = __esm({
|
|
1637
1637
|
"src/controllers/resources.ts"() {
|
|
1638
1638
|
"use strict";
|
|
1639
1639
|
import_bcryptjs = __toESM(require("bcryptjs"));
|
|
1640
|
-
|
|
1640
|
+
import_core55 = require("@axiom-lattice/core");
|
|
1641
1641
|
init_mime();
|
|
1642
1642
|
ResourceController = class {
|
|
1643
1643
|
constructor(deps) {
|
|
@@ -1652,14 +1652,14 @@ var init_resources = __esm({
|
|
|
1652
1652
|
if (!workspaceId || !projectId) {
|
|
1653
1653
|
return reply.status(400).send({ error: "x-workspace-id and x-project-id headers required" });
|
|
1654
1654
|
}
|
|
1655
|
-
const payload = (0,
|
|
1655
|
+
const payload = (0, import_core55.createSharePayload)(
|
|
1656
1656
|
tenantId,
|
|
1657
1657
|
workspaceId,
|
|
1658
1658
|
projectId,
|
|
1659
1659
|
userId,
|
|
1660
1660
|
body
|
|
1661
1661
|
);
|
|
1662
|
-
const token = (0,
|
|
1662
|
+
const token = (0, import_core55.generateToken)();
|
|
1663
1663
|
try {
|
|
1664
1664
|
await this.deps.store.create({ ...payload, token });
|
|
1665
1665
|
this.deps.logger.info(
|
|
@@ -1811,7 +1811,7 @@ var init_resources = __esm({
|
|
|
1811
1811
|
resourcePath: subPath
|
|
1812
1812
|
}, subPath, ext, request, reply);
|
|
1813
1813
|
}
|
|
1814
|
-
const volume = (0,
|
|
1814
|
+
const volume = (0, import_core55.buildNamedVolumeName)("p", "project", tenantId, workspaceId, projectId);
|
|
1815
1815
|
return this._resolveAndServe(
|
|
1816
1816
|
volume,
|
|
1817
1817
|
subPath,
|
|
@@ -2261,6 +2261,20 @@ var createRun = async (request, reply) => {
|
|
|
2261
2261
|
project_id,
|
|
2262
2262
|
custom_run_config: mergedConfig
|
|
2263
2263
|
});
|
|
2264
|
+
if (background) {
|
|
2265
|
+
const messageInput = message_id ? { ...input, id: message_id } : input;
|
|
2266
|
+
const result = await agent.addMessage({
|
|
2267
|
+
input: messageInput,
|
|
2268
|
+
command,
|
|
2269
|
+
custom_run_config: mergedConfig
|
|
2270
|
+
}, mode);
|
|
2271
|
+
reply.status(202).send({
|
|
2272
|
+
success: true,
|
|
2273
|
+
messageId: result.messageId,
|
|
2274
|
+
queued: true
|
|
2275
|
+
});
|
|
2276
|
+
return;
|
|
2277
|
+
}
|
|
2264
2278
|
if (streaming) {
|
|
2265
2279
|
reply.hijack();
|
|
2266
2280
|
reply.raw.writeHead(200, {
|
|
@@ -2346,8 +2360,13 @@ var resumeStream = async (request, reply) => {
|
|
|
2346
2360
|
workspace_id,
|
|
2347
2361
|
project_id
|
|
2348
2362
|
});
|
|
2349
|
-
const stream = agent.chunkStream(message_id, [
|
|
2363
|
+
const stream = agent.chunkStream(message_id, []);
|
|
2364
|
+
let closed = false;
|
|
2365
|
+
request.raw.on("close", () => {
|
|
2366
|
+
closed = true;
|
|
2367
|
+
});
|
|
2350
2368
|
for await (const chunk of stream) {
|
|
2369
|
+
if (closed || reply.raw.destroyed) break;
|
|
2351
2370
|
reply.raw.write(`data: ${JSON.stringify(chunk)}
|
|
2352
2371
|
|
|
2353
2372
|
`);
|
|
@@ -4332,6 +4351,8 @@ async function getAllWorkflowRuns(request, reply) {
|
|
|
4332
4351
|
});
|
|
4333
4352
|
}
|
|
4334
4353
|
}
|
|
4354
|
+
var INBOX_DEFAULT_PAGE_SIZE = 20;
|
|
4355
|
+
var INBOX_MAX_PAGE_SIZE = 100;
|
|
4335
4356
|
async function getInboxItems(request, reply) {
|
|
4336
4357
|
const tenantId = getTenantId7(request);
|
|
4337
4358
|
try {
|
|
@@ -4349,10 +4370,30 @@ async function getInboxItems(request, reply) {
|
|
|
4349
4370
|
}
|
|
4350
4371
|
} catch {
|
|
4351
4372
|
}
|
|
4352
|
-
const
|
|
4353
|
-
const
|
|
4373
|
+
const { page: pageParam, pageSize: pageSizeParam } = request.query;
|
|
4374
|
+
const paged = pageParam !== void 0 || pageSizeParam !== void 0;
|
|
4375
|
+
const page = Math.max(1, parseInt(pageParam ?? "", 10) || 1);
|
|
4376
|
+
const pageSize = Math.min(INBOX_MAX_PAGE_SIZE, Math.max(1, parseInt(pageSizeParam ?? "", 10) || INBOX_DEFAULT_PAGE_SIZE));
|
|
4377
|
+
let pendingRuns;
|
|
4378
|
+
let total;
|
|
4379
|
+
if (paged) {
|
|
4380
|
+
const result = await store2.queryWorkflowRuns(tenantId, {
|
|
4381
|
+
status: "interrupted",
|
|
4382
|
+
limit: pageSize,
|
|
4383
|
+
offset: (page - 1) * pageSize
|
|
4384
|
+
});
|
|
4385
|
+
pendingRuns = result.records;
|
|
4386
|
+
total = result.total;
|
|
4387
|
+
} else {
|
|
4388
|
+
const result = await store2.queryWorkflowRuns(tenantId, { status: "interrupted" });
|
|
4389
|
+
pendingRuns = result.records;
|
|
4390
|
+
}
|
|
4354
4391
|
if (pendingRuns.length === 0) {
|
|
4355
|
-
return {
|
|
4392
|
+
return {
|
|
4393
|
+
success: true,
|
|
4394
|
+
message: "No pending workflows",
|
|
4395
|
+
data: paged ? { records: [], total, page, pageSize } : { records: [] }
|
|
4396
|
+
};
|
|
4356
4397
|
}
|
|
4357
4398
|
const checkPromises = pendingRuns.map(async (r) => {
|
|
4358
4399
|
try {
|
|
@@ -4409,13 +4450,10 @@ async function getInboxItems(request, reply) {
|
|
|
4409
4450
|
});
|
|
4410
4451
|
const results = await Promise.all(checkPromises);
|
|
4411
4452
|
const inboxItems = results.flat();
|
|
4412
|
-
inboxItems.sort(
|
|
4413
|
-
(a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
|
|
4414
|
-
);
|
|
4415
4453
|
return {
|
|
4416
4454
|
success: true,
|
|
4417
4455
|
message: "Successfully retrieved inbox items",
|
|
4418
|
-
data: { records: inboxItems }
|
|
4456
|
+
data: paged ? { records: inboxItems, total, page, pageSize } : { records: inboxItems }
|
|
4419
4457
|
};
|
|
4420
4458
|
} catch (error) {
|
|
4421
4459
|
request.log.error(error, "Failed to get inbox items");
|
|
@@ -4648,6 +4686,54 @@ async function replyInboxTask(request, reply) {
|
|
|
4648
4686
|
});
|
|
4649
4687
|
}
|
|
4650
4688
|
}
|
|
4689
|
+
async function abortWorkflowRun(request, reply) {
|
|
4690
|
+
try {
|
|
4691
|
+
const { runId } = request.params;
|
|
4692
|
+
const tenantId = getTenantId7(request);
|
|
4693
|
+
const store2 = getTrackingStore();
|
|
4694
|
+
if (!store2) {
|
|
4695
|
+
return reply.status(404).send({
|
|
4696
|
+
success: false,
|
|
4697
|
+
message: "No workflow tracking store configured"
|
|
4698
|
+
});
|
|
4699
|
+
}
|
|
4700
|
+
const run = await store2.getWorkflowRun(runId);
|
|
4701
|
+
if (!run) {
|
|
4702
|
+
return reply.status(404).send({
|
|
4703
|
+
success: false,
|
|
4704
|
+
message: "Workflow run not found"
|
|
4705
|
+
});
|
|
4706
|
+
}
|
|
4707
|
+
await store2.updateWorkflowRun(runId, {
|
|
4708
|
+
status: "cancelled",
|
|
4709
|
+
errorMessage: "Aborted by user",
|
|
4710
|
+
completedAt: /* @__PURE__ */ new Date()
|
|
4711
|
+
}).catch(() => {
|
|
4712
|
+
});
|
|
4713
|
+
const workspace_id = request.headers["x-workspace-id"];
|
|
4714
|
+
const project_id = request.headers["x-project-id"];
|
|
4715
|
+
const agent = import_core15.agentInstanceManager.getAgent({
|
|
4716
|
+
assistant_id: run.assistantId,
|
|
4717
|
+
thread_id: run.threadId,
|
|
4718
|
+
tenant_id: tenantId,
|
|
4719
|
+
workspace_id,
|
|
4720
|
+
project_id
|
|
4721
|
+
});
|
|
4722
|
+
await agent.abort();
|
|
4723
|
+
(0, import_core15.abortWorkflowRun)(runId);
|
|
4724
|
+
return reply.status(200).send({
|
|
4725
|
+
success: true,
|
|
4726
|
+
message: "Workflow aborted",
|
|
4727
|
+
data: { runId, assistantId: run.assistantId, threadId: run.threadId }
|
|
4728
|
+
});
|
|
4729
|
+
} catch (error) {
|
|
4730
|
+
request.log.error(error, "Failed to abort workflow run");
|
|
4731
|
+
return reply.status(500).send({
|
|
4732
|
+
success: false,
|
|
4733
|
+
message: `Abort failed: ${error.message}`
|
|
4734
|
+
});
|
|
4735
|
+
}
|
|
4736
|
+
}
|
|
4651
4737
|
|
|
4652
4738
|
// src/controllers/personal-assistant.ts
|
|
4653
4739
|
var import_core16 = require("@axiom-lattice/core");
|
|
@@ -4911,11 +4997,339 @@ async function completeTask(request, reply) {
|
|
|
4911
4997
|
}
|
|
4912
4998
|
}
|
|
4913
4999
|
|
|
4914
|
-
// src/
|
|
5000
|
+
// src/services/ExportImportService.ts
|
|
4915
5001
|
var import_core18 = require("@axiom-lattice/core");
|
|
5002
|
+
var import_crypto4 = require("crypto");
|
|
5003
|
+
var exportJobs = /* @__PURE__ */ new Map();
|
|
5004
|
+
var JOB_TTL_MS = 60 * 60 * 1e3;
|
|
5005
|
+
function cleanExpiredJobs() {
|
|
5006
|
+
const now = Date.now();
|
|
5007
|
+
for (const [id, entry] of exportJobs) {
|
|
5008
|
+
if (now - entry.createdAt > JOB_TTL_MS) {
|
|
5009
|
+
exportJobs.delete(id);
|
|
5010
|
+
}
|
|
5011
|
+
}
|
|
5012
|
+
}
|
|
5013
|
+
var ExportImportService = class {
|
|
5014
|
+
constructor() {
|
|
5015
|
+
this.registry = import_core18.ExportableEntityRegistry.getInstance();
|
|
5016
|
+
}
|
|
5017
|
+
/**
|
|
5018
|
+
* Preview an export: check which types would be auto-included, which dependencies are missing.
|
|
5019
|
+
*/
|
|
5020
|
+
async exportPreview(tenantId, selectedTypes) {
|
|
5021
|
+
const allDefs = this.registry.getAll();
|
|
5022
|
+
const expanded = import_core18.DependencyResolver.expandCascade(allDefs, selectedTypes);
|
|
5023
|
+
const cascadeAdditions = expanded.filter((t) => !selectedTypes.includes(t));
|
|
5024
|
+
const deps = import_core18.DependencyResolver.computeDependencies(allDefs, expanded);
|
|
5025
|
+
const registeredTypes = new Set(allDefs.map((d) => d.entityType));
|
|
5026
|
+
const missingDependencies = deps.missing.filter((t) => registeredTypes.has(t));
|
|
5027
|
+
return { missingDependencies, cascadeAdditions };
|
|
5028
|
+
}
|
|
5029
|
+
/**
|
|
5030
|
+
* Generate a full ExportBundle for the given tenant and entity types.
|
|
5031
|
+
* Stores the bundle in-memory and returns a jobId for download.
|
|
5032
|
+
*/
|
|
5033
|
+
async export(tenantId, entityTypes, entityIds) {
|
|
5034
|
+
const allDefs = this.registry.getAll();
|
|
5035
|
+
const expanded = import_core18.DependencyResolver.expandCascade(allDefs, entityTypes);
|
|
5036
|
+
const finalTypes = [.../* @__PURE__ */ new Set([...expanded, ...entityTypes])];
|
|
5037
|
+
const dependencyOrder = import_core18.DependencyResolver.resolveOrder(
|
|
5038
|
+
finalTypes.map((t) => this.registry.get(t))
|
|
5039
|
+
);
|
|
5040
|
+
const entities = {};
|
|
5041
|
+
let exportCounter = 0;
|
|
5042
|
+
for (const type of dependencyOrder) {
|
|
5043
|
+
const def = this.registry.get(type);
|
|
5044
|
+
let raw = await def.listForExport(tenantId);
|
|
5045
|
+
if (entityIds && entityIds[type] && entityIds[type].length > 0) {
|
|
5046
|
+
const idSet = new Set(entityIds[type]);
|
|
5047
|
+
raw = raw.filter((e) => idSet.has(e.data.id));
|
|
5048
|
+
}
|
|
5049
|
+
entities[type] = raw.map((e) => ({
|
|
5050
|
+
...e,
|
|
5051
|
+
_exportId: `exp-${type}-${String(++exportCounter).padStart(3, "0")}`,
|
|
5052
|
+
data: this.sanitizeEntityData(e.data)
|
|
5053
|
+
}));
|
|
5054
|
+
}
|
|
5055
|
+
const rawIdToExportId = /* @__PURE__ */ new Map();
|
|
5056
|
+
for (const [, entityList] of Object.entries(entities)) {
|
|
5057
|
+
for (const entity of entityList) {
|
|
5058
|
+
const rawId = entity.data.id;
|
|
5059
|
+
if (rawId) {
|
|
5060
|
+
rawIdToExportId.set(rawId, entity._exportId);
|
|
5061
|
+
}
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
for (const [type, entityList] of Object.entries(entities)) {
|
|
5065
|
+
const def = this.registry.get(type);
|
|
5066
|
+
const refFields = def.referenceFields || {};
|
|
5067
|
+
for (const entity of entityList) {
|
|
5068
|
+
for (const [fieldName, refEntityType] of Object.entries(refFields)) {
|
|
5069
|
+
const rawValue = entity.data[fieldName];
|
|
5070
|
+
if (typeof rawValue === "string" && rawValue) {
|
|
5071
|
+
const exportId = rawIdToExportId.get(rawValue);
|
|
5072
|
+
if (exportId) {
|
|
5073
|
+
entity.data[fieldName] = `@${refEntityType}/${exportId}`;
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5076
|
+
}
|
|
5077
|
+
}
|
|
5078
|
+
}
|
|
5079
|
+
const bundle = {
|
|
5080
|
+
version: 1,
|
|
5081
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5082
|
+
sourceTenantId: tenantId,
|
|
5083
|
+
entities,
|
|
5084
|
+
dependencyOrder,
|
|
5085
|
+
_warning: "This file contains plaintext secrets (passwords, API keys, tokens). Store it securely and delete after import."
|
|
5086
|
+
};
|
|
5087
|
+
const jobId = (0, import_crypto4.randomUUID)();
|
|
5088
|
+
exportJobs.set(jobId, { bundle, tenantId, createdAt: Date.now() });
|
|
5089
|
+
return { jobId, bundle };
|
|
5090
|
+
}
|
|
5091
|
+
/**
|
|
5092
|
+
* Retrieve a previously generated export bundle by jobId with tenant validation.
|
|
5093
|
+
*/
|
|
5094
|
+
getExportJob(jobId, tenantId) {
|
|
5095
|
+
cleanExpiredJobs();
|
|
5096
|
+
const entry = exportJobs.get(jobId);
|
|
5097
|
+
if (!entry || entry.tenantId !== tenantId) return void 0;
|
|
5098
|
+
return entry.bundle;
|
|
5099
|
+
}
|
|
5100
|
+
/**
|
|
5101
|
+
* Preview import: validate bundle and detect conflicts.
|
|
5102
|
+
*/
|
|
5103
|
+
async previewImport(tenantId, bundle) {
|
|
5104
|
+
this.validateBundle(bundle);
|
|
5105
|
+
const allConflicts = [];
|
|
5106
|
+
const allInsertions = [];
|
|
5107
|
+
const allErrors = [];
|
|
5108
|
+
for (const [entityType, entities] of Object.entries(bundle.entities)) {
|
|
5109
|
+
if (entities.length === 0) continue;
|
|
5110
|
+
try {
|
|
5111
|
+
const def = this.registry.get(entityType);
|
|
5112
|
+
const result = await def.previewImport(tenantId, entities);
|
|
5113
|
+
allConflicts.push(...result.conflicts);
|
|
5114
|
+
allInsertions.push(...result.insertions);
|
|
5115
|
+
allErrors.push(...result.errors);
|
|
5116
|
+
} catch (err) {
|
|
5117
|
+
for (const entity of entities) {
|
|
5118
|
+
allErrors.push({
|
|
5119
|
+
_exportId: entity._exportId,
|
|
5120
|
+
entityType,
|
|
5121
|
+
error: `Preview failed: ${err.message}`
|
|
5122
|
+
});
|
|
5123
|
+
}
|
|
5124
|
+
}
|
|
5125
|
+
}
|
|
5126
|
+
return { conflicts: allConflicts, insertions: allInsertions, errors: allErrors };
|
|
5127
|
+
}
|
|
5128
|
+
/**
|
|
5129
|
+
* Apply import: create entities in dependency order with ID remapping.
|
|
5130
|
+
*/
|
|
5131
|
+
async applyImport(tenantId, bundle, resolutions) {
|
|
5132
|
+
this.validateBundle(bundle);
|
|
5133
|
+
const results = [];
|
|
5134
|
+
const idMap = {};
|
|
5135
|
+
const skillIdRemap = {};
|
|
5136
|
+
for (const entityType of bundle.dependencyOrder) {
|
|
5137
|
+
const entities = bundle.entities[entityType];
|
|
5138
|
+
if (!entities || entities.length === 0) continue;
|
|
5139
|
+
const def = this.registry.get(entityType);
|
|
5140
|
+
const remapper = new import_core18.IdRemapper(idMap);
|
|
5141
|
+
for (const entity of entities) {
|
|
5142
|
+
const resolution = resolutions[entity._exportId];
|
|
5143
|
+
if (resolution?.action === "skip") {
|
|
5144
|
+
results.push({ _exportId: entity._exportId, entityType, status: "skipped" });
|
|
5145
|
+
continue;
|
|
5146
|
+
}
|
|
5147
|
+
try {
|
|
5148
|
+
const remappedData = remapper.remapReferences(entity.data);
|
|
5149
|
+
if (entityType === "agent" && Object.keys(skillIdRemap).length > 0) {
|
|
5150
|
+
const skillRemapper = new import_core18.IdRemapper({});
|
|
5151
|
+
remappedData.graphDefinition = skillRemapper.remapSkillIds(
|
|
5152
|
+
remappedData.graphDefinition || {},
|
|
5153
|
+
skillIdRemap
|
|
5154
|
+
);
|
|
5155
|
+
}
|
|
5156
|
+
if (resolution?.action === "rename" && resolution.newId) {
|
|
5157
|
+
remappedData.id = resolution.newId;
|
|
5158
|
+
}
|
|
5159
|
+
const entityWithRemappedData = { ...entity, data: remappedData };
|
|
5160
|
+
const { newId } = await def.applyImport(
|
|
5161
|
+
tenantId,
|
|
5162
|
+
entityWithRemappedData,
|
|
5163
|
+
resolution ?? { _exportId: entity._exportId, action: "overwrite" }
|
|
5164
|
+
);
|
|
5165
|
+
if (newId) {
|
|
5166
|
+
idMap[entity._exportId] = newId;
|
|
5167
|
+
if (entityType === "skill" && newId) {
|
|
5168
|
+
const oldSkillId = remappedData.id;
|
|
5169
|
+
if (oldSkillId !== newId) {
|
|
5170
|
+
skillIdRemap[oldSkillId] = newId;
|
|
5171
|
+
}
|
|
5172
|
+
}
|
|
5173
|
+
results.push({
|
|
5174
|
+
_exportId: entity._exportId,
|
|
5175
|
+
entityType,
|
|
5176
|
+
status: resolution?.action === "overwrite" ? "updated" : "created",
|
|
5177
|
+
newId
|
|
5178
|
+
});
|
|
5179
|
+
}
|
|
5180
|
+
} catch (err) {
|
|
5181
|
+
results.push({
|
|
5182
|
+
_exportId: entity._exportId,
|
|
5183
|
+
entityType,
|
|
5184
|
+
status: "failed",
|
|
5185
|
+
error: err.message
|
|
5186
|
+
});
|
|
5187
|
+
}
|
|
5188
|
+
}
|
|
5189
|
+
}
|
|
5190
|
+
return { results, idMap };
|
|
5191
|
+
}
|
|
5192
|
+
/**
|
|
5193
|
+
* List all registered exportable types (for frontend).
|
|
5194
|
+
*/
|
|
5195
|
+
listExportableTypes() {
|
|
5196
|
+
return this.registry.listTypes();
|
|
5197
|
+
}
|
|
5198
|
+
validateBundle(bundle) {
|
|
5199
|
+
if (bundle.version !== 1) {
|
|
5200
|
+
throw new Error(`Unsupported bundle version: ${bundle.version}. Expected: 1`);
|
|
5201
|
+
}
|
|
5202
|
+
if (!bundle.entities || typeof bundle.entities !== "object") {
|
|
5203
|
+
throw new Error("Invalid bundle: missing entities");
|
|
5204
|
+
}
|
|
5205
|
+
if (!Array.isArray(bundle.dependencyOrder)) {
|
|
5206
|
+
throw new Error("Invalid bundle: missing dependencyOrder");
|
|
5207
|
+
}
|
|
5208
|
+
}
|
|
5209
|
+
sanitizeEntityData(data) {
|
|
5210
|
+
const sanitized = { ...data };
|
|
5211
|
+
delete sanitized.tenantId;
|
|
5212
|
+
delete sanitized.createdAt;
|
|
5213
|
+
delete sanitized.updatedAt;
|
|
5214
|
+
return sanitized;
|
|
5215
|
+
}
|
|
5216
|
+
};
|
|
5217
|
+
|
|
5218
|
+
// src/controllers/export-import.ts
|
|
5219
|
+
var import_core19 = require("@axiom-lattice/core");
|
|
5220
|
+
var service = new ExportImportService();
|
|
5221
|
+
function getTenantId10(request) {
|
|
5222
|
+
return request.user?.tenantId || request.headers["x-tenant-id"] || "default";
|
|
5223
|
+
}
|
|
5224
|
+
async function getExportableTypes(_request, reply) {
|
|
5225
|
+
const types = service.listExportableTypes();
|
|
5226
|
+
return reply.send({ success: true, data: types });
|
|
5227
|
+
}
|
|
5228
|
+
async function exportConfig(request, reply) {
|
|
5229
|
+
const tenantId = getTenantId10(request) || request.params.tenantId;
|
|
5230
|
+
const { entityTypes, entityIds } = request.body;
|
|
5231
|
+
if (!Array.isArray(entityTypes) || entityTypes.length === 0) {
|
|
5232
|
+
return reply.status(400).send({ success: false, message: "entityTypes must be a non-empty array" });
|
|
5233
|
+
}
|
|
5234
|
+
const preview = await service.exportPreview(tenantId, entityTypes);
|
|
5235
|
+
if (preview.missingDependencies.length > 0 || preview.cascadeAdditions.length > 0) {
|
|
5236
|
+
return reply.send({
|
|
5237
|
+
success: true,
|
|
5238
|
+
data: {
|
|
5239
|
+
needsConfirmation: true,
|
|
5240
|
+
missingDependencies: preview.missingDependencies,
|
|
5241
|
+
cascadeAdditions: preview.cascadeAdditions
|
|
5242
|
+
}
|
|
5243
|
+
});
|
|
5244
|
+
}
|
|
5245
|
+
const { jobId, bundle } = await service.export(tenantId, entityTypes, entityIds);
|
|
5246
|
+
return reply.send({
|
|
5247
|
+
success: true,
|
|
5248
|
+
data: {
|
|
5249
|
+
jobId,
|
|
5250
|
+
summary: Object.fromEntries(
|
|
5251
|
+
Object.entries(bundle.entities).map(([type, entities]) => [type, entities.length])
|
|
5252
|
+
)
|
|
5253
|
+
}
|
|
5254
|
+
});
|
|
5255
|
+
}
|
|
5256
|
+
async function exportConfigConfirm(request, reply) {
|
|
5257
|
+
const tenantId = getTenantId10(request) || request.params.tenantId;
|
|
5258
|
+
const { entityTypes, entityIds } = request.body;
|
|
5259
|
+
const { jobId, bundle } = await service.export(tenantId, entityTypes, entityIds);
|
|
5260
|
+
return reply.send({
|
|
5261
|
+
success: true,
|
|
5262
|
+
data: {
|
|
5263
|
+
jobId,
|
|
5264
|
+
summary: Object.fromEntries(
|
|
5265
|
+
Object.entries(bundle.entities).map(([type, entities]) => [type, entities.length])
|
|
5266
|
+
)
|
|
5267
|
+
}
|
|
5268
|
+
});
|
|
5269
|
+
}
|
|
5270
|
+
async function previewEntities(request, reply) {
|
|
5271
|
+
const tenantId = getTenantId10(request) || request.params.tenantId;
|
|
5272
|
+
const { entityTypes } = request.body;
|
|
5273
|
+
try {
|
|
5274
|
+
const registry = import_core19.ExportableEntityRegistry.getInstance();
|
|
5275
|
+
const result = {};
|
|
5276
|
+
for (const type of entityTypes) {
|
|
5277
|
+
const def = registry.get(type);
|
|
5278
|
+
const entities = await def.listForExport(tenantId);
|
|
5279
|
+
result[type] = entities.map((e) => ({
|
|
5280
|
+
id: e.data.id,
|
|
5281
|
+
name: e.data.name || e.data.id,
|
|
5282
|
+
description: e.data.description
|
|
5283
|
+
}));
|
|
5284
|
+
}
|
|
5285
|
+
return reply.send({ success: true, data: result });
|
|
5286
|
+
} catch (err) {
|
|
5287
|
+
return reply.status(400).send({ success: false, message: err.message });
|
|
5288
|
+
}
|
|
5289
|
+
}
|
|
5290
|
+
async function downloadExport(request, reply) {
|
|
5291
|
+
const tenantId = getTenantId10(request) || request.params.tenantId;
|
|
5292
|
+
const bundle = service.getExportJob(request.params.jobId, tenantId);
|
|
5293
|
+
if (!bundle) {
|
|
5294
|
+
return reply.status(404).send({ success: false, message: "Export job not found or expired" });
|
|
5295
|
+
}
|
|
5296
|
+
return reply.header("Content-Type", "application/json").header("Content-Disposition", `attachment; filename="tenant-export-${bundle.sourceTenantId}.json"`).send({ success: true, data: bundle });
|
|
5297
|
+
}
|
|
5298
|
+
async function importPreview(request, reply) {
|
|
5299
|
+
const tenantId = getTenantId10(request) || request.params.tenantId;
|
|
5300
|
+
const { bundle } = request.body;
|
|
5301
|
+
if (!bundle) {
|
|
5302
|
+
return reply.status(400).send({ success: false, message: "No bundle provided in request body" });
|
|
5303
|
+
}
|
|
5304
|
+
try {
|
|
5305
|
+
const preview = await service.previewImport(tenantId, bundle);
|
|
5306
|
+
return reply.send({ success: true, data: preview });
|
|
5307
|
+
} catch (err) {
|
|
5308
|
+
return reply.status(400).send({
|
|
5309
|
+
success: false,
|
|
5310
|
+
message: `Invalid export file: ${err.message}`
|
|
5311
|
+
});
|
|
5312
|
+
}
|
|
5313
|
+
}
|
|
5314
|
+
async function importApply(request, reply) {
|
|
5315
|
+
const tenantId = getTenantId10(request) || request.params.tenantId;
|
|
5316
|
+
try {
|
|
5317
|
+
const { bundle, resolutions } = request.body;
|
|
5318
|
+
const result = await service.applyImport(tenantId, bundle, resolutions);
|
|
5319
|
+
return reply.send({ success: true, data: result });
|
|
5320
|
+
} catch (err) {
|
|
5321
|
+
return reply.status(400).send({
|
|
5322
|
+
success: false,
|
|
5323
|
+
message: `Import failed: ${err.message}`
|
|
5324
|
+
});
|
|
5325
|
+
}
|
|
5326
|
+
}
|
|
5327
|
+
|
|
5328
|
+
// src/controllers/middleware-types.ts
|
|
5329
|
+
var import_core20 = require("@axiom-lattice/core");
|
|
4916
5330
|
function middlewareTypesRoutes(fastify2) {
|
|
4917
5331
|
fastify2.get("/api/middleware-types", async (_request, reply) => {
|
|
4918
|
-
const metas =
|
|
5332
|
+
const metas = import_core20.PluginRegistry.listMeta();
|
|
4919
5333
|
return reply.send(metas);
|
|
4920
5334
|
});
|
|
4921
5335
|
}
|
|
@@ -5261,7 +5675,7 @@ var getHealthSchema = {
|
|
|
5261
5675
|
};
|
|
5262
5676
|
|
|
5263
5677
|
// src/controllers/thread_status.ts
|
|
5264
|
-
var
|
|
5678
|
+
var import_core21 = require("@axiom-lattice/core");
|
|
5265
5679
|
async function removePendingMessageHandler(request, reply) {
|
|
5266
5680
|
try {
|
|
5267
5681
|
const { assistant_id, thread_id, message_id } = request.params;
|
|
@@ -5274,7 +5688,7 @@ async function removePendingMessageHandler(request, reply) {
|
|
|
5274
5688
|
if (!assistant_id) {
|
|
5275
5689
|
return reply.code(400).send({ error: "Missing assistant_id parameter" });
|
|
5276
5690
|
}
|
|
5277
|
-
const agent =
|
|
5691
|
+
const agent = import_core21.agentInstanceManager.getAgent({
|
|
5278
5692
|
assistant_id,
|
|
5279
5693
|
thread_id,
|
|
5280
5694
|
tenant_id,
|
|
@@ -5308,7 +5722,7 @@ async function removePendingMessageHandler(request, reply) {
|
|
|
5308
5722
|
}
|
|
5309
5723
|
|
|
5310
5724
|
// src/services/sandbox_service.ts
|
|
5311
|
-
var
|
|
5725
|
+
var import_core22 = require("@axiom-lattice/core");
|
|
5312
5726
|
var ERROR_HTML = `<!DOCTYPE html>
|
|
5313
5727
|
<html lang="zh-CN">
|
|
5314
5728
|
<head>
|
|
@@ -5420,7 +5834,7 @@ var ERROR_HTML = `<!DOCTYPE html>
|
|
|
5420
5834
|
</html>`;
|
|
5421
5835
|
var SandboxService = class {
|
|
5422
5836
|
getFilesystemVmIsolation(tenantId, assistantId) {
|
|
5423
|
-
const agentLattice =
|
|
5837
|
+
const agentLattice = import_core22.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
|
|
5424
5838
|
if (!agentLattice) {
|
|
5425
5839
|
return null;
|
|
5426
5840
|
}
|
|
@@ -5434,9 +5848,9 @@ var SandboxService = class {
|
|
|
5434
5848
|
computeSandboxName(assistantId, threadId, vmIsolation, tenantId, workspaceId, projectId) {
|
|
5435
5849
|
switch (vmIsolation) {
|
|
5436
5850
|
case "agent":
|
|
5437
|
-
return (0,
|
|
5851
|
+
return (0, import_core22.normalizeSandboxName)(`${tenantId ?? "default"}-${assistantId}`);
|
|
5438
5852
|
case "project":
|
|
5439
|
-
return (0,
|
|
5853
|
+
return (0, import_core22.normalizeSandboxName)(
|
|
5440
5854
|
`${tenantId ?? "default"}-${workspaceId ?? "default"}-${projectId ?? "default"}`
|
|
5441
5855
|
);
|
|
5442
5856
|
case "global":
|
|
@@ -5492,7 +5906,7 @@ var SandboxService = class {
|
|
|
5492
5906
|
var sandboxService = new SandboxService();
|
|
5493
5907
|
|
|
5494
5908
|
// src/controllers/sandbox.ts
|
|
5495
|
-
var
|
|
5909
|
+
var import_core23 = require("@axiom-lattice/core");
|
|
5496
5910
|
init_mime();
|
|
5497
5911
|
function registerSandboxProxyRoutes(app2) {
|
|
5498
5912
|
app2.post(
|
|
@@ -5507,7 +5921,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
5507
5921
|
}
|
|
5508
5922
|
const workspaceId = request.headers["x-workspace-id"];
|
|
5509
5923
|
const projectId = request.headers["x-project-id"];
|
|
5510
|
-
const sandboxManager = (0,
|
|
5924
|
+
const sandboxManager = (0, import_core23.getSandBoxManager)();
|
|
5511
5925
|
const sandbox = await sandboxManager.getSandboxFromConfig({
|
|
5512
5926
|
assistant_id: assistantId,
|
|
5513
5927
|
thread_id: threadId,
|
|
@@ -5555,7 +5969,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
5555
5969
|
}
|
|
5556
5970
|
const workspaceId = request.headers["x-workspace-id"];
|
|
5557
5971
|
const projectId = request.headers["x-project-id"];
|
|
5558
|
-
const sandboxManager = (0,
|
|
5972
|
+
const sandboxManager = (0, import_core23.getSandBoxManager)();
|
|
5559
5973
|
const sandbox = await sandboxManager.getSandboxFromConfig({
|
|
5560
5974
|
assistant_id: assistantId,
|
|
5561
5975
|
thread_id: threadId,
|
|
@@ -5588,15 +6002,15 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
5588
6002
|
// src/controllers/workspace.ts
|
|
5589
6003
|
var fs = __toESM(require("fs/promises"));
|
|
5590
6004
|
var path = __toESM(require("path"));
|
|
5591
|
-
var import_core22 = require("@axiom-lattice/core");
|
|
5592
|
-
var import_core23 = require("@axiom-lattice/core");
|
|
5593
6005
|
var import_core24 = require("@axiom-lattice/core");
|
|
6006
|
+
var import_core25 = require("@axiom-lattice/core");
|
|
6007
|
+
var import_core26 = require("@axiom-lattice/core");
|
|
5594
6008
|
var import_uuid3 = require("uuid");
|
|
5595
6009
|
init_mime();
|
|
5596
6010
|
var WorkspaceController = class {
|
|
5597
6011
|
constructor() {
|
|
5598
|
-
this.workspaceStore = (0,
|
|
5599
|
-
this.projectStore = (0,
|
|
6012
|
+
this.workspaceStore = (0, import_core24.getStoreLattice)("default", "workspace").store;
|
|
6013
|
+
this.projectStore = (0, import_core24.getStoreLattice)("default", "project").store;
|
|
5600
6014
|
}
|
|
5601
6015
|
getTenantId(request) {
|
|
5602
6016
|
const userTenantId = request.user?.tenantId;
|
|
@@ -5730,7 +6144,7 @@ var WorkspaceController = class {
|
|
|
5730
6144
|
}
|
|
5731
6145
|
console.log(`[getBackend] storageType=${workspace.storageType} filePath=${filePath}`);
|
|
5732
6146
|
if (workspace.storageType === "sandbox") {
|
|
5733
|
-
const sandboxManager = (0,
|
|
6147
|
+
const sandboxManager = (0, import_core26.getSandBoxManager)();
|
|
5734
6148
|
const volumeConfig = {
|
|
5735
6149
|
assistant_id: assistantId || "",
|
|
5736
6150
|
thread_id: "",
|
|
@@ -5748,7 +6162,7 @@ var WorkspaceController = class {
|
|
|
5748
6162
|
const sandbox = await sandboxManager.getSandboxFromConfig(volumeConfig);
|
|
5749
6163
|
console.log(`[getBackend] sandbox acquired, name=${sandbox.name || "unknown"}`);
|
|
5750
6164
|
return {
|
|
5751
|
-
backend: new
|
|
6165
|
+
backend: new import_core25.SandboxFilesystem({
|
|
5752
6166
|
sandboxInstance: sandbox
|
|
5753
6167
|
}),
|
|
5754
6168
|
workspace
|
|
@@ -5756,7 +6170,7 @@ var WorkspaceController = class {
|
|
|
5756
6170
|
} else {
|
|
5757
6171
|
console.log(`[getBackend] using FilesystemBackend rootDir=/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`);
|
|
5758
6172
|
return {
|
|
5759
|
-
backend: new
|
|
6173
|
+
backend: new import_core25.FilesystemBackend({
|
|
5760
6174
|
rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
|
|
5761
6175
|
virtualMode: true
|
|
5762
6176
|
}),
|
|
@@ -5808,7 +6222,7 @@ var WorkspaceController = class {
|
|
|
5808
6222
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId, assistantId);
|
|
5809
6223
|
const resolvedPath = filePath;
|
|
5810
6224
|
if (workspace.storageType === "sandbox") {
|
|
5811
|
-
const sandboxManager = (0,
|
|
6225
|
+
const sandboxManager = (0, import_core26.getSandBoxManager)();
|
|
5812
6226
|
const volumeConfig = {
|
|
5813
6227
|
assistant_id: assistantId || "",
|
|
5814
6228
|
thread_id: "",
|
|
@@ -5862,7 +6276,7 @@ var WorkspaceController = class {
|
|
|
5862
6276
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId, assistantId);
|
|
5863
6277
|
const resolvedPath = filePath;
|
|
5864
6278
|
if (workspace.storageType === "sandbox") {
|
|
5865
|
-
const sandboxManager = (0,
|
|
6279
|
+
const sandboxManager = (0, import_core26.getSandBoxManager)();
|
|
5866
6280
|
const volumeConfig = {
|
|
5867
6281
|
assistant_id: assistantId || "",
|
|
5868
6282
|
thread_id: "",
|
|
@@ -6003,7 +6417,7 @@ var WorkspaceController = class {
|
|
|
6003
6417
|
return reply.status(400).send({ success: false, error: "Invalid path parameter" });
|
|
6004
6418
|
}
|
|
6005
6419
|
if (workspace.storageType === "sandbox") {
|
|
6006
|
-
const sandboxManager = (0,
|
|
6420
|
+
const sandboxManager = (0, import_core26.getSandBoxManager)();
|
|
6007
6421
|
const volumeConfig = {
|
|
6008
6422
|
assistant_id: assistantId || "",
|
|
6009
6423
|
thread_id: "",
|
|
@@ -6111,9 +6525,9 @@ function registerWorkspaceRoutes(app2) {
|
|
|
6111
6525
|
}
|
|
6112
6526
|
|
|
6113
6527
|
// src/controllers/database-configs.ts
|
|
6114
|
-
var
|
|
6115
|
-
var
|
|
6116
|
-
function
|
|
6528
|
+
var import_core27 = require("@axiom-lattice/core");
|
|
6529
|
+
var import_crypto5 = require("crypto");
|
|
6530
|
+
function getTenantId11(request) {
|
|
6117
6531
|
const userTenantId = request.user?.tenantId;
|
|
6118
6532
|
if (userTenantId) {
|
|
6119
6533
|
return userTenantId;
|
|
@@ -6121,9 +6535,9 @@ function getTenantId10(request) {
|
|
|
6121
6535
|
return request.headers["x-tenant-id"] || "default";
|
|
6122
6536
|
}
|
|
6123
6537
|
async function getDatabaseConfigList(request, reply) {
|
|
6124
|
-
const tenantId =
|
|
6538
|
+
const tenantId = getTenantId11(request);
|
|
6125
6539
|
try {
|
|
6126
|
-
const storeLattice = (0,
|
|
6540
|
+
const storeLattice = (0, import_core27.getStoreLattice)("default", "database");
|
|
6127
6541
|
const store2 = storeLattice.store;
|
|
6128
6542
|
const configs = await store2.getAllConfigs(tenantId);
|
|
6129
6543
|
console.log("Backend: getAllConfigs returned:", configs);
|
|
@@ -6151,10 +6565,10 @@ async function getDatabaseConfigList(request, reply) {
|
|
|
6151
6565
|
}
|
|
6152
6566
|
}
|
|
6153
6567
|
async function getDatabaseConfig(request, reply) {
|
|
6154
|
-
const tenantId =
|
|
6568
|
+
const tenantId = getTenantId11(request);
|
|
6155
6569
|
const { key } = request.params;
|
|
6156
6570
|
try {
|
|
6157
|
-
const storeLattice = (0,
|
|
6571
|
+
const storeLattice = (0, import_core27.getStoreLattice)("default", "database");
|
|
6158
6572
|
const store2 = storeLattice.store;
|
|
6159
6573
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
6160
6574
|
if (!config) {
|
|
@@ -6177,10 +6591,10 @@ async function getDatabaseConfig(request, reply) {
|
|
|
6177
6591
|
}
|
|
6178
6592
|
}
|
|
6179
6593
|
async function createDatabaseConfig(request, reply) {
|
|
6180
|
-
const tenantId =
|
|
6594
|
+
const tenantId = getTenantId11(request);
|
|
6181
6595
|
const body = request.body;
|
|
6182
6596
|
try {
|
|
6183
|
-
const storeLattice = (0,
|
|
6597
|
+
const storeLattice = (0, import_core27.getStoreLattice)("default", "database");
|
|
6184
6598
|
const store2 = storeLattice.store;
|
|
6185
6599
|
const existing = await store2.getConfigByKey(tenantId, body.key);
|
|
6186
6600
|
if (existing) {
|
|
@@ -6190,10 +6604,10 @@ async function createDatabaseConfig(request, reply) {
|
|
|
6190
6604
|
message: "Database configuration with this key already exists"
|
|
6191
6605
|
};
|
|
6192
6606
|
}
|
|
6193
|
-
const id = body.id || (0,
|
|
6607
|
+
const id = body.id || (0, import_crypto5.randomUUID)();
|
|
6194
6608
|
const config = await store2.createConfig(tenantId, id, body);
|
|
6195
6609
|
try {
|
|
6196
|
-
|
|
6610
|
+
import_core27.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
|
|
6197
6611
|
} catch (error) {
|
|
6198
6612
|
console.warn("Failed to auto-register database:", error);
|
|
6199
6613
|
}
|
|
@@ -6212,11 +6626,11 @@ async function createDatabaseConfig(request, reply) {
|
|
|
6212
6626
|
}
|
|
6213
6627
|
}
|
|
6214
6628
|
async function updateDatabaseConfig(request, reply) {
|
|
6215
|
-
const tenantId =
|
|
6629
|
+
const tenantId = getTenantId11(request);
|
|
6216
6630
|
const { key } = request.params;
|
|
6217
6631
|
const updates = request.body;
|
|
6218
6632
|
try {
|
|
6219
|
-
const storeLattice = (0,
|
|
6633
|
+
const storeLattice = (0, import_core27.getStoreLattice)("default", "database");
|
|
6220
6634
|
const store2 = storeLattice.store;
|
|
6221
6635
|
const existing = await store2.getConfigByKey(tenantId, key);
|
|
6222
6636
|
if (!existing) {
|
|
@@ -6235,7 +6649,7 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
6235
6649
|
}
|
|
6236
6650
|
if (updates.config) {
|
|
6237
6651
|
try {
|
|
6238
|
-
|
|
6652
|
+
import_core27.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
|
|
6239
6653
|
} catch (error) {
|
|
6240
6654
|
console.warn("Failed to re-register database:", error);
|
|
6241
6655
|
}
|
|
@@ -6254,10 +6668,10 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
6254
6668
|
}
|
|
6255
6669
|
}
|
|
6256
6670
|
async function deleteDatabaseConfig(request, reply) {
|
|
6257
|
-
const tenantId =
|
|
6671
|
+
const tenantId = getTenantId11(request);
|
|
6258
6672
|
const { keyOrId } = request.params;
|
|
6259
6673
|
try {
|
|
6260
|
-
const storeLattice = (0,
|
|
6674
|
+
const storeLattice = (0, import_core27.getStoreLattice)("default", "database");
|
|
6261
6675
|
const store2 = storeLattice.store;
|
|
6262
6676
|
console.log("Delete request - keyOrId:", keyOrId);
|
|
6263
6677
|
let config = await store2.getConfigByKey(tenantId, keyOrId);
|
|
@@ -6284,8 +6698,8 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
6284
6698
|
};
|
|
6285
6699
|
}
|
|
6286
6700
|
try {
|
|
6287
|
-
if (
|
|
6288
|
-
await
|
|
6701
|
+
if (import_core27.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
|
|
6702
|
+
await import_core27.sqlDatabaseManager.removeDatabase(tenantId, configKey);
|
|
6289
6703
|
}
|
|
6290
6704
|
} catch (error) {
|
|
6291
6705
|
console.warn("Failed to remove from SqlDatabaseManager:", error);
|
|
@@ -6303,10 +6717,10 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
6303
6717
|
}
|
|
6304
6718
|
}
|
|
6305
6719
|
async function testDatabaseConnection(request, reply) {
|
|
6306
|
-
const tenantId =
|
|
6720
|
+
const tenantId = getTenantId11(request);
|
|
6307
6721
|
const { key } = request.params;
|
|
6308
6722
|
try {
|
|
6309
|
-
const storeLattice = (0,
|
|
6723
|
+
const storeLattice = (0, import_core27.getStoreLattice)("default", "database");
|
|
6310
6724
|
const store2 = storeLattice.store;
|
|
6311
6725
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
6312
6726
|
if (!config) {
|
|
@@ -6317,16 +6731,16 @@ async function testDatabaseConnection(request, reply) {
|
|
|
6317
6731
|
};
|
|
6318
6732
|
}
|
|
6319
6733
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
6320
|
-
|
|
6734
|
+
import_core27.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
|
|
6321
6735
|
const startTime = Date.now();
|
|
6322
|
-
const db = await
|
|
6736
|
+
const db = await import_core27.sqlDatabaseManager.getDatabase(tenantId, testKey);
|
|
6323
6737
|
try {
|
|
6324
6738
|
await db.connect();
|
|
6325
6739
|
await db.listTables();
|
|
6326
6740
|
const latency = Date.now() - startTime;
|
|
6327
6741
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
6328
6742
|
await db.disconnect();
|
|
6329
|
-
await
|
|
6743
|
+
await import_core27.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
6330
6744
|
return {
|
|
6331
6745
|
success: true,
|
|
6332
6746
|
message: "Connection test successful",
|
|
@@ -6338,7 +6752,7 @@ async function testDatabaseConnection(request, reply) {
|
|
|
6338
6752
|
} catch (error) {
|
|
6339
6753
|
try {
|
|
6340
6754
|
await db.disconnect();
|
|
6341
|
-
await
|
|
6755
|
+
await import_core27.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
6342
6756
|
} catch {
|
|
6343
6757
|
}
|
|
6344
6758
|
return {
|
|
@@ -6390,9 +6804,9 @@ function registerDatabaseConfigRoutes(app2) {
|
|
|
6390
6804
|
}
|
|
6391
6805
|
|
|
6392
6806
|
// src/controllers/metrics-configs.ts
|
|
6393
|
-
var
|
|
6394
|
-
var
|
|
6395
|
-
function
|
|
6807
|
+
var import_core28 = require("@axiom-lattice/core");
|
|
6808
|
+
var import_crypto6 = require("crypto");
|
|
6809
|
+
function getTenantId12(request) {
|
|
6396
6810
|
const userTenantId = request.user?.tenantId;
|
|
6397
6811
|
if (userTenantId) {
|
|
6398
6812
|
return userTenantId;
|
|
@@ -6400,9 +6814,9 @@ function getTenantId11(request) {
|
|
|
6400
6814
|
return request.headers["x-tenant-id"] || "default";
|
|
6401
6815
|
}
|
|
6402
6816
|
async function getMetricsServerConfigList(request, reply) {
|
|
6403
|
-
const tenantId =
|
|
6817
|
+
const tenantId = getTenantId12(request);
|
|
6404
6818
|
try {
|
|
6405
|
-
const storeLattice = (0,
|
|
6819
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6406
6820
|
const store2 = storeLattice.store;
|
|
6407
6821
|
const configs = await store2.getAllConfigs(tenantId);
|
|
6408
6822
|
return {
|
|
@@ -6426,10 +6840,10 @@ async function getMetricsServerConfigList(request, reply) {
|
|
|
6426
6840
|
}
|
|
6427
6841
|
}
|
|
6428
6842
|
async function getMetricsServerConfig(request, reply) {
|
|
6429
|
-
const tenantId =
|
|
6843
|
+
const tenantId = getTenantId12(request);
|
|
6430
6844
|
const { key } = request.params;
|
|
6431
6845
|
try {
|
|
6432
|
-
const storeLattice = (0,
|
|
6846
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6433
6847
|
const store2 = storeLattice.store;
|
|
6434
6848
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
6435
6849
|
if (!config) {
|
|
@@ -6452,10 +6866,10 @@ async function getMetricsServerConfig(request, reply) {
|
|
|
6452
6866
|
}
|
|
6453
6867
|
}
|
|
6454
6868
|
async function createMetricsServerConfig(request, reply) {
|
|
6455
|
-
const tenantId =
|
|
6869
|
+
const tenantId = getTenantId12(request);
|
|
6456
6870
|
const body = request.body;
|
|
6457
6871
|
try {
|
|
6458
|
-
const storeLattice = (0,
|
|
6872
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6459
6873
|
const store2 = storeLattice.store;
|
|
6460
6874
|
const existing = await store2.getConfigByKey(tenantId, body.key);
|
|
6461
6875
|
if (existing) {
|
|
@@ -6472,7 +6886,7 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
6472
6886
|
message: "selectedDataSources is required for semantic metrics servers"
|
|
6473
6887
|
};
|
|
6474
6888
|
}
|
|
6475
|
-
const id = body.id || (0,
|
|
6889
|
+
const id = body.id || (0, import_crypto6.randomUUID)();
|
|
6476
6890
|
const configData = {
|
|
6477
6891
|
key: body.key,
|
|
6478
6892
|
name: body.name,
|
|
@@ -6484,7 +6898,7 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
6484
6898
|
};
|
|
6485
6899
|
const config = await store2.createConfig(tenantId, id, configData);
|
|
6486
6900
|
try {
|
|
6487
|
-
|
|
6901
|
+
import_core28.metricsServerManager.registerServer(tenantId, config.key, config.config);
|
|
6488
6902
|
} catch (error) {
|
|
6489
6903
|
console.warn("Failed to auto-register metrics server:", error);
|
|
6490
6904
|
}
|
|
@@ -6503,11 +6917,11 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
6503
6917
|
}
|
|
6504
6918
|
}
|
|
6505
6919
|
async function updateMetricsServerConfig(request, reply) {
|
|
6506
|
-
const tenantId =
|
|
6920
|
+
const tenantId = getTenantId12(request);
|
|
6507
6921
|
const { key } = request.params;
|
|
6508
6922
|
const updates = request.body;
|
|
6509
6923
|
try {
|
|
6510
|
-
const storeLattice = (0,
|
|
6924
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6511
6925
|
const store2 = storeLattice.store;
|
|
6512
6926
|
const existing = await store2.getConfigByKey(tenantId, key);
|
|
6513
6927
|
if (!existing) {
|
|
@@ -6535,7 +6949,7 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
6535
6949
|
}
|
|
6536
6950
|
if (updates.config) {
|
|
6537
6951
|
try {
|
|
6538
|
-
|
|
6952
|
+
import_core28.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
|
|
6539
6953
|
} catch (error) {
|
|
6540
6954
|
console.warn("Failed to re-register metrics server:", error);
|
|
6541
6955
|
}
|
|
@@ -6554,10 +6968,10 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
6554
6968
|
}
|
|
6555
6969
|
}
|
|
6556
6970
|
async function deleteMetricsServerConfig(request, reply) {
|
|
6557
|
-
const tenantId =
|
|
6971
|
+
const tenantId = getTenantId12(request);
|
|
6558
6972
|
const { keyOrId } = request.params;
|
|
6559
6973
|
try {
|
|
6560
|
-
const storeLattice = (0,
|
|
6974
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6561
6975
|
const store2 = storeLattice.store;
|
|
6562
6976
|
let config = await store2.getConfigByKey(tenantId, keyOrId);
|
|
6563
6977
|
let configKey = keyOrId;
|
|
@@ -6582,8 +6996,8 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
6582
6996
|
};
|
|
6583
6997
|
}
|
|
6584
6998
|
try {
|
|
6585
|
-
if (
|
|
6586
|
-
|
|
6999
|
+
if (import_core28.metricsServerManager.hasServer(tenantId, configKey)) {
|
|
7000
|
+
import_core28.metricsServerManager.removeServer(tenantId, configKey);
|
|
6587
7001
|
}
|
|
6588
7002
|
} catch (error) {
|
|
6589
7003
|
console.warn("Failed to remove from MetricsServerManager:", error);
|
|
@@ -6601,10 +7015,10 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
6601
7015
|
}
|
|
6602
7016
|
}
|
|
6603
7017
|
async function testMetricsServerConnection(request, reply) {
|
|
6604
|
-
const tenantId =
|
|
7018
|
+
const tenantId = getTenantId12(request);
|
|
6605
7019
|
const { key } = request.params;
|
|
6606
7020
|
try {
|
|
6607
|
-
const storeLattice = (0,
|
|
7021
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6608
7022
|
const store2 = storeLattice.store;
|
|
6609
7023
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
6610
7024
|
if (!config) {
|
|
@@ -6615,11 +7029,11 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
6615
7029
|
};
|
|
6616
7030
|
}
|
|
6617
7031
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
6618
|
-
|
|
7032
|
+
import_core28.metricsServerManager.registerServer(tenantId, testKey, config.config);
|
|
6619
7033
|
try {
|
|
6620
|
-
const client = await
|
|
7034
|
+
const client = await import_core28.metricsServerManager.getClient(tenantId, testKey);
|
|
6621
7035
|
const result = await client.testConnection();
|
|
6622
|
-
|
|
7036
|
+
import_core28.metricsServerManager.removeServer(tenantId, testKey);
|
|
6623
7037
|
return {
|
|
6624
7038
|
success: true,
|
|
6625
7039
|
message: result.connected ? "Connection test successful" : "Connection test failed",
|
|
@@ -6627,7 +7041,7 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
6627
7041
|
};
|
|
6628
7042
|
} catch (error) {
|
|
6629
7043
|
try {
|
|
6630
|
-
|
|
7044
|
+
import_core28.metricsServerManager.removeServer(tenantId, testKey);
|
|
6631
7045
|
} catch {
|
|
6632
7046
|
}
|
|
6633
7047
|
return {
|
|
@@ -6652,10 +7066,10 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
6652
7066
|
}
|
|
6653
7067
|
}
|
|
6654
7068
|
async function listAvailableMetrics(request, reply) {
|
|
6655
|
-
const tenantId =
|
|
7069
|
+
const tenantId = getTenantId12(request);
|
|
6656
7070
|
const { key } = request.params;
|
|
6657
7071
|
try {
|
|
6658
|
-
const storeLattice = (0,
|
|
7072
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6659
7073
|
const store2 = storeLattice.store;
|
|
6660
7074
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
6661
7075
|
if (!config) {
|
|
@@ -6665,10 +7079,10 @@ async function listAvailableMetrics(request, reply) {
|
|
|
6665
7079
|
message: "Metrics server configuration not found"
|
|
6666
7080
|
};
|
|
6667
7081
|
}
|
|
6668
|
-
if (!
|
|
6669
|
-
|
|
7082
|
+
if (!import_core28.metricsServerManager.hasServer(tenantId, key)) {
|
|
7083
|
+
import_core28.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
6670
7084
|
}
|
|
6671
|
-
const client = await
|
|
7085
|
+
const client = await import_core28.metricsServerManager.getClient(tenantId, key);
|
|
6672
7086
|
const metrics = await client.listMetrics();
|
|
6673
7087
|
return {
|
|
6674
7088
|
success: true,
|
|
@@ -6690,11 +7104,11 @@ async function listAvailableMetrics(request, reply) {
|
|
|
6690
7104
|
}
|
|
6691
7105
|
}
|
|
6692
7106
|
async function queryMetricsData(request, reply) {
|
|
6693
|
-
const tenantId =
|
|
7107
|
+
const tenantId = getTenantId12(request);
|
|
6694
7108
|
const { key } = request.params;
|
|
6695
7109
|
const { metricName, startTime, endTime, step, labels } = request.body;
|
|
6696
7110
|
try {
|
|
6697
|
-
const storeLattice = (0,
|
|
7111
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6698
7112
|
const store2 = storeLattice.store;
|
|
6699
7113
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
6700
7114
|
if (!config) {
|
|
@@ -6711,10 +7125,10 @@ async function queryMetricsData(request, reply) {
|
|
|
6711
7125
|
message: "metricName is required"
|
|
6712
7126
|
};
|
|
6713
7127
|
}
|
|
6714
|
-
if (!
|
|
6715
|
-
|
|
7128
|
+
if (!import_core28.metricsServerManager.hasServer(tenantId, key)) {
|
|
7129
|
+
import_core28.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
6716
7130
|
}
|
|
6717
|
-
const client = await
|
|
7131
|
+
const client = await import_core28.metricsServerManager.getClient(tenantId, key);
|
|
6718
7132
|
const result = await client.queryMetricData(metricName, {
|
|
6719
7133
|
startTime,
|
|
6720
7134
|
endTime,
|
|
@@ -6738,10 +7152,10 @@ async function queryMetricsData(request, reply) {
|
|
|
6738
7152
|
}
|
|
6739
7153
|
}
|
|
6740
7154
|
async function getDataSources(request, reply) {
|
|
6741
|
-
const tenantId =
|
|
7155
|
+
const tenantId = getTenantId12(request);
|
|
6742
7156
|
const { key } = request.params;
|
|
6743
7157
|
try {
|
|
6744
|
-
const storeLattice = (0,
|
|
7158
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6745
7159
|
const store2 = storeLattice.store;
|
|
6746
7160
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
6747
7161
|
if (!config) {
|
|
@@ -6759,7 +7173,7 @@ async function getDataSources(request, reply) {
|
|
|
6759
7173
|
};
|
|
6760
7174
|
}
|
|
6761
7175
|
const semanticConfig = config.config;
|
|
6762
|
-
const client = new
|
|
7176
|
+
const client = new import_core28.SemanticMetricsClient(semanticConfig);
|
|
6763
7177
|
const allDatasources = await client.getDataSources();
|
|
6764
7178
|
const selectedIds = semanticConfig.selectedDataSources || [];
|
|
6765
7179
|
const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
|
|
@@ -6779,10 +7193,10 @@ async function getDataSources(request, reply) {
|
|
|
6779
7193
|
}
|
|
6780
7194
|
}
|
|
6781
7195
|
async function getDatasourceMetrics(request, reply) {
|
|
6782
|
-
const tenantId =
|
|
7196
|
+
const tenantId = getTenantId12(request);
|
|
6783
7197
|
const { key, datasourceId } = request.params;
|
|
6784
7198
|
try {
|
|
6785
|
-
const storeLattice = (0,
|
|
7199
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6786
7200
|
const store2 = storeLattice.store;
|
|
6787
7201
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
6788
7202
|
if (!config) {
|
|
@@ -6800,7 +7214,7 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
6800
7214
|
};
|
|
6801
7215
|
}
|
|
6802
7216
|
const semanticConfig = config.config;
|
|
6803
|
-
const client = new
|
|
7217
|
+
const client = new import_core28.SemanticMetricsClient(semanticConfig);
|
|
6804
7218
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
6805
7219
|
return {
|
|
6806
7220
|
success: true,
|
|
@@ -6816,11 +7230,11 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
6816
7230
|
}
|
|
6817
7231
|
}
|
|
6818
7232
|
async function querySemanticMetrics(request, reply) {
|
|
6819
|
-
const tenantId =
|
|
7233
|
+
const tenantId = getTenantId12(request);
|
|
6820
7234
|
const { key } = request.params;
|
|
6821
7235
|
const body = request.body;
|
|
6822
7236
|
try {
|
|
6823
|
-
const storeLattice = (0,
|
|
7237
|
+
const storeLattice = (0, import_core28.getStoreLattice)("default", "metrics");
|
|
6824
7238
|
const store2 = storeLattice.store;
|
|
6825
7239
|
const config = await store2.getConfigByKey(tenantId, key);
|
|
6826
7240
|
if (!config) {
|
|
@@ -6845,7 +7259,7 @@ async function querySemanticMetrics(request, reply) {
|
|
|
6845
7259
|
};
|
|
6846
7260
|
}
|
|
6847
7261
|
const semanticConfig = config.config;
|
|
6848
|
-
const client = new
|
|
7262
|
+
const client = new import_core28.SemanticMetricsClient(semanticConfig);
|
|
6849
7263
|
const result = await client.semanticQuery(body);
|
|
6850
7264
|
const columnNames = result.columns.map((col) => col.name);
|
|
6851
7265
|
const allDataPoints = [];
|
|
@@ -6905,7 +7319,7 @@ async function testSemanticDataSources(request, reply) {
|
|
|
6905
7319
|
password: body.password,
|
|
6906
7320
|
headers: body.headers
|
|
6907
7321
|
};
|
|
6908
|
-
const client = new
|
|
7322
|
+
const client = new import_core28.SemanticMetricsClient(testConfig);
|
|
6909
7323
|
const datasources = await client.getDataSources();
|
|
6910
7324
|
return {
|
|
6911
7325
|
success: true,
|
|
@@ -6941,7 +7355,7 @@ async function testDatasourceMetrics(request, reply) {
|
|
|
6941
7355
|
password: body.password,
|
|
6942
7356
|
headers: body.headers
|
|
6943
7357
|
};
|
|
6944
|
-
const client = new
|
|
7358
|
+
const client = new import_core28.SemanticMetricsClient(testConfig);
|
|
6945
7359
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
6946
7360
|
return {
|
|
6947
7361
|
success: true,
|
|
@@ -6973,7 +7387,7 @@ function registerMetricsServerConfigRoutes(app2) {
|
|
|
6973
7387
|
}
|
|
6974
7388
|
|
|
6975
7389
|
// src/controllers/connections.ts
|
|
6976
|
-
var
|
|
7390
|
+
var import_core29 = require("@axiom-lattice/core");
|
|
6977
7391
|
var import_zod = require("zod");
|
|
6978
7392
|
var createBody = import_zod.z.object({
|
|
6979
7393
|
type: import_zod.z.string().min(1),
|
|
@@ -6987,6 +7401,10 @@ var testOrDiscoverBody = import_zod.z.object({
|
|
|
6987
7401
|
config: import_zod.z.record(import_zod.z.unknown()).optional()
|
|
6988
7402
|
});
|
|
6989
7403
|
function getTenant(request) {
|
|
7404
|
+
const userTenantId = request.user?.tenantId;
|
|
7405
|
+
if (userTenantId) {
|
|
7406
|
+
return userTenantId;
|
|
7407
|
+
}
|
|
6990
7408
|
return request.headers["x-tenant-id"] || "default";
|
|
6991
7409
|
}
|
|
6992
7410
|
function maskSecrets(config) {
|
|
@@ -7010,7 +7428,7 @@ function maskSecrets(config) {
|
|
|
7010
7428
|
}
|
|
7011
7429
|
async function resolveConfig(type, body, tenantId) {
|
|
7012
7430
|
if (body.key) {
|
|
7013
|
-
const entry = await
|
|
7431
|
+
const entry = await import_core29.ConnectionRegistry.get(type, body.key, tenantId);
|
|
7014
7432
|
if (!entry) throw { status: 404, error: `Connection "${body.key}" not found` };
|
|
7015
7433
|
return entry.config;
|
|
7016
7434
|
}
|
|
@@ -7021,7 +7439,7 @@ function connectionRoutes(fastify2) {
|
|
|
7021
7439
|
fastify2.get("/api/connections", async (request, reply) => {
|
|
7022
7440
|
const { type } = request.query;
|
|
7023
7441
|
if (!type) return reply.status(400).send({ error: "query 'type' required" });
|
|
7024
|
-
const entries = await
|
|
7442
|
+
const entries = await import_core29.ConnectionRegistry.list(type, getTenant(request));
|
|
7025
7443
|
return reply.send({
|
|
7026
7444
|
success: true,
|
|
7027
7445
|
data: { records: entries.map((e) => ({ ...e, config: maskSecrets(e.config) })), total: entries.length }
|
|
@@ -7029,7 +7447,7 @@ function connectionRoutes(fastify2) {
|
|
|
7029
7447
|
});
|
|
7030
7448
|
fastify2.post("/api/connections", async (request, reply) => {
|
|
7031
7449
|
const parsed = createBody.parse(request.body);
|
|
7032
|
-
const entry = await
|
|
7450
|
+
const entry = await import_core29.ConnectionRegistry.create({
|
|
7033
7451
|
tenantId: getTenant(request),
|
|
7034
7452
|
type: parsed.type,
|
|
7035
7453
|
key: parsed.key,
|
|
@@ -7048,7 +7466,7 @@ function connectionRoutes(fastify2) {
|
|
|
7048
7466
|
const { key } = request.params;
|
|
7049
7467
|
const body = request.body;
|
|
7050
7468
|
const tenantId = getTenant(request);
|
|
7051
|
-
const existing = await
|
|
7469
|
+
const existing = await import_core29.ConnectionRegistry.get(type, key, tenantId);
|
|
7052
7470
|
if (!existing) return reply.status(404).send({ error: "not found" });
|
|
7053
7471
|
const updates = {};
|
|
7054
7472
|
if (body.name !== void 0) updates.name = body.name;
|
|
@@ -7056,7 +7474,7 @@ function connectionRoutes(fastify2) {
|
|
|
7056
7474
|
if (body.config) {
|
|
7057
7475
|
updates.config = { ...existing.config, ...body.config };
|
|
7058
7476
|
}
|
|
7059
|
-
const entry = await
|
|
7477
|
+
const entry = await import_core29.ConnectionRegistry.update(tenantId, type, key, updates);
|
|
7060
7478
|
return reply.send({
|
|
7061
7479
|
success: true,
|
|
7062
7480
|
data: { ...entry, config: maskSecrets(entry?.config ?? {}) }
|
|
@@ -7066,13 +7484,13 @@ function connectionRoutes(fastify2) {
|
|
|
7066
7484
|
const { type } = request.query;
|
|
7067
7485
|
if (!type) return reply.status(400).send({ error: "query 'type' required" });
|
|
7068
7486
|
const { key } = request.params;
|
|
7069
|
-
const ok = await
|
|
7487
|
+
const ok = await import_core29.ConnectionRegistry.delete(getTenant(request), type, key);
|
|
7070
7488
|
return reply.send({ success: ok });
|
|
7071
7489
|
});
|
|
7072
7490
|
fastify2.post("/api/connections/test", async (request, reply) => {
|
|
7073
7491
|
const { type } = request.query;
|
|
7074
7492
|
if (!type) return reply.status(400).send({ error: "query 'type' required" });
|
|
7075
|
-
const plugin =
|
|
7493
|
+
const plugin = import_core29.PluginRegistry.get(type);
|
|
7076
7494
|
if (!plugin?.connection?.test) {
|
|
7077
7495
|
return reply.status(400).send({ error: "plugin does not support connection testing" });
|
|
7078
7496
|
}
|
|
@@ -7100,7 +7518,7 @@ function connectionRoutes(fastify2) {
|
|
|
7100
7518
|
fastify2.post("/api/connections/discover", async (request, reply) => {
|
|
7101
7519
|
const { type } = request.query;
|
|
7102
7520
|
if (!type) return reply.status(400).send({ error: "query 'type' required" });
|
|
7103
|
-
const plugin =
|
|
7521
|
+
const plugin = import_core29.PluginRegistry.get(type);
|
|
7104
7522
|
if (!plugin?.connection?.discover) {
|
|
7105
7523
|
return reply.status(400).send({ error: "plugin does not support resource discovery" });
|
|
7106
7524
|
}
|
|
@@ -7130,13 +7548,12 @@ function connectionRoutes(fastify2) {
|
|
|
7130
7548
|
init_mcp_configs();
|
|
7131
7549
|
|
|
7132
7550
|
// src/controllers/eval.ts
|
|
7133
|
-
var
|
|
7551
|
+
var import_core32 = require("@axiom-lattice/core");
|
|
7134
7552
|
var import_uuid5 = require("uuid");
|
|
7135
7553
|
|
|
7136
7554
|
// src/services/eval-runner.ts
|
|
7137
7555
|
var import_events = require("events");
|
|
7138
|
-
var
|
|
7139
|
-
var import_agent_eval = require("@axiom-lattice/agent-eval");
|
|
7556
|
+
var import_core31 = require("@axiom-lattice/core");
|
|
7140
7557
|
var import_uuid4 = require("uuid");
|
|
7141
7558
|
function mapLogs(logs) {
|
|
7142
7559
|
return logs.map((l) => ({
|
|
@@ -7158,6 +7575,11 @@ var EvalRunner = class {
|
|
|
7158
7575
|
const store2 = this.getEvalStore();
|
|
7159
7576
|
const project = await store2.getProjectById(tenantId, projectId);
|
|
7160
7577
|
if (!project) throw new Error("Project not found");
|
|
7578
|
+
for (const ctx of this.runs.values()) {
|
|
7579
|
+
if (ctx.projectId === projectId) {
|
|
7580
|
+
throw new Error("A run is already in progress for this project");
|
|
7581
|
+
}
|
|
7582
|
+
}
|
|
7161
7583
|
const existingRuns = await store2.getRunsByTenant(tenantId, { projectId, status: "running" });
|
|
7162
7584
|
if (existingRuns.length > 0) {
|
|
7163
7585
|
throw new Error("A run is already in progress for this project");
|
|
@@ -7174,7 +7596,7 @@ var EvalRunner = class {
|
|
|
7174
7596
|
caseId: c.id,
|
|
7175
7597
|
input: { message: c.inputMessage, files: c.inputFiles },
|
|
7176
7598
|
steps: c.steps,
|
|
7177
|
-
output: { type:
|
|
7599
|
+
output: { type: "message_content" },
|
|
7178
7600
|
eval: {
|
|
7179
7601
|
content_assertion: c.contentAssertion,
|
|
7180
7602
|
eval_rubrics: c.rubrics?.map((r) => ({
|
|
@@ -7186,35 +7608,32 @@ var EvalRunner = class {
|
|
|
7186
7608
|
}))
|
|
7187
7609
|
});
|
|
7188
7610
|
}
|
|
7189
|
-
const
|
|
7190
|
-
const
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
const hasCredentials = hasApiKey;
|
|
7196
|
-
let judgeModelConfig = {};
|
|
7197
|
-
if (hasModelKey) {
|
|
7198
|
-
judgeModelConfig = { modelKey: judgeCfg.modelKey };
|
|
7199
|
-
} else if (!hasCredentials) {
|
|
7200
|
-
const firstModel = import_core29.modelLatticeManager.getAllLattices()[0];
|
|
7201
|
-
if (firstModel) {
|
|
7202
|
-
judgeModelConfig = { modelKey: firstModel.key };
|
|
7203
|
-
} else {
|
|
7204
|
-
judgeModelConfig = { model: judgeCfg };
|
|
7611
|
+
const judgeCfg = project.judgeModelConfig ?? {};
|
|
7612
|
+
const judgeModelKey = judgeCfg.modelKey || "";
|
|
7613
|
+
let resolvedJudgeModelKey;
|
|
7614
|
+
if (judgeModelKey) {
|
|
7615
|
+
if (!import_core31.modelLatticeManager.hasLattice(judgeModelKey)) {
|
|
7616
|
+
throw new Error(`Judge model "${judgeModelKey}" is not registered`);
|
|
7205
7617
|
}
|
|
7618
|
+
resolvedJudgeModelKey = judgeModelKey;
|
|
7206
7619
|
} else {
|
|
7207
|
-
|
|
7620
|
+
const firstModel = import_core31.modelLatticeManager.getAllLattices()[0];
|
|
7621
|
+
if (!firstModel) {
|
|
7622
|
+
throw new Error("No model registered \u2014 cannot run eval without a judge model");
|
|
7623
|
+
}
|
|
7624
|
+
resolvedJudgeModelKey = firstModel.key;
|
|
7625
|
+
console.warn(`[eval-runner] Project "${project.name}" has no judge modelKey \u2014 falling back to first registered model "${firstModel.key}"`);
|
|
7208
7626
|
}
|
|
7627
|
+
const runId = (0, import_uuid4.v4)();
|
|
7628
|
+
const concurrency = Math.max(1, Math.floor(project.concurrency) || 3);
|
|
7629
|
+
await store2.createRun(tenantId, projectId, runId, { totalCases, concurrency });
|
|
7209
7630
|
const projectConfig = {
|
|
7210
7631
|
projectName: project.name,
|
|
7211
7632
|
version: project.version,
|
|
7212
7633
|
description: project.description,
|
|
7213
7634
|
suites: evalSuites,
|
|
7214
|
-
judge_agent_config:
|
|
7635
|
+
judge_agent_config: { modelKey: resolvedJudgeModelKey },
|
|
7215
7636
|
lattice_server_config: {
|
|
7216
|
-
base_url: project.targetServerConfig.base_url || "",
|
|
7217
|
-
api_key: project.targetServerConfig.api_key || "",
|
|
7218
7637
|
tenant_id: tenantId
|
|
7219
7638
|
},
|
|
7220
7639
|
concurrency
|
|
@@ -7258,34 +7677,38 @@ var EvalRunner = class {
|
|
|
7258
7677
|
};
|
|
7259
7678
|
const runPromise = (async () => {
|
|
7260
7679
|
try {
|
|
7261
|
-
const evalProject = new
|
|
7262
|
-
const { report } = await evalProject.runAllSuitesBatch(concurrency);
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7680
|
+
const evalProject = new import_core31.LatticeEvalProject(projectConfig, onCaseComplete);
|
|
7681
|
+
const { report } = await evalProject.runAllSuitesBatch(concurrency, abortController.signal);
|
|
7682
|
+
if (!abortController.signal.aborted) {
|
|
7683
|
+
const completedCount = stats.passed + stats.failed;
|
|
7684
|
+
await store2.updateRunStatus(tenantId, runId, {
|
|
7685
|
+
status: "completed",
|
|
7686
|
+
completedAt: /* @__PURE__ */ new Date(),
|
|
7687
|
+
passedCases: stats.passed,
|
|
7688
|
+
failedCases: stats.failed,
|
|
7689
|
+
avgScore: completedCount > 0 ? stats.totalScore / completedCount : 0
|
|
7690
|
+
});
|
|
7691
|
+
this.eventEmitter.emit(`run:${runId}`, {
|
|
7692
|
+
type: "completed",
|
|
7693
|
+
runId,
|
|
7694
|
+
data: { passed: stats.passed, failed: stats.failed, avgScore: completedCount > 0 ? stats.totalScore / completedCount : 0 }
|
|
7695
|
+
});
|
|
7696
|
+
}
|
|
7276
7697
|
return { report };
|
|
7277
7698
|
} catch (err) {
|
|
7278
7699
|
const errorMsg = err.message;
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7700
|
+
if (!abortController.signal.aborted) {
|
|
7701
|
+
await store2.updateRunStatus(tenantId, runId, {
|
|
7702
|
+
status: "failed",
|
|
7703
|
+
error: errorMsg,
|
|
7704
|
+
completedAt: /* @__PURE__ */ new Date()
|
|
7705
|
+
});
|
|
7706
|
+
this.eventEmitter.emit(`run:${runId}`, {
|
|
7707
|
+
type: "error",
|
|
7708
|
+
runId,
|
|
7709
|
+
data: { message: errorMsg }
|
|
7710
|
+
});
|
|
7711
|
+
}
|
|
7289
7712
|
throw err;
|
|
7290
7713
|
} finally {
|
|
7291
7714
|
this.runs.delete(runId);
|
|
@@ -7308,13 +7731,13 @@ var EvalRunner = class {
|
|
|
7308
7731
|
return this.runs.has(runId);
|
|
7309
7732
|
}
|
|
7310
7733
|
getEvalStore() {
|
|
7311
|
-
return (0,
|
|
7734
|
+
return (0, import_core31.getStoreLattice)("default", "eval").store;
|
|
7312
7735
|
}
|
|
7313
7736
|
};
|
|
7314
7737
|
var evalRunner = new EvalRunner();
|
|
7315
7738
|
|
|
7316
7739
|
// src/controllers/eval.ts
|
|
7317
|
-
function
|
|
7740
|
+
function getTenantId14(request) {
|
|
7318
7741
|
const userTenantId = request.user?.tenantId;
|
|
7319
7742
|
if (userTenantId) {
|
|
7320
7743
|
return userTenantId;
|
|
@@ -7322,20 +7745,35 @@ function getTenantId13(request) {
|
|
|
7322
7745
|
return request.headers["x-tenant-id"] || "default";
|
|
7323
7746
|
}
|
|
7324
7747
|
function getEvalStore() {
|
|
7325
|
-
return (0,
|
|
7748
|
+
return (0, import_core32.getStoreLattice)("default", "eval").store;
|
|
7326
7749
|
}
|
|
7327
7750
|
async function createProject(request, reply) {
|
|
7328
7751
|
try {
|
|
7329
|
-
const tenantId =
|
|
7752
|
+
const tenantId = getTenantId14(request);
|
|
7330
7753
|
const store2 = getEvalStore();
|
|
7331
7754
|
const id = (0, import_uuid5.v4)();
|
|
7332
7755
|
const data = request.body;
|
|
7756
|
+
const serverCfg = data.targetServerConfig || {};
|
|
7757
|
+
const judgeCfg = data.judgeModelConfig || {};
|
|
7758
|
+
const modelKey = judgeCfg.modelKey || "";
|
|
7759
|
+
if (modelKey) {
|
|
7760
|
+
const { modelLatticeManager: modelLatticeManager3 } = await import("@axiom-lattice/core");
|
|
7761
|
+
if (!modelLatticeManager3.hasLattice(modelKey)) {
|
|
7762
|
+
return reply.status(400).send({ success: false, message: `Judge model "${modelKey}" is not registered` });
|
|
7763
|
+
}
|
|
7764
|
+
}
|
|
7333
7765
|
const project = await store2.createProject(tenantId, id, {
|
|
7334
7766
|
name: data.name,
|
|
7335
7767
|
description: data.description,
|
|
7336
7768
|
version: data.version,
|
|
7337
|
-
judgeModelConfig:
|
|
7338
|
-
|
|
7769
|
+
judgeModelConfig: {
|
|
7770
|
+
modelKey,
|
|
7771
|
+
displayName: judgeCfg.displayName || ""
|
|
7772
|
+
},
|
|
7773
|
+
targetServerConfig: {
|
|
7774
|
+
base_url: serverCfg.base_url || "",
|
|
7775
|
+
api_key: serverCfg.api_key || ""
|
|
7776
|
+
},
|
|
7339
7777
|
concurrency: data.concurrency ?? 1,
|
|
7340
7778
|
reportConfig: data.reportConfig
|
|
7341
7779
|
});
|
|
@@ -7351,7 +7789,7 @@ async function createProject(request, reply) {
|
|
|
7351
7789
|
}
|
|
7352
7790
|
async function listProjects(request, reply) {
|
|
7353
7791
|
try {
|
|
7354
|
-
const tenantId =
|
|
7792
|
+
const tenantId = getTenantId14(request);
|
|
7355
7793
|
const store2 = getEvalStore();
|
|
7356
7794
|
let projects = await store2.getProjectsByTenant(tenantId);
|
|
7357
7795
|
if (projects.length === 0) {
|
|
@@ -7359,7 +7797,7 @@ async function listProjects(request, reply) {
|
|
|
7359
7797
|
const { modelLatticeManager: modelLatticeManager3 } = await import("@axiom-lattice/core");
|
|
7360
7798
|
const models = modelLatticeManager3.getAllLattices();
|
|
7361
7799
|
const first = models[0];
|
|
7362
|
-
const judgeModel = first ? { modelKey: first.key } : {
|
|
7800
|
+
const judgeModel = first ? { modelKey: first.key } : {};
|
|
7363
7801
|
const host = request.hostname || "localhost";
|
|
7364
7802
|
const baseUrl = `http://${host}:${process.env.PORT || 4001}`;
|
|
7365
7803
|
await store2.createProject(tenantId, (0, import_uuid5.v4)(), {
|
|
@@ -7385,7 +7823,7 @@ async function listProjects(request, reply) {
|
|
|
7385
7823
|
}
|
|
7386
7824
|
async function getProject(request, reply) {
|
|
7387
7825
|
try {
|
|
7388
|
-
const tenantId =
|
|
7826
|
+
const tenantId = getTenantId14(request);
|
|
7389
7827
|
const store2 = getEvalStore();
|
|
7390
7828
|
const { pid } = request.params;
|
|
7391
7829
|
const project = await store2.getProjectById(tenantId, pid);
|
|
@@ -7405,14 +7843,37 @@ async function getProject(request, reply) {
|
|
|
7405
7843
|
}
|
|
7406
7844
|
async function updateProject(request, reply) {
|
|
7407
7845
|
try {
|
|
7408
|
-
const tenantId =
|
|
7846
|
+
const tenantId = getTenantId14(request);
|
|
7409
7847
|
const store2 = getEvalStore();
|
|
7410
7848
|
const { pid } = request.params;
|
|
7411
7849
|
const existing = await store2.getProjectById(tenantId, pid);
|
|
7412
7850
|
if (!existing) {
|
|
7413
7851
|
return reply.status(404).send({ success: false, message: "Project not found" });
|
|
7414
7852
|
}
|
|
7415
|
-
const
|
|
7853
|
+
const body = request.body;
|
|
7854
|
+
const updateData = { ...body };
|
|
7855
|
+
const serverCfg = body.targetServerConfig || {};
|
|
7856
|
+
if (body.targetServerConfig !== void 0) {
|
|
7857
|
+
updateData.targetServerConfig = {
|
|
7858
|
+
base_url: serverCfg.base_url || "",
|
|
7859
|
+
api_key: serverCfg.api_key || ""
|
|
7860
|
+
};
|
|
7861
|
+
}
|
|
7862
|
+
if (body.judgeModelConfig !== void 0) {
|
|
7863
|
+
const judgeCfg = body.judgeModelConfig || {};
|
|
7864
|
+
const modelKey = judgeCfg.modelKey || "";
|
|
7865
|
+
if (modelKey) {
|
|
7866
|
+
const { modelLatticeManager: modelLatticeManager3 } = await import("@axiom-lattice/core");
|
|
7867
|
+
if (!modelLatticeManager3.hasLattice(modelKey)) {
|
|
7868
|
+
return reply.status(400).send({ success: false, message: `Judge model "${modelKey}" is not registered` });
|
|
7869
|
+
}
|
|
7870
|
+
}
|
|
7871
|
+
updateData.judgeModelConfig = {
|
|
7872
|
+
modelKey,
|
|
7873
|
+
displayName: judgeCfg.displayName || ""
|
|
7874
|
+
};
|
|
7875
|
+
}
|
|
7876
|
+
const updated = await store2.updateProject(tenantId, pid, updateData);
|
|
7416
7877
|
return {
|
|
7417
7878
|
success: true,
|
|
7418
7879
|
message: "Successfully updated project",
|
|
@@ -7425,7 +7886,7 @@ async function updateProject(request, reply) {
|
|
|
7425
7886
|
}
|
|
7426
7887
|
async function deleteProject(request, reply) {
|
|
7427
7888
|
try {
|
|
7428
|
-
const tenantId =
|
|
7889
|
+
const tenantId = getTenantId14(request);
|
|
7429
7890
|
const store2 = getEvalStore();
|
|
7430
7891
|
const { pid } = request.params;
|
|
7431
7892
|
const existing = await store2.getProjectById(tenantId, pid);
|
|
@@ -7444,7 +7905,7 @@ async function deleteProject(request, reply) {
|
|
|
7444
7905
|
}
|
|
7445
7906
|
async function createSuite(request, reply) {
|
|
7446
7907
|
try {
|
|
7447
|
-
const tenantId =
|
|
7908
|
+
const tenantId = getTenantId14(request);
|
|
7448
7909
|
const store2 = getEvalStore();
|
|
7449
7910
|
const { pid } = request.params;
|
|
7450
7911
|
const project = await store2.getProjectById(tenantId, pid);
|
|
@@ -7466,7 +7927,7 @@ async function createSuite(request, reply) {
|
|
|
7466
7927
|
}
|
|
7467
7928
|
async function updateSuite(request, reply) {
|
|
7468
7929
|
try {
|
|
7469
|
-
const tenantId =
|
|
7930
|
+
const tenantId = getTenantId14(request);
|
|
7470
7931
|
const store2 = getEvalStore();
|
|
7471
7932
|
const { sid } = request.params;
|
|
7472
7933
|
const existing = await store2.getSuiteById(tenantId, sid);
|
|
@@ -7486,7 +7947,7 @@ async function updateSuite(request, reply) {
|
|
|
7486
7947
|
}
|
|
7487
7948
|
async function deleteSuite(request, reply) {
|
|
7488
7949
|
try {
|
|
7489
|
-
const tenantId =
|
|
7950
|
+
const tenantId = getTenantId14(request);
|
|
7490
7951
|
const store2 = getEvalStore();
|
|
7491
7952
|
const { sid } = request.params;
|
|
7492
7953
|
const existing = await store2.getSuiteById(tenantId, sid);
|
|
@@ -7505,7 +7966,7 @@ async function deleteSuite(request, reply) {
|
|
|
7505
7966
|
}
|
|
7506
7967
|
async function createCase(request, reply) {
|
|
7507
7968
|
try {
|
|
7508
|
-
const tenantId =
|
|
7969
|
+
const tenantId = getTenantId14(request);
|
|
7509
7970
|
const store2 = getEvalStore();
|
|
7510
7971
|
const { sid } = request.params;
|
|
7511
7972
|
const suite = await store2.getSuiteById(tenantId, sid);
|
|
@@ -7534,7 +7995,7 @@ async function createCase(request, reply) {
|
|
|
7534
7995
|
}
|
|
7535
7996
|
async function listCasesForSuite(request, reply) {
|
|
7536
7997
|
try {
|
|
7537
|
-
const tenantId =
|
|
7998
|
+
const tenantId = getTenantId14(request);
|
|
7538
7999
|
const store2 = getEvalStore();
|
|
7539
8000
|
const { sid } = request.params;
|
|
7540
8001
|
const cases = await store2.getCasesBySuite(tenantId, sid);
|
|
@@ -7550,7 +8011,7 @@ async function listCasesForSuite(request, reply) {
|
|
|
7550
8011
|
}
|
|
7551
8012
|
async function updateCase(request, reply) {
|
|
7552
8013
|
try {
|
|
7553
|
-
const tenantId =
|
|
8014
|
+
const tenantId = getTenantId14(request);
|
|
7554
8015
|
const store2 = getEvalStore();
|
|
7555
8016
|
const { cid } = request.params;
|
|
7556
8017
|
const existing = await store2.getCaseById(tenantId, cid);
|
|
@@ -7570,7 +8031,7 @@ async function updateCase(request, reply) {
|
|
|
7570
8031
|
}
|
|
7571
8032
|
async function deleteCase(request, reply) {
|
|
7572
8033
|
try {
|
|
7573
|
-
const tenantId =
|
|
8034
|
+
const tenantId = getTenantId14(request);
|
|
7574
8035
|
const store2 = getEvalStore();
|
|
7575
8036
|
const { cid } = request.params;
|
|
7576
8037
|
const existing = await store2.getCaseById(tenantId, cid);
|
|
@@ -7602,7 +8063,7 @@ function registerEvalRoutes(app2) {
|
|
|
7602
8063
|
app2.delete("/api/eval/projects/:pid/suites/:sid/cases/:cid", deleteCase);
|
|
7603
8064
|
app2.post("/api/eval/projects/:pid/runs", async (request, reply) => {
|
|
7604
8065
|
try {
|
|
7605
|
-
const tenantId =
|
|
8066
|
+
const tenantId = getTenantId14(request);
|
|
7606
8067
|
const { pid } = request.params;
|
|
7607
8068
|
const runId = await evalRunner.startRun(tenantId, pid);
|
|
7608
8069
|
reply.status(202).send({ success: true, message: "Run started", data: { run_id: runId } });
|
|
@@ -7614,7 +8075,7 @@ function registerEvalRoutes(app2) {
|
|
|
7614
8075
|
});
|
|
7615
8076
|
app2.get("/api/eval/runs", async (request, reply) => {
|
|
7616
8077
|
try {
|
|
7617
|
-
const tenantId =
|
|
8078
|
+
const tenantId = getTenantId14(request);
|
|
7618
8079
|
const query = request.query;
|
|
7619
8080
|
const runs = await getEvalStore().getRunsByTenant(tenantId, { projectId: query.project_id, status: query.status });
|
|
7620
8081
|
reply.send({ success: true, message: "Ok", data: { records: runs, total: runs.length } });
|
|
@@ -7624,7 +8085,7 @@ function registerEvalRoutes(app2) {
|
|
|
7624
8085
|
});
|
|
7625
8086
|
app2.get("/api/eval/runs/:rid", async (request, reply) => {
|
|
7626
8087
|
try {
|
|
7627
|
-
const tenantId =
|
|
8088
|
+
const tenantId = getTenantId14(request);
|
|
7628
8089
|
const { rid } = request.params;
|
|
7629
8090
|
const run = await getEvalStore().getRunById(tenantId, rid);
|
|
7630
8091
|
if (!run) return reply.status(404).send({ success: false, message: "Run not found" });
|
|
@@ -7646,7 +8107,7 @@ function registerEvalRoutes(app2) {
|
|
|
7646
8107
|
const emitter = evalRunner.getEventEmitter();
|
|
7647
8108
|
const eventKey = `run:${rid}`;
|
|
7648
8109
|
if (!evalRunner.isRunning(rid)) {
|
|
7649
|
-
const tenantId =
|
|
8110
|
+
const tenantId = getTenantId14(request);
|
|
7650
8111
|
const run = await getEvalStore().getRunById(tenantId, rid);
|
|
7651
8112
|
if (run) {
|
|
7652
8113
|
const eventType = run.status === "completed" ? "completed" : "error";
|
|
@@ -7685,7 +8146,7 @@ data: ${JSON.stringify(event.data)}
|
|
|
7685
8146
|
});
|
|
7686
8147
|
app2.delete("/api/eval/runs/:rid", async (request, reply) => {
|
|
7687
8148
|
try {
|
|
7688
|
-
const tenantId =
|
|
8149
|
+
const tenantId = getTenantId14(request);
|
|
7689
8150
|
const { rid } = request.params;
|
|
7690
8151
|
const deleted = await getEvalStore().deleteRun(tenantId, rid);
|
|
7691
8152
|
if (!deleted) return reply.status(404).send({ success: false, message: "Run not found" });
|
|
@@ -7696,7 +8157,7 @@ data: ${JSON.stringify(event.data)}
|
|
|
7696
8157
|
});
|
|
7697
8158
|
app2.get("/api/eval/reports/projects/:pid", async (request, reply) => {
|
|
7698
8159
|
try {
|
|
7699
|
-
const tenantId =
|
|
8160
|
+
const tenantId = getTenantId14(request);
|
|
7700
8161
|
const { pid } = request.params;
|
|
7701
8162
|
const report = await getEvalStore().getProjectReport(tenantId, pid);
|
|
7702
8163
|
if (!report) return reply.status(404).send({ success: false, message: "Project not found" });
|
|
@@ -7708,11 +8169,11 @@ data: ${JSON.stringify(event.data)}
|
|
|
7708
8169
|
}
|
|
7709
8170
|
|
|
7710
8171
|
// src/controllers/users.ts
|
|
7711
|
-
var
|
|
8172
|
+
var import_core33 = require("@axiom-lattice/core");
|
|
7712
8173
|
var import_uuid6 = require("uuid");
|
|
7713
8174
|
var UsersController = class {
|
|
7714
8175
|
constructor() {
|
|
7715
|
-
this.userStore = (0,
|
|
8176
|
+
this.userStore = (0, import_core33.getStoreLattice)("default", "user").store;
|
|
7716
8177
|
}
|
|
7717
8178
|
async listUsers(request, reply) {
|
|
7718
8179
|
const { email } = request.query;
|
|
@@ -7790,11 +8251,11 @@ function registerUserRoutes(app2) {
|
|
|
7790
8251
|
}
|
|
7791
8252
|
|
|
7792
8253
|
// src/controllers/tenants.ts
|
|
7793
|
-
var
|
|
8254
|
+
var import_core34 = require("@axiom-lattice/core");
|
|
7794
8255
|
var import_uuid7 = require("uuid");
|
|
7795
8256
|
var TenantsController = class {
|
|
7796
8257
|
constructor() {
|
|
7797
|
-
this.tenantStore = (0,
|
|
8258
|
+
this.tenantStore = (0, import_core34.getStoreLattice)("default", "tenant").store;
|
|
7798
8259
|
}
|
|
7799
8260
|
// ==================== Tenant CRUD ====================
|
|
7800
8261
|
async listTenants(request, reply) {
|
|
@@ -7858,7 +8319,7 @@ function registerTenantRoutes(app2) {
|
|
|
7858
8319
|
}
|
|
7859
8320
|
|
|
7860
8321
|
// src/controllers/auth.ts
|
|
7861
|
-
var
|
|
8322
|
+
var import_core35 = require("@axiom-lattice/core");
|
|
7862
8323
|
var import_uuid8 = require("uuid");
|
|
7863
8324
|
var defaultAuthConfig = {
|
|
7864
8325
|
autoApproveUsers: true,
|
|
@@ -7867,9 +8328,9 @@ var defaultAuthConfig = {
|
|
|
7867
8328
|
};
|
|
7868
8329
|
var AuthController = class {
|
|
7869
8330
|
constructor(config = {}) {
|
|
7870
|
-
this.userStore = (0,
|
|
7871
|
-
this.tenantStore = (0,
|
|
7872
|
-
this.userTenantLinkStore = (0,
|
|
8331
|
+
this.userStore = (0, import_core35.getStoreLattice)("default", "user").store;
|
|
8332
|
+
this.tenantStore = (0, import_core35.getStoreLattice)("default", "tenant").store;
|
|
8333
|
+
this.userTenantLinkStore = (0, import_core35.getStoreLattice)("default", "userTenantLink").store;
|
|
7873
8334
|
this.config = { ...defaultAuthConfig, ...config };
|
|
7874
8335
|
}
|
|
7875
8336
|
async register(request, reply) {
|
|
@@ -8027,7 +8488,7 @@ var AuthController = class {
|
|
|
8027
8488
|
const linkMeta = link?.metadata || {};
|
|
8028
8489
|
let personalAssistant = null;
|
|
8029
8490
|
if (linkMeta.personalAssistantId) {
|
|
8030
|
-
const assistantStore = (0,
|
|
8491
|
+
const assistantStore = (0, import_core35.getStoreLattice)("default", "assistant").store;
|
|
8031
8492
|
const exists = await assistantStore.hasAssistant(tenantId, linkMeta.personalAssistantId);
|
|
8032
8493
|
if (exists) {
|
|
8033
8494
|
personalAssistant = {
|
|
@@ -8447,7 +8908,7 @@ var larkChannelAdapter = {
|
|
|
8447
8908
|
};
|
|
8448
8909
|
|
|
8449
8910
|
// src/channels/lark/verification.ts
|
|
8450
|
-
var
|
|
8911
|
+
var import_crypto8 = __toESM(require("crypto"));
|
|
8451
8912
|
function parseLarkRequestBody(body, encryptKey) {
|
|
8452
8913
|
const parsed = body || {};
|
|
8453
8914
|
if (encryptKey && typeof parsed.encrypt === "string") {
|
|
@@ -8456,11 +8917,11 @@ function parseLarkRequestBody(body, encryptKey) {
|
|
|
8456
8917
|
return parsed;
|
|
8457
8918
|
}
|
|
8458
8919
|
function decryptLarkPayload(encryptKey, encryptedPayload) {
|
|
8459
|
-
const key =
|
|
8920
|
+
const key = import_crypto8.default.createHash("sha256").update(encryptKey).digest();
|
|
8460
8921
|
const buffer = Buffer.from(encryptedPayload, "base64");
|
|
8461
8922
|
const iv = buffer.subarray(0, 16);
|
|
8462
8923
|
const ciphertext = buffer.subarray(16);
|
|
8463
|
-
const decipher =
|
|
8924
|
+
const decipher = import_crypto8.default.createDecipheriv("aes-256-cbc", key, iv);
|
|
8464
8925
|
const plaintext = Buffer.concat([
|
|
8465
8926
|
decipher.update(ciphertext),
|
|
8466
8927
|
decipher.final()
|
|
@@ -8577,14 +9038,14 @@ function registerChannelRoutes(app2, dependencies) {
|
|
|
8577
9038
|
}
|
|
8578
9039
|
|
|
8579
9040
|
// src/controllers/channel-installations.ts
|
|
8580
|
-
var
|
|
9041
|
+
var import_crypto9 = require("crypto");
|
|
8581
9042
|
var _adapterRegistry;
|
|
8582
9043
|
var _router;
|
|
8583
9044
|
function setChannelControllerDeps(deps) {
|
|
8584
9045
|
_adapterRegistry = deps.adapterRegistry;
|
|
8585
9046
|
_router = deps.router;
|
|
8586
9047
|
}
|
|
8587
|
-
function
|
|
9048
|
+
function getTenantId15(request) {
|
|
8588
9049
|
const userTenantId = request.user?.tenantId;
|
|
8589
9050
|
if (userTenantId) {
|
|
8590
9051
|
return userTenantId;
|
|
@@ -8592,8 +9053,8 @@ function getTenantId14(request) {
|
|
|
8592
9053
|
return request.headers["x-tenant-id"] || "default";
|
|
8593
9054
|
}
|
|
8594
9055
|
async function getInstallationStore() {
|
|
8595
|
-
const { getStoreLattice:
|
|
8596
|
-
const store2 =
|
|
9056
|
+
const { getStoreLattice: getStoreLattice31 } = await import("@axiom-lattice/core");
|
|
9057
|
+
const store2 = getStoreLattice31("default", "channelInstallation").store;
|
|
8597
9058
|
if (store2) return store2;
|
|
8598
9059
|
const { PostgreSQLChannelInstallationStore } = await import("@axiom-lattice/pg-stores");
|
|
8599
9060
|
const databaseUrl = process.env.DATABASE_URL;
|
|
@@ -8605,7 +9066,7 @@ async function getInstallationStore() {
|
|
|
8605
9066
|
});
|
|
8606
9067
|
}
|
|
8607
9068
|
async function getChannelInstallationList(request, reply) {
|
|
8608
|
-
const tenantId =
|
|
9069
|
+
const tenantId = getTenantId15(request);
|
|
8609
9070
|
const { channel } = request.query;
|
|
8610
9071
|
try {
|
|
8611
9072
|
const store2 = await getInstallationStore();
|
|
@@ -8631,7 +9092,7 @@ async function getChannelInstallationList(request, reply) {
|
|
|
8631
9092
|
}
|
|
8632
9093
|
}
|
|
8633
9094
|
async function getChannelInstallation(request, reply) {
|
|
8634
|
-
const tenantId =
|
|
9095
|
+
const tenantId = getTenantId15(request);
|
|
8635
9096
|
const { installationId } = request.params;
|
|
8636
9097
|
try {
|
|
8637
9098
|
const store2 = await getInstallationStore();
|
|
@@ -8664,7 +9125,7 @@ async function getChannelInstallation(request, reply) {
|
|
|
8664
9125
|
}
|
|
8665
9126
|
}
|
|
8666
9127
|
async function createChannelInstallation(request, reply) {
|
|
8667
|
-
const tenantId =
|
|
9128
|
+
const tenantId = getTenantId15(request);
|
|
8668
9129
|
const body = request.body;
|
|
8669
9130
|
try {
|
|
8670
9131
|
if (!body.channel) {
|
|
@@ -8699,7 +9160,7 @@ async function createChannelInstallation(request, reply) {
|
|
|
8699
9160
|
}
|
|
8700
9161
|
}
|
|
8701
9162
|
const store2 = await getInstallationStore();
|
|
8702
|
-
const installationId = body.id || (0,
|
|
9163
|
+
const installationId = body.id || (0, import_crypto9.randomUUID)();
|
|
8703
9164
|
const installation = await store2.createInstallation(
|
|
8704
9165
|
tenantId,
|
|
8705
9166
|
installationId,
|
|
@@ -8737,7 +9198,7 @@ async function createChannelInstallation(request, reply) {
|
|
|
8737
9198
|
}
|
|
8738
9199
|
}
|
|
8739
9200
|
async function updateChannelInstallation(request, reply) {
|
|
8740
|
-
const tenantId =
|
|
9201
|
+
const tenantId = getTenantId15(request);
|
|
8741
9202
|
const { installationId } = request.params;
|
|
8742
9203
|
const body = request.body;
|
|
8743
9204
|
try {
|
|
@@ -8791,7 +9252,7 @@ async function updateChannelInstallation(request, reply) {
|
|
|
8791
9252
|
}
|
|
8792
9253
|
}
|
|
8793
9254
|
async function deleteChannelInstallation(request, reply) {
|
|
8794
|
-
const tenantId =
|
|
9255
|
+
const tenantId = getTenantId15(request);
|
|
8795
9256
|
const { installationId } = request.params;
|
|
8796
9257
|
try {
|
|
8797
9258
|
const store2 = await getInstallationStore();
|
|
@@ -8851,17 +9312,17 @@ function registerChannelInstallationRoutes(app2) {
|
|
|
8851
9312
|
}
|
|
8852
9313
|
|
|
8853
9314
|
// src/controllers/channel-bindings.ts
|
|
8854
|
-
var
|
|
8855
|
-
function
|
|
9315
|
+
var import_core36 = require("@axiom-lattice/core");
|
|
9316
|
+
function getTenantId16(request) {
|
|
8856
9317
|
const userTenantId = request.user?.tenantId;
|
|
8857
9318
|
if (userTenantId) return userTenantId;
|
|
8858
9319
|
return request.headers["x-tenant-id"] || "default";
|
|
8859
9320
|
}
|
|
8860
9321
|
async function getBindingList(request, _reply) {
|
|
8861
|
-
const tenantId =
|
|
9322
|
+
const tenantId = getTenantId16(request);
|
|
8862
9323
|
const { channel, agentId, channelInstallationId, limit, offset } = request.query;
|
|
8863
9324
|
try {
|
|
8864
|
-
const registry = (0,
|
|
9325
|
+
const registry = (0, import_core36.getBindingRegistry)();
|
|
8865
9326
|
const bindings = await registry.list({ channel, agentId, tenantId, channelInstallationId, limit, offset });
|
|
8866
9327
|
return { success: true, message: "Bindings retrieved", data: { records: bindings, total: bindings.length } };
|
|
8867
9328
|
} catch (error) {
|
|
@@ -8870,9 +9331,9 @@ async function getBindingList(request, _reply) {
|
|
|
8870
9331
|
}
|
|
8871
9332
|
}
|
|
8872
9333
|
async function getBinding(request, reply) {
|
|
8873
|
-
const tenantId =
|
|
9334
|
+
const tenantId = getTenantId16(request);
|
|
8874
9335
|
try {
|
|
8875
|
-
const registry = (0,
|
|
9336
|
+
const registry = (0, import_core36.getBindingRegistry)();
|
|
8876
9337
|
const bindings = await registry.list({ tenantId });
|
|
8877
9338
|
const binding = bindings.find((b) => b.id === request.params.id);
|
|
8878
9339
|
if (!binding || binding.tenantId !== tenantId) {
|
|
@@ -8886,9 +9347,9 @@ async function getBinding(request, reply) {
|
|
|
8886
9347
|
}
|
|
8887
9348
|
}
|
|
8888
9349
|
async function createBinding(request, reply) {
|
|
8889
|
-
const tenantId =
|
|
9350
|
+
const tenantId = getTenantId16(request);
|
|
8890
9351
|
try {
|
|
8891
|
-
const registry = (0,
|
|
9352
|
+
const registry = (0, import_core36.getBindingRegistry)();
|
|
8892
9353
|
const binding = await registry.create({ ...request.body, tenantId });
|
|
8893
9354
|
reply.status(201);
|
|
8894
9355
|
return { success: true, message: "Binding created", data: binding };
|
|
@@ -8900,8 +9361,8 @@ async function createBinding(request, reply) {
|
|
|
8900
9361
|
}
|
|
8901
9362
|
async function updateBinding(request, reply) {
|
|
8902
9363
|
try {
|
|
8903
|
-
const tenantId =
|
|
8904
|
-
const registry = (0,
|
|
9364
|
+
const tenantId = getTenantId16(request);
|
|
9365
|
+
const registry = (0, import_core36.getBindingRegistry)();
|
|
8905
9366
|
const bindings = await registry.list({ tenantId });
|
|
8906
9367
|
const existing = bindings.find((b) => b.id === request.params.id);
|
|
8907
9368
|
if (!existing || existing.tenantId !== tenantId) {
|
|
@@ -8918,8 +9379,8 @@ async function updateBinding(request, reply) {
|
|
|
8918
9379
|
}
|
|
8919
9380
|
async function deleteBinding(request, reply) {
|
|
8920
9381
|
try {
|
|
8921
|
-
const tenantId =
|
|
8922
|
-
const registry = (0,
|
|
9382
|
+
const tenantId = getTenantId16(request);
|
|
9383
|
+
const registry = (0, import_core36.getBindingRegistry)();
|
|
8923
9384
|
const bindings = await registry.list({ tenantId });
|
|
8924
9385
|
const existing = bindings.find((b) => b.id === request.params.id);
|
|
8925
9386
|
if (!existing || existing.tenantId !== tenantId) {
|
|
@@ -8935,10 +9396,10 @@ async function deleteBinding(request, reply) {
|
|
|
8935
9396
|
}
|
|
8936
9397
|
}
|
|
8937
9398
|
async function resolveBinding(request, _reply) {
|
|
8938
|
-
const tenantId =
|
|
9399
|
+
const tenantId = getTenantId16(request);
|
|
8939
9400
|
const { channel, senderId, channelInstallationId } = request.query;
|
|
8940
9401
|
try {
|
|
8941
|
-
const registry = (0,
|
|
9402
|
+
const registry = (0, import_core36.getBindingRegistry)();
|
|
8942
9403
|
const binding = await registry.resolve({ channel, senderId, channelInstallationId, tenantId });
|
|
8943
9404
|
if (!binding) {
|
|
8944
9405
|
return { success: false, message: "No binding found", data: null };
|
|
@@ -8961,8 +9422,8 @@ function registerChannelBindingRoutes(app2) {
|
|
|
8961
9422
|
}
|
|
8962
9423
|
|
|
8963
9424
|
// src/controllers/menu-items.ts
|
|
8964
|
-
var
|
|
8965
|
-
function
|
|
9425
|
+
var import_core37 = require("@axiom-lattice/core");
|
|
9426
|
+
function getTenantId17(request) {
|
|
8966
9427
|
const userTenantId = request.user?.tenantId;
|
|
8967
9428
|
if (userTenantId) return userTenantId;
|
|
8968
9429
|
return request.headers["x-tenant-id"] || "default";
|
|
@@ -8971,9 +9432,9 @@ function errorMessage(err) {
|
|
|
8971
9432
|
return err instanceof Error ? err.message : "Unexpected error";
|
|
8972
9433
|
}
|
|
8973
9434
|
async function getMenuItemList(request, _reply) {
|
|
8974
|
-
const tenantId =
|
|
9435
|
+
const tenantId = getTenantId17(request);
|
|
8975
9436
|
try {
|
|
8976
|
-
const registry = (0,
|
|
9437
|
+
const registry = (0, import_core37.getMenuRegistry)();
|
|
8977
9438
|
const items = await registry.list({ tenantId, menuTarget: request.query.menuTarget });
|
|
8978
9439
|
return { success: true, message: "Menu items retrieved", data: { records: items, total: items.length } };
|
|
8979
9440
|
} catch (error) {
|
|
@@ -8983,9 +9444,9 @@ async function getMenuItemList(request, _reply) {
|
|
|
8983
9444
|
}
|
|
8984
9445
|
}
|
|
8985
9446
|
async function getMenuItem(request, reply) {
|
|
8986
|
-
const tenantId =
|
|
9447
|
+
const tenantId = getTenantId17(request);
|
|
8987
9448
|
try {
|
|
8988
|
-
const registry = (0,
|
|
9449
|
+
const registry = (0, import_core37.getMenuRegistry)();
|
|
8989
9450
|
const item = await registry.getById(request.params.id);
|
|
8990
9451
|
if (!item || item.tenantId !== tenantId) {
|
|
8991
9452
|
reply.status(404);
|
|
@@ -9000,9 +9461,9 @@ async function getMenuItem(request, reply) {
|
|
|
9000
9461
|
}
|
|
9001
9462
|
}
|
|
9002
9463
|
async function createMenuItem(request, reply) {
|
|
9003
|
-
const tenantId =
|
|
9464
|
+
const tenantId = getTenantId17(request);
|
|
9004
9465
|
try {
|
|
9005
|
-
const registry = (0,
|
|
9466
|
+
const registry = (0, import_core37.getMenuRegistry)();
|
|
9006
9467
|
const item = await registry.create({ ...request.body, tenantId });
|
|
9007
9468
|
reply.status(201);
|
|
9008
9469
|
return { success: true, message: "Menu item created", data: item };
|
|
@@ -9015,8 +9476,8 @@ async function createMenuItem(request, reply) {
|
|
|
9015
9476
|
}
|
|
9016
9477
|
async function updateMenuItem(request, reply) {
|
|
9017
9478
|
try {
|
|
9018
|
-
const tenantId =
|
|
9019
|
-
const registry = (0,
|
|
9479
|
+
const tenantId = getTenantId17(request);
|
|
9480
|
+
const registry = (0, import_core37.getMenuRegistry)();
|
|
9020
9481
|
const existing = await registry.getById(request.params.id);
|
|
9021
9482
|
if (!existing || existing.tenantId !== tenantId) {
|
|
9022
9483
|
reply.status(404);
|
|
@@ -9033,8 +9494,8 @@ async function updateMenuItem(request, reply) {
|
|
|
9033
9494
|
}
|
|
9034
9495
|
async function deleteMenuItem(request, reply) {
|
|
9035
9496
|
try {
|
|
9036
|
-
const tenantId =
|
|
9037
|
-
const registry = (0,
|
|
9497
|
+
const tenantId = getTenantId17(request);
|
|
9498
|
+
const registry = (0, import_core37.getMenuRegistry)();
|
|
9038
9499
|
const existing = await registry.getById(request.params.id);
|
|
9039
9500
|
if (!existing || existing.tenantId !== tenantId) {
|
|
9040
9501
|
reply.status(404);
|
|
@@ -9466,11 +9927,37 @@ var registerLatticeRoutes = (app2, channelDeps) => {
|
|
|
9466
9927
|
app2.delete("/api/workflows/runs/:runId", deleteWorkflowRun);
|
|
9467
9928
|
app2.get("/api/workflows/runs/:runId/steps", getRunSteps);
|
|
9468
9929
|
app2.get("/api/workflows/runs/:runId/tasks", getRunTasks);
|
|
9930
|
+
app2.post("/api/workflows/runs/:runId/abort", abortWorkflowRun);
|
|
9469
9931
|
app2.post("/api/workflows/inbox/reply", replyInboxTask);
|
|
9470
9932
|
app2.delete(
|
|
9471
9933
|
"/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
|
|
9472
9934
|
removePendingMessageHandler
|
|
9473
9935
|
);
|
|
9936
|
+
app2.get("/api/tenants/exportable-types", getExportableTypes);
|
|
9937
|
+
app2.post(
|
|
9938
|
+
"/api/tenants/:tenantId/export",
|
|
9939
|
+
exportConfig
|
|
9940
|
+
);
|
|
9941
|
+
app2.post(
|
|
9942
|
+
"/api/tenants/:tenantId/export/confirm",
|
|
9943
|
+
exportConfigConfirm
|
|
9944
|
+
);
|
|
9945
|
+
app2.post(
|
|
9946
|
+
"/api/tenants/:tenantId/export/entities",
|
|
9947
|
+
previewEntities
|
|
9948
|
+
);
|
|
9949
|
+
app2.get(
|
|
9950
|
+
"/api/tenants/:tenantId/export/:jobId/download",
|
|
9951
|
+
downloadExport
|
|
9952
|
+
);
|
|
9953
|
+
app2.post(
|
|
9954
|
+
"/api/tenants/:tenantId/import/preview",
|
|
9955
|
+
importPreview
|
|
9956
|
+
);
|
|
9957
|
+
app2.post(
|
|
9958
|
+
"/api/tenants/:tenantId/import/apply",
|
|
9959
|
+
importApply
|
|
9960
|
+
);
|
|
9474
9961
|
};
|
|
9475
9962
|
|
|
9476
9963
|
// src/routes/resource-routes.ts
|
|
@@ -9499,9 +9986,1317 @@ function registerResourceRoutes(app2, controller) {
|
|
|
9499
9986
|
app2.delete("/api/resources/share/:token", controller.revokeShare.bind(controller));
|
|
9500
9987
|
}
|
|
9501
9988
|
|
|
9989
|
+
// src/export_registrations/index.ts
|
|
9990
|
+
var import_core51 = require("@axiom-lattice/core");
|
|
9991
|
+
|
|
9992
|
+
// src/export_registrations/skill.registration.ts
|
|
9993
|
+
var import_core38 = require("@axiom-lattice/core");
|
|
9994
|
+
function getStore2() {
|
|
9995
|
+
return (0, import_core38.getStoreLattice)("default", "skill").store;
|
|
9996
|
+
}
|
|
9997
|
+
var skillRegistration = {
|
|
9998
|
+
entityType: "skill",
|
|
9999
|
+
label: "Skill(\u6280\u80FD)",
|
|
10000
|
+
category: "core",
|
|
10001
|
+
dependsOn: [],
|
|
10002
|
+
cascadeParents: [],
|
|
10003
|
+
async listForExport(tenantId) {
|
|
10004
|
+
const store2 = getStore2();
|
|
10005
|
+
const skills = await store2.getAllSkills(tenantId);
|
|
10006
|
+
return skills.map((s) => ({
|
|
10007
|
+
_exportId: "",
|
|
10008
|
+
data: {
|
|
10009
|
+
id: s.id,
|
|
10010
|
+
name: s.name,
|
|
10011
|
+
description: s.description,
|
|
10012
|
+
license: s.license,
|
|
10013
|
+
compatibility: s.compatibility,
|
|
10014
|
+
metadata: s.metadata,
|
|
10015
|
+
content: s.content,
|
|
10016
|
+
subSkills: s.subSkills
|
|
10017
|
+
}
|
|
10018
|
+
}));
|
|
10019
|
+
},
|
|
10020
|
+
async previewImport(tenantId, entities) {
|
|
10021
|
+
const store2 = getStore2();
|
|
10022
|
+
const existing = await store2.getAllSkills(tenantId);
|
|
10023
|
+
const existingIds = new Set(existing.map((s) => s.id));
|
|
10024
|
+
const conflicts = [];
|
|
10025
|
+
const insertions = [];
|
|
10026
|
+
for (const entity of entities) {
|
|
10027
|
+
const id = entity.data.id;
|
|
10028
|
+
if (existingIds.has(id)) {
|
|
10029
|
+
conflicts.push({
|
|
10030
|
+
_exportId: entity._exportId,
|
|
10031
|
+
entityType: "skill",
|
|
10032
|
+
conflictType: "id_exists",
|
|
10033
|
+
existingId: id,
|
|
10034
|
+
existingName: entity.data.name || id
|
|
10035
|
+
});
|
|
10036
|
+
} else {
|
|
10037
|
+
insertions.push({
|
|
10038
|
+
_exportId: entity._exportId,
|
|
10039
|
+
entityType: "skill",
|
|
10040
|
+
name: entity.data.name || id
|
|
10041
|
+
});
|
|
10042
|
+
}
|
|
10043
|
+
}
|
|
10044
|
+
return { conflicts, insertions, errors: [] };
|
|
10045
|
+
},
|
|
10046
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10047
|
+
const store2 = getStore2();
|
|
10048
|
+
const data = entity.data;
|
|
10049
|
+
const id = resolution.action === "rename" && resolution.newId ? resolution.newId : data.id;
|
|
10050
|
+
if (resolution.action === "overwrite") {
|
|
10051
|
+
try {
|
|
10052
|
+
await store2.deleteSkill(tenantId, id);
|
|
10053
|
+
} catch {
|
|
10054
|
+
}
|
|
10055
|
+
}
|
|
10056
|
+
await store2.createSkill(tenantId, id, {
|
|
10057
|
+
name: data.name,
|
|
10058
|
+
description: data.description,
|
|
10059
|
+
license: data.license,
|
|
10060
|
+
compatibility: data.compatibility,
|
|
10061
|
+
metadata: data.metadata,
|
|
10062
|
+
content: data.content,
|
|
10063
|
+
subSkills: data.subSkills
|
|
10064
|
+
});
|
|
10065
|
+
return { newId: id };
|
|
10066
|
+
}
|
|
10067
|
+
};
|
|
10068
|
+
|
|
10069
|
+
// src/export_registrations/agent.registration.ts
|
|
10070
|
+
var import_core39 = require("@axiom-lattice/core");
|
|
10071
|
+
function getStore3() {
|
|
10072
|
+
return (0, import_core39.getStoreLattice)("default", "assistant").store;
|
|
10073
|
+
}
|
|
10074
|
+
var agentRegistration = {
|
|
10075
|
+
entityType: "agent",
|
|
10076
|
+
label: "Agent(\u667A\u80FD\u4F53)",
|
|
10077
|
+
category: "core",
|
|
10078
|
+
dependsOn: ["skill"],
|
|
10079
|
+
cascadeParents: [],
|
|
10080
|
+
async listForExport(tenantId) {
|
|
10081
|
+
const store2 = getStore3();
|
|
10082
|
+
const agents = await store2.getAllAssistants(tenantId);
|
|
10083
|
+
return agents.map((a) => ({
|
|
10084
|
+
_exportId: "",
|
|
10085
|
+
data: {
|
|
10086
|
+
id: a.id,
|
|
10087
|
+
name: a.name,
|
|
10088
|
+
description: a.description,
|
|
10089
|
+
graphDefinition: a.graphDefinition
|
|
10090
|
+
}
|
|
10091
|
+
}));
|
|
10092
|
+
},
|
|
10093
|
+
async previewImport(tenantId, entities) {
|
|
10094
|
+
const store2 = getStore3();
|
|
10095
|
+
const existing = await store2.getAllAssistants(tenantId);
|
|
10096
|
+
const existingIds = new Set(existing.map((a) => a.id));
|
|
10097
|
+
const conflicts = [];
|
|
10098
|
+
const insertions = [];
|
|
10099
|
+
for (const entity of entities) {
|
|
10100
|
+
const id = entity.data.id;
|
|
10101
|
+
if (existingIds.has(id)) {
|
|
10102
|
+
conflicts.push({
|
|
10103
|
+
_exportId: entity._exportId,
|
|
10104
|
+
entityType: "agent",
|
|
10105
|
+
conflictType: "id_exists",
|
|
10106
|
+
existingId: id,
|
|
10107
|
+
existingName: entity.data.name || id
|
|
10108
|
+
});
|
|
10109
|
+
} else {
|
|
10110
|
+
insertions.push({
|
|
10111
|
+
_exportId: entity._exportId,
|
|
10112
|
+
entityType: "agent",
|
|
10113
|
+
name: entity.data.name || id
|
|
10114
|
+
});
|
|
10115
|
+
}
|
|
10116
|
+
}
|
|
10117
|
+
return { conflicts, insertions, errors: [] };
|
|
10118
|
+
},
|
|
10119
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10120
|
+
const store2 = getStore3();
|
|
10121
|
+
const data = entity.data;
|
|
10122
|
+
const id = resolution.action === "rename" && resolution.newId ? resolution.newId : data.id;
|
|
10123
|
+
if (resolution.action === "overwrite") {
|
|
10124
|
+
try {
|
|
10125
|
+
await store2.deleteAssistant(tenantId, id);
|
|
10126
|
+
} catch {
|
|
10127
|
+
}
|
|
10128
|
+
}
|
|
10129
|
+
await store2.createAssistant(tenantId, id, {
|
|
10130
|
+
name: data.name,
|
|
10131
|
+
description: data.description || "",
|
|
10132
|
+
graphDefinition: data.graphDefinition
|
|
10133
|
+
});
|
|
10134
|
+
return { newId: id };
|
|
10135
|
+
}
|
|
10136
|
+
};
|
|
10137
|
+
|
|
10138
|
+
// src/export_registrations/binding.registration.ts
|
|
10139
|
+
var import_core40 = require("@axiom-lattice/core");
|
|
10140
|
+
function getStore4() {
|
|
10141
|
+
return (0, import_core40.getStoreLattice)("default", "channelBinding").store;
|
|
10142
|
+
}
|
|
10143
|
+
var bindingRegistration = {
|
|
10144
|
+
entityType: "binding",
|
|
10145
|
+
label: "Binding(\u6E20\u9053\u7ED1\u5B9A)",
|
|
10146
|
+
category: "core",
|
|
10147
|
+
dependsOn: ["agent", "channel_installation"],
|
|
10148
|
+
cascadeParents: [],
|
|
10149
|
+
referenceFields: { agentId: "agent", channelInstallationId: "channel_installation" },
|
|
10150
|
+
async listForExport(tenantId) {
|
|
10151
|
+
const store2 = getStore4();
|
|
10152
|
+
const bindings = await store2.list({ tenantId, limit: 1e4, offset: 0 });
|
|
10153
|
+
return bindings.map((b) => ({
|
|
10154
|
+
_exportId: "",
|
|
10155
|
+
data: {
|
|
10156
|
+
channel: b.channel,
|
|
10157
|
+
channelInstallationId: b.channelInstallationId,
|
|
10158
|
+
senderId: b.senderId,
|
|
10159
|
+
agentId: b.agentId,
|
|
10160
|
+
threadId: b.threadId,
|
|
10161
|
+
workspaceId: b.workspaceId,
|
|
10162
|
+
projectId: b.projectId,
|
|
10163
|
+
threadMode: b.threadMode,
|
|
10164
|
+
senderDisplayName: b.senderDisplayName,
|
|
10165
|
+
senderMetadata: b.senderMetadata,
|
|
10166
|
+
enabled: b.enabled
|
|
10167
|
+
}
|
|
10168
|
+
}));
|
|
10169
|
+
},
|
|
10170
|
+
async previewImport(tenantId, entities) {
|
|
10171
|
+
const store2 = getStore4();
|
|
10172
|
+
const existing = await store2.list({ tenantId, limit: 1e4, offset: 0 });
|
|
10173
|
+
const existingKeys = new Set(
|
|
10174
|
+
existing.map((b) => `${b.channel}:${b.channelInstallationId}:${b.senderId}`)
|
|
10175
|
+
);
|
|
10176
|
+
const conflicts = [];
|
|
10177
|
+
const insertions = [];
|
|
10178
|
+
for (const entity of entities) {
|
|
10179
|
+
const d = entity.data;
|
|
10180
|
+
const key = `${d.channel}:${d.channelInstallationId}:${d.senderId}`;
|
|
10181
|
+
if (existingKeys.has(key)) {
|
|
10182
|
+
conflicts.push({
|
|
10183
|
+
_exportId: entity._exportId,
|
|
10184
|
+
entityType: "binding",
|
|
10185
|
+
conflictType: "unique_constraint",
|
|
10186
|
+
existingName: `${d.channel}:${d.senderId}`,
|
|
10187
|
+
field: "channel+channelInstallationId+senderId"
|
|
10188
|
+
});
|
|
10189
|
+
} else {
|
|
10190
|
+
insertions.push({
|
|
10191
|
+
_exportId: entity._exportId,
|
|
10192
|
+
entityType: "binding",
|
|
10193
|
+
name: `${d.channel}:${d.senderId}`
|
|
10194
|
+
});
|
|
10195
|
+
}
|
|
10196
|
+
}
|
|
10197
|
+
return { conflicts, insertions, errors: [] };
|
|
10198
|
+
},
|
|
10199
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10200
|
+
if (resolution.action === "skip") return {};
|
|
10201
|
+
const store2 = getStore4();
|
|
10202
|
+
const d = entity.data;
|
|
10203
|
+
if (resolution.action === "overwrite") {
|
|
10204
|
+
const existing = await store2.list({ tenantId, limit: 1e4, offset: 0 });
|
|
10205
|
+
const match = existing.find(
|
|
10206
|
+
(b) => b.channel === d.channel && b.channelInstallationId === d.channelInstallationId && b.senderId === d.senderId
|
|
10207
|
+
);
|
|
10208
|
+
if (match) {
|
|
10209
|
+
await store2.delete(match.id);
|
|
10210
|
+
}
|
|
10211
|
+
}
|
|
10212
|
+
await store2.create({
|
|
10213
|
+
channel: d.channel,
|
|
10214
|
+
channelInstallationId: d.channelInstallationId,
|
|
10215
|
+
tenantId,
|
|
10216
|
+
senderId: d.senderId,
|
|
10217
|
+
agentId: d.agentId,
|
|
10218
|
+
threadMode: d.threadMode || "fixed",
|
|
10219
|
+
senderDisplayName: d.senderDisplayName,
|
|
10220
|
+
senderMetadata: d.senderMetadata,
|
|
10221
|
+
workspaceId: d.workspaceId,
|
|
10222
|
+
projectId: d.projectId
|
|
10223
|
+
});
|
|
10224
|
+
return { newId: void 0 };
|
|
10225
|
+
}
|
|
10226
|
+
};
|
|
10227
|
+
|
|
10228
|
+
// src/export_registrations/database-config.registration.ts
|
|
10229
|
+
var import_core41 = require("@axiom-lattice/core");
|
|
10230
|
+
function getStore5() {
|
|
10231
|
+
return (0, import_core41.getStoreLattice)("default", "database").store;
|
|
10232
|
+
}
|
|
10233
|
+
var databaseConfigRegistration = {
|
|
10234
|
+
entityType: "database_config",
|
|
10235
|
+
label: "Database Config(\u6570\u636E\u5E93\u914D\u7F6E)",
|
|
10236
|
+
category: "core",
|
|
10237
|
+
dependsOn: [],
|
|
10238
|
+
cascadeParents: [],
|
|
10239
|
+
async listForExport(tenantId) {
|
|
10240
|
+
const store2 = getStore5();
|
|
10241
|
+
const configs = await store2.getAllConfigs(tenantId);
|
|
10242
|
+
return configs.map((c) => ({
|
|
10243
|
+
_exportId: "",
|
|
10244
|
+
data: {
|
|
10245
|
+
id: c.id,
|
|
10246
|
+
key: c.key,
|
|
10247
|
+
name: c.name,
|
|
10248
|
+
description: c.description,
|
|
10249
|
+
config: c.config
|
|
10250
|
+
}
|
|
10251
|
+
}));
|
|
10252
|
+
},
|
|
10253
|
+
async previewImport(tenantId, entities) {
|
|
10254
|
+
const store2 = getStore5();
|
|
10255
|
+
const existing = await store2.getAllConfigs(tenantId);
|
|
10256
|
+
const existingIds = new Set(existing.map((c) => c.id));
|
|
10257
|
+
const existingKeys = new Set(existing.map((c) => c.key));
|
|
10258
|
+
const conflicts = [];
|
|
10259
|
+
const insertions = [];
|
|
10260
|
+
for (const entity of entities) {
|
|
10261
|
+
const d = entity.data;
|
|
10262
|
+
const id = d.id;
|
|
10263
|
+
const key = d.key;
|
|
10264
|
+
if (existingIds.has(id)) {
|
|
10265
|
+
conflicts.push({
|
|
10266
|
+
_exportId: entity._exportId,
|
|
10267
|
+
entityType: "database_config",
|
|
10268
|
+
conflictType: "id_exists",
|
|
10269
|
+
existingId: id,
|
|
10270
|
+
existingName: d.name || key
|
|
10271
|
+
});
|
|
10272
|
+
} else if (key && existingKeys.has(key)) {
|
|
10273
|
+
conflicts.push({
|
|
10274
|
+
_exportId: entity._exportId,
|
|
10275
|
+
entityType: "database_config",
|
|
10276
|
+
conflictType: "unique_constraint",
|
|
10277
|
+
existingName: d.name || key,
|
|
10278
|
+
field: "key"
|
|
10279
|
+
});
|
|
10280
|
+
} else {
|
|
10281
|
+
insertions.push({
|
|
10282
|
+
_exportId: entity._exportId,
|
|
10283
|
+
entityType: "database_config",
|
|
10284
|
+
name: d.name || key
|
|
10285
|
+
});
|
|
10286
|
+
}
|
|
10287
|
+
}
|
|
10288
|
+
return { conflicts, insertions, errors: [] };
|
|
10289
|
+
},
|
|
10290
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10291
|
+
const store2 = getStore5();
|
|
10292
|
+
const data = entity.data;
|
|
10293
|
+
const id = resolution.action === "rename" && resolution.newId ? resolution.newId : data.id;
|
|
10294
|
+
if (resolution.action === "overwrite") {
|
|
10295
|
+
try {
|
|
10296
|
+
await store2.deleteConfig(tenantId, id);
|
|
10297
|
+
} catch {
|
|
10298
|
+
}
|
|
10299
|
+
}
|
|
10300
|
+
await store2.createConfig(tenantId, id, {
|
|
10301
|
+
key: data.key,
|
|
10302
|
+
name: data.name,
|
|
10303
|
+
description: data.description,
|
|
10304
|
+
config: data.config
|
|
10305
|
+
});
|
|
10306
|
+
return { newId: id };
|
|
10307
|
+
}
|
|
10308
|
+
};
|
|
10309
|
+
|
|
10310
|
+
// src/export_registrations/metrics-config.registration.ts
|
|
10311
|
+
var import_core42 = require("@axiom-lattice/core");
|
|
10312
|
+
function getStore6() {
|
|
10313
|
+
return (0, import_core42.getStoreLattice)("default", "metrics").store;
|
|
10314
|
+
}
|
|
10315
|
+
var metricsConfigRegistration = {
|
|
10316
|
+
entityType: "metrics_config",
|
|
10317
|
+
label: "Metrics Config(\u6307\u6807\u914D\u7F6E)",
|
|
10318
|
+
category: "core",
|
|
10319
|
+
dependsOn: [],
|
|
10320
|
+
cascadeParents: [],
|
|
10321
|
+
async listForExport(tenantId) {
|
|
10322
|
+
const store2 = getStore6();
|
|
10323
|
+
const configs = await store2.getAllConfigs(tenantId);
|
|
10324
|
+
return configs.map((c) => ({
|
|
10325
|
+
_exportId: "",
|
|
10326
|
+
data: {
|
|
10327
|
+
id: c.id,
|
|
10328
|
+
key: c.key,
|
|
10329
|
+
name: c.name,
|
|
10330
|
+
description: c.description,
|
|
10331
|
+
config: c.config
|
|
10332
|
+
}
|
|
10333
|
+
}));
|
|
10334
|
+
},
|
|
10335
|
+
async previewImport(tenantId, entities) {
|
|
10336
|
+
const store2 = getStore6();
|
|
10337
|
+
const existing = await store2.getAllConfigs(tenantId);
|
|
10338
|
+
const existingIds = new Set(existing.map((c) => c.id));
|
|
10339
|
+
const existingKeys = new Set(existing.map((c) => c.key));
|
|
10340
|
+
const conflicts = [];
|
|
10341
|
+
const insertions = [];
|
|
10342
|
+
for (const entity of entities) {
|
|
10343
|
+
const d = entity.data;
|
|
10344
|
+
const id = d.id;
|
|
10345
|
+
const key = d.key;
|
|
10346
|
+
if (existingIds.has(id)) {
|
|
10347
|
+
conflicts.push({
|
|
10348
|
+
_exportId: entity._exportId,
|
|
10349
|
+
entityType: "metrics_config",
|
|
10350
|
+
conflictType: "id_exists",
|
|
10351
|
+
existingId: id,
|
|
10352
|
+
existingName: d.name || key
|
|
10353
|
+
});
|
|
10354
|
+
} else if (key && existingKeys.has(key)) {
|
|
10355
|
+
conflicts.push({
|
|
10356
|
+
_exportId: entity._exportId,
|
|
10357
|
+
entityType: "metrics_config",
|
|
10358
|
+
conflictType: "unique_constraint",
|
|
10359
|
+
existingName: d.name || key,
|
|
10360
|
+
field: "key"
|
|
10361
|
+
});
|
|
10362
|
+
} else {
|
|
10363
|
+
insertions.push({
|
|
10364
|
+
_exportId: entity._exportId,
|
|
10365
|
+
entityType: "metrics_config",
|
|
10366
|
+
name: d.name || key
|
|
10367
|
+
});
|
|
10368
|
+
}
|
|
10369
|
+
}
|
|
10370
|
+
return { conflicts, insertions, errors: [] };
|
|
10371
|
+
},
|
|
10372
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10373
|
+
const store2 = getStore6();
|
|
10374
|
+
const data = entity.data;
|
|
10375
|
+
const id = resolution.action === "rename" && resolution.newId ? resolution.newId : data.id;
|
|
10376
|
+
if (resolution.action === "overwrite") {
|
|
10377
|
+
try {
|
|
10378
|
+
await store2.deleteConfig(tenantId, id);
|
|
10379
|
+
} catch {
|
|
10380
|
+
}
|
|
10381
|
+
}
|
|
10382
|
+
await store2.createConfig(tenantId, id, {
|
|
10383
|
+
key: data.key,
|
|
10384
|
+
name: data.name,
|
|
10385
|
+
description: data.description,
|
|
10386
|
+
config: data.config
|
|
10387
|
+
});
|
|
10388
|
+
return { newId: id };
|
|
10389
|
+
}
|
|
10390
|
+
};
|
|
10391
|
+
|
|
10392
|
+
// src/export_registrations/mcp-config.registration.ts
|
|
10393
|
+
var import_core43 = require("@axiom-lattice/core");
|
|
10394
|
+
function getStore7() {
|
|
10395
|
+
return (0, import_core43.getStoreLattice)("default", "mcp").store;
|
|
10396
|
+
}
|
|
10397
|
+
var mcpConfigRegistration = {
|
|
10398
|
+
entityType: "mcp_config",
|
|
10399
|
+
label: "MCP Config(MCP\u914D\u7F6E)",
|
|
10400
|
+
category: "core",
|
|
10401
|
+
dependsOn: [],
|
|
10402
|
+
cascadeParents: [],
|
|
10403
|
+
async listForExport(tenantId) {
|
|
10404
|
+
const store2 = getStore7();
|
|
10405
|
+
const configs = await store2.getAllConfigs(tenantId);
|
|
10406
|
+
return configs.map((c) => ({
|
|
10407
|
+
_exportId: "",
|
|
10408
|
+
data: {
|
|
10409
|
+
id: c.id,
|
|
10410
|
+
key: c.key,
|
|
10411
|
+
name: c.name,
|
|
10412
|
+
description: c.description,
|
|
10413
|
+
config: c.config,
|
|
10414
|
+
selectedTools: c.selectedTools,
|
|
10415
|
+
status: c.status
|
|
10416
|
+
}
|
|
10417
|
+
}));
|
|
10418
|
+
},
|
|
10419
|
+
async previewImport(tenantId, entities) {
|
|
10420
|
+
const store2 = getStore7();
|
|
10421
|
+
const existing = await store2.getAllConfigs(tenantId);
|
|
10422
|
+
const existingIds = new Set(existing.map((c) => c.id));
|
|
10423
|
+
const existingKeys = new Set(existing.map((c) => c.key));
|
|
10424
|
+
const conflicts = [];
|
|
10425
|
+
const insertions = [];
|
|
10426
|
+
for (const entity of entities) {
|
|
10427
|
+
const d = entity.data;
|
|
10428
|
+
const id = d.id;
|
|
10429
|
+
const key = d.key;
|
|
10430
|
+
if (existingIds.has(id)) {
|
|
10431
|
+
conflicts.push({
|
|
10432
|
+
_exportId: entity._exportId,
|
|
10433
|
+
entityType: "mcp_config",
|
|
10434
|
+
conflictType: "id_exists",
|
|
10435
|
+
existingId: id,
|
|
10436
|
+
existingName: d.name || key
|
|
10437
|
+
});
|
|
10438
|
+
} else if (key && existingKeys.has(key)) {
|
|
10439
|
+
conflicts.push({
|
|
10440
|
+
_exportId: entity._exportId,
|
|
10441
|
+
entityType: "mcp_config",
|
|
10442
|
+
conflictType: "unique_constraint",
|
|
10443
|
+
existingName: d.name || key,
|
|
10444
|
+
field: "key"
|
|
10445
|
+
});
|
|
10446
|
+
} else {
|
|
10447
|
+
insertions.push({
|
|
10448
|
+
_exportId: entity._exportId,
|
|
10449
|
+
entityType: "mcp_config",
|
|
10450
|
+
name: d.name || key
|
|
10451
|
+
});
|
|
10452
|
+
}
|
|
10453
|
+
}
|
|
10454
|
+
return { conflicts, insertions, errors: [] };
|
|
10455
|
+
},
|
|
10456
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10457
|
+
const store2 = getStore7();
|
|
10458
|
+
const data = entity.data;
|
|
10459
|
+
const id = resolution.action === "rename" && resolution.newId ? resolution.newId : data.id;
|
|
10460
|
+
if (resolution.action === "overwrite") {
|
|
10461
|
+
try {
|
|
10462
|
+
await store2.deleteConfig(tenantId, id);
|
|
10463
|
+
} catch {
|
|
10464
|
+
}
|
|
10465
|
+
}
|
|
10466
|
+
await store2.createConfig(tenantId, id, {
|
|
10467
|
+
key: data.key,
|
|
10468
|
+
name: data.name,
|
|
10469
|
+
description: data.description,
|
|
10470
|
+
config: data.config,
|
|
10471
|
+
selectedTools: data.selectedTools
|
|
10472
|
+
});
|
|
10473
|
+
return { newId: id };
|
|
10474
|
+
}
|
|
10475
|
+
};
|
|
10476
|
+
|
|
10477
|
+
// src/export_registrations/connection.registration.ts
|
|
10478
|
+
var import_core44 = require("@axiom-lattice/core");
|
|
10479
|
+
function getStore8() {
|
|
10480
|
+
return (0, import_core44.getStoreLattice)("default", "connection").store;
|
|
10481
|
+
}
|
|
10482
|
+
async function listAllConnections(tenantId) {
|
|
10483
|
+
const store2 = getStore8();
|
|
10484
|
+
if (typeof store2.listByTenant !== "function") {
|
|
10485
|
+
throw new Error("ConnectionStore.listByTenant is not implemented. SQL bypass removed \u2014 upgrade your store adapter.");
|
|
10486
|
+
}
|
|
10487
|
+
return store2.listByTenant(tenantId);
|
|
10488
|
+
}
|
|
10489
|
+
var connectionRegistration = {
|
|
10490
|
+
entityType: "connection",
|
|
10491
|
+
label: "Connection(\u8FDE\u63A5)",
|
|
10492
|
+
category: "core",
|
|
10493
|
+
dependsOn: [],
|
|
10494
|
+
cascadeParents: [],
|
|
10495
|
+
async listForExport(tenantId) {
|
|
10496
|
+
const connections2 = await listAllConnections(tenantId);
|
|
10497
|
+
return connections2.map((c) => ({
|
|
10498
|
+
_exportId: "",
|
|
10499
|
+
data: {
|
|
10500
|
+
id: c.id,
|
|
10501
|
+
type: c.type,
|
|
10502
|
+
key: c.key,
|
|
10503
|
+
name: c.name,
|
|
10504
|
+
description: c.description,
|
|
10505
|
+
config: c.config
|
|
10506
|
+
}
|
|
10507
|
+
}));
|
|
10508
|
+
},
|
|
10509
|
+
async previewImport(tenantId, entities) {
|
|
10510
|
+
const existing = await listAllConnections(tenantId);
|
|
10511
|
+
const existingCompositeKeys = new Set(
|
|
10512
|
+
existing.map((c) => `${c.type}:${c.key}`)
|
|
10513
|
+
);
|
|
10514
|
+
const conflicts = [];
|
|
10515
|
+
const insertions = [];
|
|
10516
|
+
for (const entity of entities) {
|
|
10517
|
+
const d = entity.data;
|
|
10518
|
+
const compositeKey = `${d.type}:${d.key}`;
|
|
10519
|
+
if (existingCompositeKeys.has(compositeKey)) {
|
|
10520
|
+
conflicts.push({
|
|
10521
|
+
_exportId: entity._exportId,
|
|
10522
|
+
entityType: "connection",
|
|
10523
|
+
conflictType: "unique_constraint",
|
|
10524
|
+
existingName: `${d.type}:${d.key}`,
|
|
10525
|
+
field: "type+key"
|
|
10526
|
+
});
|
|
10527
|
+
} else {
|
|
10528
|
+
insertions.push({
|
|
10529
|
+
_exportId: entity._exportId,
|
|
10530
|
+
entityType: "connection",
|
|
10531
|
+
name: `${d.type}:${d.key}`
|
|
10532
|
+
});
|
|
10533
|
+
}
|
|
10534
|
+
}
|
|
10535
|
+
return { conflicts, insertions, errors: [] };
|
|
10536
|
+
},
|
|
10537
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10538
|
+
if (resolution.action === "skip") return {};
|
|
10539
|
+
const store2 = getStore8();
|
|
10540
|
+
const d = entity.data;
|
|
10541
|
+
const type = d.type;
|
|
10542
|
+
const key = d.key;
|
|
10543
|
+
if (resolution.action === "overwrite") {
|
|
10544
|
+
try {
|
|
10545
|
+
await store2.delete(tenantId, type, key);
|
|
10546
|
+
} catch {
|
|
10547
|
+
}
|
|
10548
|
+
}
|
|
10549
|
+
await store2.create({
|
|
10550
|
+
tenantId,
|
|
10551
|
+
type,
|
|
10552
|
+
key,
|
|
10553
|
+
name: d.name,
|
|
10554
|
+
description: d.description,
|
|
10555
|
+
config: d.config
|
|
10556
|
+
});
|
|
10557
|
+
return { newId: void 0 };
|
|
10558
|
+
}
|
|
10559
|
+
};
|
|
10560
|
+
|
|
10561
|
+
// src/export_registrations/collection.registration.ts
|
|
10562
|
+
var import_core45 = require("@axiom-lattice/core");
|
|
10563
|
+
function getStore9() {
|
|
10564
|
+
return (0, import_core45.getStoreLattice)("default", "collection").store;
|
|
10565
|
+
}
|
|
10566
|
+
var collectionRegistration = {
|
|
10567
|
+
entityType: "collection",
|
|
10568
|
+
label: "Collection(\u77E5\u8BC6\u5E93)",
|
|
10569
|
+
category: "core",
|
|
10570
|
+
dependsOn: [],
|
|
10571
|
+
cascadeParents: [],
|
|
10572
|
+
async listForExport(tenantId) {
|
|
10573
|
+
const store2 = getStore9();
|
|
10574
|
+
const collections = await store2.getAllCollections(tenantId);
|
|
10575
|
+
return collections.map((c) => ({
|
|
10576
|
+
_exportId: "",
|
|
10577
|
+
data: {
|
|
10578
|
+
id: c.id,
|
|
10579
|
+
name: c.name,
|
|
10580
|
+
label: c.label,
|
|
10581
|
+
embeddingKey: c.embeddingKey,
|
|
10582
|
+
schema: c.schema
|
|
10583
|
+
}
|
|
10584
|
+
}));
|
|
10585
|
+
},
|
|
10586
|
+
async previewImport(tenantId, entities) {
|
|
10587
|
+
const store2 = getStore9();
|
|
10588
|
+
const existing = await store2.getAllCollections(tenantId);
|
|
10589
|
+
const existingNames = new Set(existing.map((c) => c.name));
|
|
10590
|
+
const conflicts = [];
|
|
10591
|
+
const insertions = [];
|
|
10592
|
+
for (const entity of entities) {
|
|
10593
|
+
const d = entity.data;
|
|
10594
|
+
const name = d.name;
|
|
10595
|
+
if (existingNames.has(name)) {
|
|
10596
|
+
conflicts.push({
|
|
10597
|
+
_exportId: entity._exportId,
|
|
10598
|
+
entityType: "collection",
|
|
10599
|
+
conflictType: "unique_constraint",
|
|
10600
|
+
existingName: name,
|
|
10601
|
+
field: "name"
|
|
10602
|
+
});
|
|
10603
|
+
} else {
|
|
10604
|
+
insertions.push({
|
|
10605
|
+
_exportId: entity._exportId,
|
|
10606
|
+
entityType: "collection",
|
|
10607
|
+
name
|
|
10608
|
+
});
|
|
10609
|
+
}
|
|
10610
|
+
}
|
|
10611
|
+
return { conflicts, insertions, errors: [] };
|
|
10612
|
+
},
|
|
10613
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10614
|
+
if (resolution.action === "skip") return {};
|
|
10615
|
+
const store2 = getStore9();
|
|
10616
|
+
const d = entity.data;
|
|
10617
|
+
const name = d.name;
|
|
10618
|
+
if (resolution.action === "overwrite") {
|
|
10619
|
+
try {
|
|
10620
|
+
await store2.deleteCollection(tenantId, name);
|
|
10621
|
+
} catch {
|
|
10622
|
+
}
|
|
10623
|
+
}
|
|
10624
|
+
await store2.createCollection(tenantId, {
|
|
10625
|
+
name,
|
|
10626
|
+
label: d.label,
|
|
10627
|
+
embeddingKey: d.embeddingKey,
|
|
10628
|
+
schema: d.schema
|
|
10629
|
+
});
|
|
10630
|
+
return { newId: void 0 };
|
|
10631
|
+
}
|
|
10632
|
+
};
|
|
10633
|
+
|
|
10634
|
+
// src/export_registrations/channel-installation.registration.ts
|
|
10635
|
+
var import_core46 = require("@axiom-lattice/core");
|
|
10636
|
+
function getStore10() {
|
|
10637
|
+
return (0, import_core46.getStoreLattice)("default", "channelInstallation").store;
|
|
10638
|
+
}
|
|
10639
|
+
var channelInstallationRegistration = {
|
|
10640
|
+
entityType: "channel_installation",
|
|
10641
|
+
label: "Channel Installation(\u6E20\u9053\u5B89\u88C5)",
|
|
10642
|
+
category: "core",
|
|
10643
|
+
dependsOn: ["agent"],
|
|
10644
|
+
cascadeParents: [],
|
|
10645
|
+
referenceFields: { fallbackAgentId: "agent" },
|
|
10646
|
+
async listForExport(tenantId) {
|
|
10647
|
+
const store2 = getStore10();
|
|
10648
|
+
const installations = await store2.getInstallationsByTenant(tenantId);
|
|
10649
|
+
return installations.map((i) => ({
|
|
10650
|
+
_exportId: "",
|
|
10651
|
+
data: {
|
|
10652
|
+
id: i.id,
|
|
10653
|
+
channel: i.channel,
|
|
10654
|
+
name: i.name,
|
|
10655
|
+
config: i.config,
|
|
10656
|
+
enabled: i.enabled,
|
|
10657
|
+
fallbackAgentId: i.fallbackAgentId,
|
|
10658
|
+
rejectWhenNoBinding: i.rejectWhenNoBinding
|
|
10659
|
+
}
|
|
10660
|
+
}));
|
|
10661
|
+
},
|
|
10662
|
+
async previewImport(tenantId, entities) {
|
|
10663
|
+
const store2 = getStore10();
|
|
10664
|
+
const existing = await store2.getInstallationsByTenant(tenantId);
|
|
10665
|
+
const existingIds = new Set(existing.map((i) => i.id));
|
|
10666
|
+
const conflicts = [];
|
|
10667
|
+
const insertions = [];
|
|
10668
|
+
for (const entity of entities) {
|
|
10669
|
+
const d = entity.data;
|
|
10670
|
+
const id = d.id;
|
|
10671
|
+
if (existingIds.has(id)) {
|
|
10672
|
+
conflicts.push({
|
|
10673
|
+
_exportId: entity._exportId,
|
|
10674
|
+
entityType: "channel_installation",
|
|
10675
|
+
conflictType: "id_exists",
|
|
10676
|
+
existingId: id,
|
|
10677
|
+
existingName: d.name || id
|
|
10678
|
+
});
|
|
10679
|
+
} else {
|
|
10680
|
+
insertions.push({
|
|
10681
|
+
_exportId: entity._exportId,
|
|
10682
|
+
entityType: "channel_installation",
|
|
10683
|
+
name: d.name || id
|
|
10684
|
+
});
|
|
10685
|
+
}
|
|
10686
|
+
}
|
|
10687
|
+
return { conflicts, insertions, errors: [] };
|
|
10688
|
+
},
|
|
10689
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10690
|
+
const store2 = getStore10();
|
|
10691
|
+
const data = entity.data;
|
|
10692
|
+
const id = resolution.action === "rename" && resolution.newId ? resolution.newId : data.id;
|
|
10693
|
+
if (resolution.action === "overwrite") {
|
|
10694
|
+
try {
|
|
10695
|
+
await store2.deleteInstallation(tenantId, id);
|
|
10696
|
+
} catch {
|
|
10697
|
+
}
|
|
10698
|
+
}
|
|
10699
|
+
await store2.createInstallation(tenantId, id, {
|
|
10700
|
+
channel: data.channel,
|
|
10701
|
+
name: data.name,
|
|
10702
|
+
config: data.config,
|
|
10703
|
+
enabled: data.enabled,
|
|
10704
|
+
fallbackAgentId: data.fallbackAgentId,
|
|
10705
|
+
rejectWhenNoBinding: data.rejectWhenNoBinding
|
|
10706
|
+
});
|
|
10707
|
+
return { newId: id };
|
|
10708
|
+
}
|
|
10709
|
+
};
|
|
10710
|
+
|
|
10711
|
+
// src/export_registrations/menu.registration.ts
|
|
10712
|
+
var import_core47 = require("@axiom-lattice/core");
|
|
10713
|
+
function getStore11() {
|
|
10714
|
+
return (0, import_core47.getStoreLattice)("default", "menu").store;
|
|
10715
|
+
}
|
|
10716
|
+
var menuRegistration = {
|
|
10717
|
+
entityType: "menu",
|
|
10718
|
+
label: "Menu(\u83DC\u5355)",
|
|
10719
|
+
category: "core",
|
|
10720
|
+
dependsOn: ["agent"],
|
|
10721
|
+
cascadeParents: [],
|
|
10722
|
+
async listForExport(tenantId) {
|
|
10723
|
+
const store2 = getStore11();
|
|
10724
|
+
const menus = await store2.list({ tenantId });
|
|
10725
|
+
return menus.map((m) => ({
|
|
10726
|
+
_exportId: "",
|
|
10727
|
+
data: {
|
|
10728
|
+
id: m.id,
|
|
10729
|
+
menuTarget: m.menuTarget,
|
|
10730
|
+
group: m.group,
|
|
10731
|
+
name: m.name,
|
|
10732
|
+
icon: m.icon,
|
|
10733
|
+
sortOrder: m.sortOrder,
|
|
10734
|
+
contentType: m.contentType,
|
|
10735
|
+
contentConfig: m.contentConfig,
|
|
10736
|
+
enabled: m.enabled
|
|
10737
|
+
}
|
|
10738
|
+
}));
|
|
10739
|
+
},
|
|
10740
|
+
async previewImport(tenantId, entities) {
|
|
10741
|
+
const store2 = getStore11();
|
|
10742
|
+
const existing = await store2.list({ tenantId });
|
|
10743
|
+
const existingIds = new Set(existing.map((m) => m.id));
|
|
10744
|
+
const conflicts = [];
|
|
10745
|
+
const insertions = [];
|
|
10746
|
+
for (const entity of entities) {
|
|
10747
|
+
const d = entity.data;
|
|
10748
|
+
const id = d.id;
|
|
10749
|
+
if (existingIds.has(id)) {
|
|
10750
|
+
conflicts.push({
|
|
10751
|
+
_exportId: entity._exportId,
|
|
10752
|
+
entityType: "menu",
|
|
10753
|
+
conflictType: "id_exists",
|
|
10754
|
+
existingId: id,
|
|
10755
|
+
existingName: d.name || id
|
|
10756
|
+
});
|
|
10757
|
+
} else {
|
|
10758
|
+
insertions.push({
|
|
10759
|
+
_exportId: entity._exportId,
|
|
10760
|
+
entityType: "menu",
|
|
10761
|
+
name: d.name || id
|
|
10762
|
+
});
|
|
10763
|
+
}
|
|
10764
|
+
}
|
|
10765
|
+
return { conflicts, insertions, errors: [] };
|
|
10766
|
+
},
|
|
10767
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10768
|
+
const store2 = getStore11();
|
|
10769
|
+
const d = entity.data;
|
|
10770
|
+
const id = resolution.action === "rename" && resolution.newId ? resolution.newId : d.id;
|
|
10771
|
+
if (resolution.action === "overwrite") {
|
|
10772
|
+
try {
|
|
10773
|
+
await store2.delete(id);
|
|
10774
|
+
} catch {
|
|
10775
|
+
}
|
|
10776
|
+
}
|
|
10777
|
+
await store2.create({
|
|
10778
|
+
tenantId,
|
|
10779
|
+
menuTarget: d.menuTarget,
|
|
10780
|
+
group: d.group,
|
|
10781
|
+
name: d.name,
|
|
10782
|
+
icon: d.icon,
|
|
10783
|
+
sortOrder: d.sortOrder,
|
|
10784
|
+
contentType: d.contentType,
|
|
10785
|
+
contentConfig: d.contentConfig
|
|
10786
|
+
});
|
|
10787
|
+
return { newId: void 0 };
|
|
10788
|
+
}
|
|
10789
|
+
};
|
|
10790
|
+
|
|
10791
|
+
// src/export_registrations/task.registration.ts
|
|
10792
|
+
var import_core48 = require("@axiom-lattice/core");
|
|
10793
|
+
function getStore12() {
|
|
10794
|
+
return (0, import_core48.getStoreLattice)("default", "task").store;
|
|
10795
|
+
}
|
|
10796
|
+
var taskRegistration = {
|
|
10797
|
+
entityType: "task",
|
|
10798
|
+
label: "Task(\u4EFB\u52A1)",
|
|
10799
|
+
category: "core",
|
|
10800
|
+
dependsOn: ["agent"],
|
|
10801
|
+
cascadeParents: [],
|
|
10802
|
+
referenceFields: { ownerId: "agent", parentId: "task" },
|
|
10803
|
+
async listForExport(tenantId) {
|
|
10804
|
+
const store2 = getStore12();
|
|
10805
|
+
const tasks = await store2.list({ tenantId, limit: 1e4, offset: 0 });
|
|
10806
|
+
return tasks.map((t) => ({
|
|
10807
|
+
_exportId: "",
|
|
10808
|
+
data: {
|
|
10809
|
+
id: t.id,
|
|
10810
|
+
title: t.title,
|
|
10811
|
+
description: t.description,
|
|
10812
|
+
status: t.status,
|
|
10813
|
+
priority: t.priority,
|
|
10814
|
+
dueDate: t.dueDate,
|
|
10815
|
+
ownerType: t.ownerType,
|
|
10816
|
+
ownerId: t.ownerId,
|
|
10817
|
+
metadata: t.metadata,
|
|
10818
|
+
parentId: t.parentId,
|
|
10819
|
+
sourceId: t.sourceId,
|
|
10820
|
+
context: t.context
|
|
10821
|
+
}
|
|
10822
|
+
}));
|
|
10823
|
+
},
|
|
10824
|
+
async previewImport(tenantId, entities) {
|
|
10825
|
+
const store2 = getStore12();
|
|
10826
|
+
const existing = await store2.list({ tenantId, limit: 1e4, offset: 0 });
|
|
10827
|
+
const existingIds = new Set(existing.map((t) => t.id));
|
|
10828
|
+
const conflicts = [];
|
|
10829
|
+
const insertions = [];
|
|
10830
|
+
for (const entity of entities) {
|
|
10831
|
+
const d = entity.data;
|
|
10832
|
+
const id = d.id;
|
|
10833
|
+
if (existingIds.has(id)) {
|
|
10834
|
+
conflicts.push({
|
|
10835
|
+
_exportId: entity._exportId,
|
|
10836
|
+
entityType: "task",
|
|
10837
|
+
conflictType: "id_exists",
|
|
10838
|
+
existingId: id,
|
|
10839
|
+
existingName: d.title || id
|
|
10840
|
+
});
|
|
10841
|
+
} else {
|
|
10842
|
+
insertions.push({
|
|
10843
|
+
_exportId: entity._exportId,
|
|
10844
|
+
entityType: "task",
|
|
10845
|
+
name: d.title || id
|
|
10846
|
+
});
|
|
10847
|
+
}
|
|
10848
|
+
}
|
|
10849
|
+
return { conflicts, insertions, errors: [] };
|
|
10850
|
+
},
|
|
10851
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10852
|
+
const store2 = getStore12();
|
|
10853
|
+
const data = entity.data;
|
|
10854
|
+
const id = resolution.action === "rename" && resolution.newId ? resolution.newId : data.id;
|
|
10855
|
+
if (resolution.action === "overwrite") {
|
|
10856
|
+
try {
|
|
10857
|
+
await store2.delete(tenantId, id);
|
|
10858
|
+
} catch {
|
|
10859
|
+
}
|
|
10860
|
+
}
|
|
10861
|
+
await store2.create({
|
|
10862
|
+
tenantId,
|
|
10863
|
+
ownerType: data.ownerType || "user",
|
|
10864
|
+
ownerId: data.ownerId || "",
|
|
10865
|
+
title: data.title,
|
|
10866
|
+
description: data.description,
|
|
10867
|
+
status: data.status,
|
|
10868
|
+
priority: data.priority,
|
|
10869
|
+
dueDate: data.dueDate,
|
|
10870
|
+
metadata: data.metadata,
|
|
10871
|
+
parentId: data.parentId,
|
|
10872
|
+
sourceId: data.sourceId,
|
|
10873
|
+
context: data.context
|
|
10874
|
+
});
|
|
10875
|
+
return { newId: id };
|
|
10876
|
+
}
|
|
10877
|
+
};
|
|
10878
|
+
|
|
10879
|
+
// src/export_registrations/a2a-api-key.registration.ts
|
|
10880
|
+
var import_core49 = require("@axiom-lattice/core");
|
|
10881
|
+
function getStore13() {
|
|
10882
|
+
return (0, import_core49.getStoreLattice)("default", "a2aApiKey").store;
|
|
10883
|
+
}
|
|
10884
|
+
var a2aApiKeyRegistration = {
|
|
10885
|
+
entityType: "a2a_api_key",
|
|
10886
|
+
label: "A2A API Key(API\u5BC6\u94A5)",
|
|
10887
|
+
category: "core",
|
|
10888
|
+
dependsOn: [],
|
|
10889
|
+
cascadeParents: [],
|
|
10890
|
+
async listForExport(tenantId) {
|
|
10891
|
+
const store2 = getStore13();
|
|
10892
|
+
const keys = await store2.list({ tenantId, limit: 1e4, offset: 0 });
|
|
10893
|
+
return keys.map((k) => ({
|
|
10894
|
+
_exportId: "",
|
|
10895
|
+
data: {
|
|
10896
|
+
id: k.id,
|
|
10897
|
+
tenantId: k.tenantId,
|
|
10898
|
+
projectId: k.projectId,
|
|
10899
|
+
workspaceId: k.workspaceId,
|
|
10900
|
+
label: k.label,
|
|
10901
|
+
enabled: k.enabled
|
|
10902
|
+
}
|
|
10903
|
+
}));
|
|
10904
|
+
},
|
|
10905
|
+
async previewImport(tenantId, entities) {
|
|
10906
|
+
const store2 = getStore13();
|
|
10907
|
+
const existing = await store2.list({ tenantId, limit: 1e4, offset: 0 });
|
|
10908
|
+
const existingIds = new Set(existing.map((k) => k.id));
|
|
10909
|
+
const conflicts = [];
|
|
10910
|
+
const insertions = [];
|
|
10911
|
+
for (const entity of entities) {
|
|
10912
|
+
const d = entity.data;
|
|
10913
|
+
const id = d.id;
|
|
10914
|
+
if (existingIds.has(id)) {
|
|
10915
|
+
conflicts.push({
|
|
10916
|
+
_exportId: entity._exportId,
|
|
10917
|
+
entityType: "a2a_api_key",
|
|
10918
|
+
conflictType: "id_exists",
|
|
10919
|
+
existingId: id,
|
|
10920
|
+
existingName: d.label || id
|
|
10921
|
+
});
|
|
10922
|
+
} else {
|
|
10923
|
+
insertions.push({
|
|
10924
|
+
_exportId: entity._exportId,
|
|
10925
|
+
entityType: "a2a_api_key",
|
|
10926
|
+
name: d.label || id
|
|
10927
|
+
});
|
|
10928
|
+
}
|
|
10929
|
+
}
|
|
10930
|
+
return { conflicts, insertions, errors: [] };
|
|
10931
|
+
},
|
|
10932
|
+
async applyImport(tenantId, entity, resolution) {
|
|
10933
|
+
if (resolution.action === "skip") return {};
|
|
10934
|
+
const store2 = getStore13();
|
|
10935
|
+
const d = entity.data;
|
|
10936
|
+
if (resolution.action === "overwrite") {
|
|
10937
|
+
try {
|
|
10938
|
+
await store2.delete(d.id);
|
|
10939
|
+
} catch {
|
|
10940
|
+
}
|
|
10941
|
+
}
|
|
10942
|
+
await store2.create({
|
|
10943
|
+
tenantId,
|
|
10944
|
+
projectId: d.projectId,
|
|
10945
|
+
workspaceId: d.workspaceId,
|
|
10946
|
+
label: d.label
|
|
10947
|
+
});
|
|
10948
|
+
return { newId: void 0 };
|
|
10949
|
+
}
|
|
10950
|
+
};
|
|
10951
|
+
|
|
10952
|
+
// src/export_registrations/eval.registration.ts
|
|
10953
|
+
var import_core50 = require("@axiom-lattice/core");
|
|
10954
|
+
function getStore14() {
|
|
10955
|
+
return (0, import_core50.getStoreLattice)("default", "eval").store;
|
|
10956
|
+
}
|
|
10957
|
+
var evalRegistration = {
|
|
10958
|
+
entityType: "eval",
|
|
10959
|
+
label: "Eval(\u8BC4\u4F30)",
|
|
10960
|
+
category: "core",
|
|
10961
|
+
dependsOn: [],
|
|
10962
|
+
cascadeParents: [],
|
|
10963
|
+
referenceFields: { suiteId: "eval_suite", projectId: "eval_project", runId: "eval_run", caseId: "eval_case" },
|
|
10964
|
+
async listForExport(tenantId) {
|
|
10965
|
+
const store2 = getStore14();
|
|
10966
|
+
const projects = await store2.getProjectsByTenant(tenantId);
|
|
10967
|
+
const entities = [];
|
|
10968
|
+
for (const project of projects) {
|
|
10969
|
+
entities.push({
|
|
10970
|
+
_exportId: "",
|
|
10971
|
+
data: {
|
|
10972
|
+
_subType: "eval_project",
|
|
10973
|
+
id: project.id,
|
|
10974
|
+
name: project.name,
|
|
10975
|
+
description: project.description,
|
|
10976
|
+
version: project.version,
|
|
10977
|
+
judgeModelConfig: project.judgeModelConfig,
|
|
10978
|
+
targetServerConfig: project.targetServerConfig,
|
|
10979
|
+
concurrency: project.concurrency,
|
|
10980
|
+
reportConfig: project.reportConfig
|
|
10981
|
+
}
|
|
10982
|
+
});
|
|
10983
|
+
const suites = await store2.getSuitesByProject(tenantId, project.id);
|
|
10984
|
+
for (const suite of suites) {
|
|
10985
|
+
entities.push({
|
|
10986
|
+
_exportId: "",
|
|
10987
|
+
data: {
|
|
10988
|
+
_subType: "eval_suite",
|
|
10989
|
+
id: suite.id,
|
|
10990
|
+
projectId: suite.projectId,
|
|
10991
|
+
name: suite.name
|
|
10992
|
+
}
|
|
10993
|
+
});
|
|
10994
|
+
const cases = await store2.getCasesBySuite(tenantId, suite.id);
|
|
10995
|
+
for (const c of cases) {
|
|
10996
|
+
entities.push({
|
|
10997
|
+
_exportId: "",
|
|
10998
|
+
data: {
|
|
10999
|
+
_subType: "eval_case",
|
|
11000
|
+
id: c.id,
|
|
11001
|
+
suiteId: c.suiteId,
|
|
11002
|
+
inputMessage: c.inputMessage,
|
|
11003
|
+
inputFiles: c.inputFiles,
|
|
11004
|
+
steps: c.steps,
|
|
11005
|
+
outputType: c.outputType,
|
|
11006
|
+
contentAssertion: c.contentAssertion,
|
|
11007
|
+
rubrics: c.rubrics
|
|
11008
|
+
}
|
|
11009
|
+
});
|
|
11010
|
+
}
|
|
11011
|
+
}
|
|
11012
|
+
const runs = await store2.getRunsByTenant(tenantId, { projectId: project.id });
|
|
11013
|
+
for (const run of runs) {
|
|
11014
|
+
entities.push({
|
|
11015
|
+
_exportId: "",
|
|
11016
|
+
data: {
|
|
11017
|
+
_subType: "eval_run",
|
|
11018
|
+
id: run.id,
|
|
11019
|
+
projectId: run.projectId,
|
|
11020
|
+
status: run.status,
|
|
11021
|
+
concurrency: run.concurrency,
|
|
11022
|
+
totalCases: run.totalCases,
|
|
11023
|
+
passedCases: run.passedCases,
|
|
11024
|
+
failedCases: run.failedCases,
|
|
11025
|
+
avgScore: run.avgScore,
|
|
11026
|
+
error: run.error
|
|
11027
|
+
}
|
|
11028
|
+
});
|
|
11029
|
+
const results = await store2.getResultsByRun(tenantId, run.id);
|
|
11030
|
+
for (const result of results) {
|
|
11031
|
+
entities.push({
|
|
11032
|
+
_exportId: "",
|
|
11033
|
+
data: {
|
|
11034
|
+
_subType: "eval_run_result",
|
|
11035
|
+
id: result.id,
|
|
11036
|
+
runId: result.runId,
|
|
11037
|
+
suiteName: result.suiteName,
|
|
11038
|
+
caseId: result.caseId,
|
|
11039
|
+
pass: result.pass,
|
|
11040
|
+
score: result.score,
|
|
11041
|
+
summary: result.summary,
|
|
11042
|
+
dimensionResults: result.dimensionResults,
|
|
11043
|
+
durationMs: result.durationMs,
|
|
11044
|
+
messages: result.messages,
|
|
11045
|
+
logs: result.logs,
|
|
11046
|
+
error: result.error
|
|
11047
|
+
}
|
|
11048
|
+
});
|
|
11049
|
+
}
|
|
11050
|
+
}
|
|
11051
|
+
}
|
|
11052
|
+
return entities;
|
|
11053
|
+
},
|
|
11054
|
+
async previewImport(tenantId, entities) {
|
|
11055
|
+
const store2 = getStore14();
|
|
11056
|
+
const existingProjects = await store2.getProjectsByTenant(tenantId);
|
|
11057
|
+
const existingProjectIds = new Set(existingProjects.map((p) => p.id));
|
|
11058
|
+
const existingProjectNames = new Set(existingProjects.map((p) => p.name));
|
|
11059
|
+
const existingSuites = /* @__PURE__ */ new Map();
|
|
11060
|
+
const existingSuiteIds = /* @__PURE__ */ new Set();
|
|
11061
|
+
const existingCaseIds = /* @__PURE__ */ new Set();
|
|
11062
|
+
const existingRunIds = /* @__PURE__ */ new Set();
|
|
11063
|
+
const existingResultIds = /* @__PURE__ */ new Set();
|
|
11064
|
+
for (const project of existingProjects) {
|
|
11065
|
+
const suites = await store2.getSuitesByProject(tenantId, project.id);
|
|
11066
|
+
existingSuites.set(project.id, new Set(suites.map((s) => `${s.projectId}:${s.name}`)));
|
|
11067
|
+
for (const s of suites) {
|
|
11068
|
+
existingSuiteIds.add(s.id);
|
|
11069
|
+
try {
|
|
11070
|
+
const cases = await store2.getCasesBySuite(tenantId, s.id);
|
|
11071
|
+
for (const c of cases) existingCaseIds.add(c.id);
|
|
11072
|
+
} catch {
|
|
11073
|
+
}
|
|
11074
|
+
}
|
|
11075
|
+
}
|
|
11076
|
+
for (const project of existingProjects) {
|
|
11077
|
+
const runs = await store2.getRunsByTenant(tenantId, { projectId: project.id });
|
|
11078
|
+
for (const run of runs) {
|
|
11079
|
+
existingRunIds.add(run.id);
|
|
11080
|
+
try {
|
|
11081
|
+
const results = await store2.getResultsByRun(tenantId, run.id);
|
|
11082
|
+
for (const r of results) existingResultIds.add(r.id);
|
|
11083
|
+
} catch {
|
|
11084
|
+
}
|
|
11085
|
+
}
|
|
11086
|
+
}
|
|
11087
|
+
const conflicts = [];
|
|
11088
|
+
const insertions = [];
|
|
11089
|
+
for (const entity of entities) {
|
|
11090
|
+
const d = entity.data;
|
|
11091
|
+
const subType = d._subType;
|
|
11092
|
+
const id = d.id;
|
|
11093
|
+
switch (subType) {
|
|
11094
|
+
case "eval_project": {
|
|
11095
|
+
const name = d.name;
|
|
11096
|
+
if (existingProjectIds.has(id)) {
|
|
11097
|
+
conflicts.push({
|
|
11098
|
+
_exportId: entity._exportId,
|
|
11099
|
+
entityType: "eval_project",
|
|
11100
|
+
conflictType: "id_exists",
|
|
11101
|
+
existingId: id,
|
|
11102
|
+
existingName: name
|
|
11103
|
+
});
|
|
11104
|
+
} else if (name && existingProjectNames.has(name)) {
|
|
11105
|
+
conflicts.push({
|
|
11106
|
+
_exportId: entity._exportId,
|
|
11107
|
+
entityType: "eval_project",
|
|
11108
|
+
conflictType: "unique_constraint",
|
|
11109
|
+
existingName: name,
|
|
11110
|
+
field: "name"
|
|
11111
|
+
});
|
|
11112
|
+
} else {
|
|
11113
|
+
insertions.push({ _exportId: entity._exportId, entityType: "eval_project", name });
|
|
11114
|
+
}
|
|
11115
|
+
break;
|
|
11116
|
+
}
|
|
11117
|
+
case "eval_suite": {
|
|
11118
|
+
const projectId = d.projectId;
|
|
11119
|
+
const name = d.name;
|
|
11120
|
+
const suiteKey = `${projectId}:${name}`;
|
|
11121
|
+
const projectSuites = existingSuites.get(projectId);
|
|
11122
|
+
if (existingSuiteIds.has(id)) {
|
|
11123
|
+
conflicts.push({
|
|
11124
|
+
_exportId: entity._exportId,
|
|
11125
|
+
entityType: "eval_suite",
|
|
11126
|
+
conflictType: "id_exists",
|
|
11127
|
+
existingId: id,
|
|
11128
|
+
existingName: name
|
|
11129
|
+
});
|
|
11130
|
+
} else if (projectSuites?.has(suiteKey)) {
|
|
11131
|
+
conflicts.push({
|
|
11132
|
+
_exportId: entity._exportId,
|
|
11133
|
+
entityType: "eval_suite",
|
|
11134
|
+
conflictType: "unique_constraint",
|
|
11135
|
+
existingName: name,
|
|
11136
|
+
field: "projectId+name"
|
|
11137
|
+
});
|
|
11138
|
+
} else {
|
|
11139
|
+
insertions.push({ _exportId: entity._exportId, entityType: "eval_suite", name });
|
|
11140
|
+
}
|
|
11141
|
+
break;
|
|
11142
|
+
}
|
|
11143
|
+
case "eval_case": {
|
|
11144
|
+
if (existingCaseIds.has(id)) {
|
|
11145
|
+
conflicts.push({
|
|
11146
|
+
_exportId: entity._exportId,
|
|
11147
|
+
entityType: "eval_case",
|
|
11148
|
+
conflictType: "id_exists",
|
|
11149
|
+
existingId: id
|
|
11150
|
+
});
|
|
11151
|
+
} else {
|
|
11152
|
+
insertions.push({ _exportId: entity._exportId, entityType: "eval_case", name: id });
|
|
11153
|
+
}
|
|
11154
|
+
break;
|
|
11155
|
+
}
|
|
11156
|
+
case "eval_run": {
|
|
11157
|
+
if (existingRunIds.has(id)) {
|
|
11158
|
+
conflicts.push({
|
|
11159
|
+
_exportId: entity._exportId,
|
|
11160
|
+
entityType: "eval_run",
|
|
11161
|
+
conflictType: "id_exists",
|
|
11162
|
+
existingId: id
|
|
11163
|
+
});
|
|
11164
|
+
} else {
|
|
11165
|
+
insertions.push({ _exportId: entity._exportId, entityType: "eval_run", name: id });
|
|
11166
|
+
}
|
|
11167
|
+
break;
|
|
11168
|
+
}
|
|
11169
|
+
case "eval_run_result": {
|
|
11170
|
+
if (existingResultIds.has(id)) {
|
|
11171
|
+
conflicts.push({
|
|
11172
|
+
_exportId: entity._exportId,
|
|
11173
|
+
entityType: "eval_run_result",
|
|
11174
|
+
conflictType: "id_exists",
|
|
11175
|
+
existingId: id
|
|
11176
|
+
});
|
|
11177
|
+
} else {
|
|
11178
|
+
insertions.push({ _exportId: entity._exportId, entityType: "eval_run_result", name: id });
|
|
11179
|
+
}
|
|
11180
|
+
break;
|
|
11181
|
+
}
|
|
11182
|
+
}
|
|
11183
|
+
}
|
|
11184
|
+
return { conflicts, insertions, errors: [] };
|
|
11185
|
+
},
|
|
11186
|
+
async applyImport(tenantId, entity, resolution) {
|
|
11187
|
+
if (resolution.action === "skip") return {};
|
|
11188
|
+
const store2 = getStore14();
|
|
11189
|
+
const d = entity.data;
|
|
11190
|
+
const subType = d._subType;
|
|
11191
|
+
const id = resolution.action === "rename" && resolution.newId ? resolution.newId : d.id;
|
|
11192
|
+
switch (subType) {
|
|
11193
|
+
case "eval_project": {
|
|
11194
|
+
if (resolution.action === "overwrite") {
|
|
11195
|
+
try {
|
|
11196
|
+
await store2.deleteProject(tenantId, id);
|
|
11197
|
+
} catch {
|
|
11198
|
+
}
|
|
11199
|
+
}
|
|
11200
|
+
await store2.createProject(tenantId, id, {
|
|
11201
|
+
name: d.name,
|
|
11202
|
+
description: d.description,
|
|
11203
|
+
version: d.version,
|
|
11204
|
+
judgeModelConfig: d.judgeModelConfig,
|
|
11205
|
+
targetServerConfig: d.targetServerConfig,
|
|
11206
|
+
concurrency: d.concurrency,
|
|
11207
|
+
reportConfig: d.reportConfig
|
|
11208
|
+
});
|
|
11209
|
+
break;
|
|
11210
|
+
}
|
|
11211
|
+
case "eval_suite": {
|
|
11212
|
+
if (resolution.action === "overwrite") {
|
|
11213
|
+
try {
|
|
11214
|
+
await store2.deleteSuite(tenantId, id);
|
|
11215
|
+
} catch {
|
|
11216
|
+
}
|
|
11217
|
+
}
|
|
11218
|
+
await store2.createSuite(tenantId, d.projectId, id, {
|
|
11219
|
+
name: d.name
|
|
11220
|
+
});
|
|
11221
|
+
break;
|
|
11222
|
+
}
|
|
11223
|
+
case "eval_case": {
|
|
11224
|
+
if (resolution.action === "overwrite") {
|
|
11225
|
+
try {
|
|
11226
|
+
await store2.deleteCase(tenantId, id);
|
|
11227
|
+
} catch {
|
|
11228
|
+
}
|
|
11229
|
+
}
|
|
11230
|
+
await store2.createCase(tenantId, d.suiteId, id, {
|
|
11231
|
+
inputMessage: d.inputMessage,
|
|
11232
|
+
inputFiles: d.inputFiles,
|
|
11233
|
+
steps: d.steps,
|
|
11234
|
+
outputType: d.outputType,
|
|
11235
|
+
contentAssertion: d.contentAssertion,
|
|
11236
|
+
rubrics: d.rubrics
|
|
11237
|
+
});
|
|
11238
|
+
break;
|
|
11239
|
+
}
|
|
11240
|
+
case "eval_run": {
|
|
11241
|
+
if (resolution.action === "overwrite") {
|
|
11242
|
+
try {
|
|
11243
|
+
await store2.deleteRun(tenantId, id);
|
|
11244
|
+
} catch {
|
|
11245
|
+
}
|
|
11246
|
+
}
|
|
11247
|
+
await store2.createRun(tenantId, d.projectId, id, {
|
|
11248
|
+
totalCases: d.totalCases,
|
|
11249
|
+
concurrency: d.concurrency
|
|
11250
|
+
});
|
|
11251
|
+
break;
|
|
11252
|
+
}
|
|
11253
|
+
case "eval_run_result": {
|
|
11254
|
+
if (resolution.action === "overwrite") {
|
|
11255
|
+
try {
|
|
11256
|
+
await store2.deleteRunResult(tenantId, entity.data.id);
|
|
11257
|
+
} catch {
|
|
11258
|
+
}
|
|
11259
|
+
}
|
|
11260
|
+
await store2.createRunResult(tenantId, d.runId, id, {
|
|
11261
|
+
suiteName: d.suiteName,
|
|
11262
|
+
caseId: d.caseId,
|
|
11263
|
+
pass: d.pass,
|
|
11264
|
+
score: d.score,
|
|
11265
|
+
summary: d.summary,
|
|
11266
|
+
dimensionResults: d.dimensionResults,
|
|
11267
|
+
durationMs: d.durationMs,
|
|
11268
|
+
messages: d.messages,
|
|
11269
|
+
logs: d.logs,
|
|
11270
|
+
error: d.error
|
|
11271
|
+
});
|
|
11272
|
+
break;
|
|
11273
|
+
}
|
|
11274
|
+
}
|
|
11275
|
+
return { newId: id };
|
|
11276
|
+
}
|
|
11277
|
+
};
|
|
11278
|
+
|
|
11279
|
+
// src/export_registrations/index.ts
|
|
11280
|
+
function registerAllBuiltinEntities() {
|
|
11281
|
+
const registry = import_core51.ExportableEntityRegistry.getInstance();
|
|
11282
|
+
registry.register(skillRegistration);
|
|
11283
|
+
registry.register(agentRegistration);
|
|
11284
|
+
registry.register(bindingRegistration);
|
|
11285
|
+
registry.register(databaseConfigRegistration);
|
|
11286
|
+
registry.register(metricsConfigRegistration);
|
|
11287
|
+
registry.register(mcpConfigRegistration);
|
|
11288
|
+
registry.register(connectionRegistration);
|
|
11289
|
+
registry.register(collectionRegistration);
|
|
11290
|
+
registry.register(channelInstallationRegistration);
|
|
11291
|
+
registry.register(menuRegistration);
|
|
11292
|
+
registry.register(taskRegistration);
|
|
11293
|
+
registry.register(a2aApiKeyRegistration);
|
|
11294
|
+
registry.register(evalRegistration);
|
|
11295
|
+
}
|
|
11296
|
+
|
|
9502
11297
|
// src/router/MessageRouter.ts
|
|
9503
|
-
var
|
|
9504
|
-
var
|
|
11298
|
+
var import_core52 = require("@axiom-lattice/core");
|
|
11299
|
+
var import_crypto10 = require("crypto");
|
|
9505
11300
|
var BindingNotFoundError = class extends Error {
|
|
9506
11301
|
constructor(message) {
|
|
9507
11302
|
super(message);
|
|
@@ -9661,7 +11456,7 @@ var MessageRouter = class {
|
|
|
9661
11456
|
channel: message.channel,
|
|
9662
11457
|
adapterChannel: adapter.channel
|
|
9663
11458
|
}, "Thread resolved by adapter strategy");
|
|
9664
|
-
const threadStore = (0,
|
|
11459
|
+
const threadStore = (0, import_core52.getStoreLattice)("default", "thread").store;
|
|
9665
11460
|
try {
|
|
9666
11461
|
await threadStore.createThread(
|
|
9667
11462
|
tenantId,
|
|
@@ -9698,8 +11493,8 @@ var MessageRouter = class {
|
|
|
9698
11493
|
}
|
|
9699
11494
|
}
|
|
9700
11495
|
if (!threadId) {
|
|
9701
|
-
const threadStore = (0,
|
|
9702
|
-
const newThreadId = (0,
|
|
11496
|
+
const threadStore = (0, import_core52.getStoreLattice)("default", "thread").store;
|
|
11497
|
+
const newThreadId = (0, import_crypto10.randomUUID)();
|
|
9703
11498
|
console.log({
|
|
9704
11499
|
event: "dispatch:thread:create",
|
|
9705
11500
|
agentId,
|
|
@@ -9738,7 +11533,7 @@ var MessageRouter = class {
|
|
|
9738
11533
|
senderId: message.sender.id,
|
|
9739
11534
|
contentLength: message.content.text.length
|
|
9740
11535
|
}, "Dispatching to agent");
|
|
9741
|
-
const agent =
|
|
11536
|
+
const agent = import_core52.agentInstanceManager.getAgent({
|
|
9742
11537
|
tenant_id: tenantId,
|
|
9743
11538
|
assistant_id: agentId,
|
|
9744
11539
|
thread_id: threadId,
|
|
@@ -9983,7 +11778,7 @@ function createAuditLoggerMiddleware() {
|
|
|
9983
11778
|
}
|
|
9984
11779
|
|
|
9985
11780
|
// src/index.ts
|
|
9986
|
-
var
|
|
11781
|
+
var import_core56 = require("@axiom-lattice/core");
|
|
9987
11782
|
|
|
9988
11783
|
// src/swagger.ts
|
|
9989
11784
|
var import_swagger = __toESM(require("@fastify/swagger"));
|
|
@@ -10048,7 +11843,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
|
|
|
10048
11843
|
};
|
|
10049
11844
|
|
|
10050
11845
|
// src/services/agent_task_consumer.ts
|
|
10051
|
-
var
|
|
11846
|
+
var import_core53 = require("@axiom-lattice/core");
|
|
10052
11847
|
var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
10053
11848
|
const {
|
|
10054
11849
|
assistant_id,
|
|
@@ -10066,17 +11861,17 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
10066
11861
|
console.log(
|
|
10067
11862
|
`\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
10068
11863
|
);
|
|
10069
|
-
const agent =
|
|
10070
|
-
await agent.addMessage({ input, command, custom_run_config: runConfig },
|
|
11864
|
+
const agent = import_core53.agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
|
|
11865
|
+
await agent.addMessage({ input, command, custom_run_config: runConfig }, import_core53.QueueMode.STEER);
|
|
10071
11866
|
if (callback_event) {
|
|
10072
11867
|
agent.subscribeOnce("message:completed", (evt) => {
|
|
10073
|
-
|
|
11868
|
+
import_core53.eventBus.publish(callback_event, {
|
|
10074
11869
|
success: true,
|
|
10075
11870
|
state: evt.state
|
|
10076
11871
|
});
|
|
10077
11872
|
if (main_thread_id && main_tenant_id) {
|
|
10078
11873
|
try {
|
|
10079
|
-
const mainAgent =
|
|
11874
|
+
const mainAgent = import_core53.agentInstanceManager.getAgent({
|
|
10080
11875
|
assistant_id: main_assistant_id ?? assistant_id,
|
|
10081
11876
|
thread_id: main_thread_id,
|
|
10082
11877
|
tenant_id: main_tenant_id,
|
|
@@ -10106,7 +11901,7 @@ ${summary}`
|
|
|
10106
11901
|
}
|
|
10107
11902
|
});
|
|
10108
11903
|
agent.subscribeOnce("message:interrupted", (evt) => {
|
|
10109
|
-
|
|
11904
|
+
import_core53.eventBus.publish(callback_event, {
|
|
10110
11905
|
success: true,
|
|
10111
11906
|
state: evt.state
|
|
10112
11907
|
});
|
|
@@ -10129,7 +11924,7 @@ ${summary}`
|
|
|
10129
11924
|
return handleAgentTask(taskRequest, nextRetryCount);
|
|
10130
11925
|
}
|
|
10131
11926
|
if (callback_event) {
|
|
10132
|
-
|
|
11927
|
+
import_core53.eventBus.publish(callback_event, {
|
|
10133
11928
|
success: false,
|
|
10134
11929
|
error: error instanceof Error ? error.message : String(error)
|
|
10135
11930
|
});
|
|
@@ -10166,7 +11961,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
10166
11961
|
* 初始化事件监听和队列轮询
|
|
10167
11962
|
*/
|
|
10168
11963
|
initialize() {
|
|
10169
|
-
|
|
11964
|
+
import_core53.eventBus.subscribe(import_core53.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
|
|
10170
11965
|
this.startPollingQueue();
|
|
10171
11966
|
console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
|
|
10172
11967
|
}
|
|
@@ -10285,7 +12080,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
10285
12080
|
handleAgentTask(taskRequest).catch((error) => {
|
|
10286
12081
|
console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
|
|
10287
12082
|
if (taskRequest.callback_event) {
|
|
10288
|
-
|
|
12083
|
+
import_core53.eventBus.publish(taskRequest.callback_event, {
|
|
10289
12084
|
success: false,
|
|
10290
12085
|
error: error instanceof Error ? error.message : String(error)
|
|
10291
12086
|
});
|
|
@@ -10300,7 +12095,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
|
|
|
10300
12095
|
var AgentTaskConsumer = _AgentTaskConsumer;
|
|
10301
12096
|
|
|
10302
12097
|
// src/index.ts
|
|
10303
|
-
var
|
|
12098
|
+
var import_core57 = require("@axiom-lattice/core");
|
|
10304
12099
|
var import_protocols5 = require("@axiom-lattice/protocols");
|
|
10305
12100
|
var import_meta = {};
|
|
10306
12101
|
process.on("unhandledRejection", (reason, promise) => {
|
|
@@ -10316,11 +12111,11 @@ var DEFAULT_LOGGER_CONFIG = {
|
|
|
10316
12111
|
var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
|
|
10317
12112
|
var logger5 = loggerLattice.client;
|
|
10318
12113
|
function initializeLogger(config) {
|
|
10319
|
-
if (
|
|
10320
|
-
|
|
12114
|
+
if (import_core57.loggerLatticeManager.hasLattice("default")) {
|
|
12115
|
+
import_core57.loggerLatticeManager.removeLattice("default");
|
|
10321
12116
|
}
|
|
10322
|
-
(0,
|
|
10323
|
-
return (0,
|
|
12117
|
+
(0, import_core57.registerLoggerLattice)("default", config);
|
|
12118
|
+
return (0, import_core57.getLoggerLattice)("default");
|
|
10324
12119
|
}
|
|
10325
12120
|
var app = (0, import_fastify.default)({
|
|
10326
12121
|
logger: false,
|
|
@@ -10431,7 +12226,7 @@ app.setErrorHandler((error, request, reply) => {
|
|
|
10431
12226
|
});
|
|
10432
12227
|
function getConfiguredSandboxProvider() {
|
|
10433
12228
|
const sandboxProviderType = process.env.SANDBOX_PROVIDER_TYPE || "microsandbox-remote";
|
|
10434
|
-
return (0,
|
|
12229
|
+
return (0, import_core57.createSandboxProvider)({
|
|
10435
12230
|
type: sandboxProviderType,
|
|
10436
12231
|
remoteBaseURL: process.env.SANDBOX_BASE_URL,
|
|
10437
12232
|
microsandboxServiceBaseURL: process.env.MICROSANDBOX_SERVICE_BASE_URL,
|
|
@@ -10447,7 +12242,7 @@ function getConfiguredSandboxProvider() {
|
|
|
10447
12242
|
}
|
|
10448
12243
|
async function restoreMcpConnections() {
|
|
10449
12244
|
try {
|
|
10450
|
-
const storeLattice = (0,
|
|
12245
|
+
const storeLattice = (0, import_core57.getStoreLattice)("default", "mcp");
|
|
10451
12246
|
const store2 = storeLattice.store;
|
|
10452
12247
|
if (!store2) {
|
|
10453
12248
|
logger5.info("MCP store not configured, skipping connection restoration");
|
|
@@ -10461,15 +12256,15 @@ async function restoreMcpConnections() {
|
|
|
10461
12256
|
for (const config of connectedConfigs) {
|
|
10462
12257
|
try {
|
|
10463
12258
|
const connection = convertToConnection2(config.config);
|
|
10464
|
-
|
|
12259
|
+
import_core57.mcpManager.addServer(config.key, connection);
|
|
10465
12260
|
} catch (err) {
|
|
10466
12261
|
logger5.warn(`Failed to prepare MCP server "${config.key}" for restoration`, { error: err });
|
|
10467
12262
|
}
|
|
10468
12263
|
}
|
|
10469
|
-
await
|
|
12264
|
+
await import_core57.mcpManager.connect();
|
|
10470
12265
|
for (const config of connectedConfigs) {
|
|
10471
12266
|
try {
|
|
10472
|
-
await
|
|
12267
|
+
await import_core57.mcpManager.registerToolsToToolLattice(config.key, config.selectedTools);
|
|
10473
12268
|
logger5.info(`MCP server "${config.key}" restored with ${config.selectedTools.length} tools`);
|
|
10474
12269
|
} catch (err) {
|
|
10475
12270
|
logger5.warn(`Failed to register tools for MCP server "${config.key}"`, { error: err });
|
|
@@ -10499,10 +12294,10 @@ var start = async (config) => {
|
|
|
10499
12294
|
const { wechatChannelAdapter: wechatChannelAdapter2 } = await Promise.resolve().then(() => (init_WechatChannelAdapter(), WechatChannelAdapter_exports));
|
|
10500
12295
|
adapterRegistry.register(wechatChannelAdapter2);
|
|
10501
12296
|
try {
|
|
10502
|
-
const { getStoreLattice:
|
|
10503
|
-
const bindingStore =
|
|
10504
|
-
const installationStore =
|
|
10505
|
-
(0,
|
|
12297
|
+
const { getStoreLattice: getStore15 } = await import("@axiom-lattice/core");
|
|
12298
|
+
const bindingStore = getStore15("default", "channelBinding").store;
|
|
12299
|
+
const installationStore = getStore15("default", "channelInstallation").store;
|
|
12300
|
+
(0, import_core56.setBindingRegistry)(bindingStore);
|
|
10506
12301
|
const router = new MessageRouter({
|
|
10507
12302
|
middlewares: [
|
|
10508
12303
|
createDeduplicationMiddleware(),
|
|
@@ -10515,7 +12310,7 @@ var start = async (config) => {
|
|
|
10515
12310
|
});
|
|
10516
12311
|
channelDeps = { router, installationStore };
|
|
10517
12312
|
try {
|
|
10518
|
-
const a2aKeyStore =
|
|
12313
|
+
const a2aKeyStore = getStore15("default", "a2aApiKey").store;
|
|
10519
12314
|
const a2a = await Promise.resolve().then(() => (init_a2a(), a2a_exports));
|
|
10520
12315
|
a2a.setA2AKeyStore(a2aKeyStore);
|
|
10521
12316
|
await a2a.refreshStoreKeyMap();
|
|
@@ -10527,27 +12322,29 @@ var start = async (config) => {
|
|
|
10527
12322
|
error: err instanceof Error ? err.message : String(err)
|
|
10528
12323
|
});
|
|
10529
12324
|
}
|
|
12325
|
+
(0, import_core56.setEvalRunService)(evalRunner);
|
|
10530
12326
|
try {
|
|
10531
|
-
const menuStore = (0,
|
|
10532
|
-
(0,
|
|
12327
|
+
const menuStore = (0, import_core57.getStoreLattice)("default", "menu").store;
|
|
12328
|
+
(0, import_core56.setMenuRegistry)(menuStore);
|
|
10533
12329
|
logger5.info("Menu registry initialized");
|
|
10534
12330
|
} catch {
|
|
10535
12331
|
}
|
|
12332
|
+
registerAllBuiltinEntities();
|
|
10536
12333
|
if (channelDeps?.router) {
|
|
10537
12334
|
setChannelControllerDeps({ adapterRegistry, router: channelDeps.router });
|
|
10538
12335
|
}
|
|
10539
12336
|
registerLatticeRoutes(app, channelDeps);
|
|
10540
|
-
if (!
|
|
10541
|
-
|
|
12337
|
+
if (!import_core57.sandboxLatticeManager.hasLattice("default")) {
|
|
12338
|
+
import_core57.sandboxLatticeManager.registerLattice("default", getConfiguredSandboxProvider());
|
|
10542
12339
|
logger5.info("Registered sandbox manager from env configuration");
|
|
10543
12340
|
}
|
|
10544
12341
|
try {
|
|
10545
12342
|
const { ResourceController: ResourceController2 } = await Promise.resolve().then(() => (init_resources(), resources_exports));
|
|
10546
|
-
const sharedResourceStore = (0,
|
|
10547
|
-
const cache = new
|
|
12343
|
+
const sharedResourceStore = (0, import_core57.getStoreLattice)("default", "sharedResource").store;
|
|
12344
|
+
const cache = new import_core57.TokenCache();
|
|
10548
12345
|
const resourceController = new ResourceController2({
|
|
10549
12346
|
store: sharedResourceStore,
|
|
10550
|
-
sandboxManager:
|
|
12347
|
+
sandboxManager: import_core57.sandboxLatticeManager,
|
|
10551
12348
|
cache,
|
|
10552
12349
|
logger: logger5
|
|
10553
12350
|
});
|
|
@@ -10587,11 +12384,13 @@ var start = async (config) => {
|
|
|
10587
12384
|
agentTaskConsumer.startPollingQueue();
|
|
10588
12385
|
}
|
|
10589
12386
|
}
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
12387
|
+
if (process.env.AXIOM_RESTORE_PENDING_ON_STARTUP === "true") {
|
|
12388
|
+
import_core57.agentInstanceManager.restore().then((stats) => {
|
|
12389
|
+
logger5.info(`Agent recovery complete: ${stats.restored} threads restored, ${stats.errors} errors`);
|
|
12390
|
+
}).catch((error) => {
|
|
12391
|
+
logger5.error("Agent recovery failed", { error });
|
|
12392
|
+
});
|
|
12393
|
+
}
|
|
10595
12394
|
restoreMcpConnections().catch((error) => {
|
|
10596
12395
|
logger5.error("MCP connection restoration failed", { error });
|
|
10597
12396
|
});
|