@axiom-lattice/gateway 2.1.62 → 2.1.64
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 +12 -12
- package/CHANGELOG.md +17 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +530 -162
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +458 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/controllers/skills.ts +9 -0
- package/src/controllers/workflow-tracking.ts +385 -0
- package/src/index.ts +18 -0
- package/src/routes/index.ts +46 -0
- package/src/services/agent_task_consumer.ts +40 -2
package/dist/index.js
CHANGED
|
@@ -1399,6 +1399,9 @@ async function createSkill(request, reply) {
|
|
|
1399
1399
|
if (error.message?.includes("already exists")) {
|
|
1400
1400
|
return reply.status(409).send({ success: false, message: error.message });
|
|
1401
1401
|
}
|
|
1402
|
+
if (error.message?.includes("built-in skill")) {
|
|
1403
|
+
return reply.status(403).send({ success: false, message: error.message });
|
|
1404
|
+
}
|
|
1402
1405
|
if (error.message?.includes("must equal name") || error.message?.includes("Invalid skill name")) {
|
|
1403
1406
|
return reply.status(400).send({ success: false, message: error.message });
|
|
1404
1407
|
}
|
|
@@ -1415,6 +1418,9 @@ async function updateSkill(request, reply) {
|
|
|
1415
1418
|
}
|
|
1416
1419
|
return { success: true, message: "Successfully updated skill", data: serializeSkill(skill) };
|
|
1417
1420
|
} catch (error) {
|
|
1421
|
+
if (error.message?.includes("built-in skill")) {
|
|
1422
|
+
return reply.status(403).send({ success: false, message: error.message });
|
|
1423
|
+
}
|
|
1418
1424
|
if (error.message?.includes("Invalid skill name")) {
|
|
1419
1425
|
return reply.status(400).send({ success: false, message: error.message });
|
|
1420
1426
|
}
|
|
@@ -1430,6 +1436,9 @@ async function deleteSkill(request, reply) {
|
|
|
1430
1436
|
}
|
|
1431
1437
|
return { success: true, message: "Successfully deleted skill" };
|
|
1432
1438
|
} catch (error) {
|
|
1439
|
+
if (error.message?.includes("built-in skill")) {
|
|
1440
|
+
return reply.status(403).send({ success: false, message: error.message });
|
|
1441
|
+
}
|
|
1433
1442
|
return reply.status(500).send({ success: false, message: `Failed to delete skill: ${error.message}` });
|
|
1434
1443
|
}
|
|
1435
1444
|
}
|
|
@@ -1725,6 +1734,296 @@ async function executeSqlQuery(client, body, reply) {
|
|
|
1725
1734
|
};
|
|
1726
1735
|
}
|
|
1727
1736
|
|
|
1737
|
+
// src/controllers/workflow-tracking.ts
|
|
1738
|
+
var import_core13 = require("@axiom-lattice/core");
|
|
1739
|
+
function getTenantId6(request) {
|
|
1740
|
+
const userTenantId = request.user?.tenantId;
|
|
1741
|
+
if (userTenantId) return userTenantId;
|
|
1742
|
+
return request.headers["x-tenant-id"] || "default";
|
|
1743
|
+
}
|
|
1744
|
+
function getTrackingStore() {
|
|
1745
|
+
try {
|
|
1746
|
+
const storeLattice = (0, import_core13.getStoreLattice)("default", "workflowTracking");
|
|
1747
|
+
return storeLattice.store;
|
|
1748
|
+
} catch {
|
|
1749
|
+
return null;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
async function getDefinitionsFromAssistants(tenantId) {
|
|
1753
|
+
try {
|
|
1754
|
+
const storeLattice = (0, import_core13.getStoreLattice)("default", "assistant");
|
|
1755
|
+
const assistantStore = storeLattice.store;
|
|
1756
|
+
const assistants = await assistantStore.getAllAssistants(tenantId);
|
|
1757
|
+
const results = [];
|
|
1758
|
+
for (const a of assistants) {
|
|
1759
|
+
const def = a.graphDefinition;
|
|
1760
|
+
if (!def || def.type !== "processing") continue;
|
|
1761
|
+
if (!def.middleware) continue;
|
|
1762
|
+
for (const mw of def.middleware) {
|
|
1763
|
+
if (mw.type === "topology" && mw.enabled && mw.config?.edges?.length > 0) {
|
|
1764
|
+
results.push({
|
|
1765
|
+
assistantId: a.id,
|
|
1766
|
+
assistantName: a.name,
|
|
1767
|
+
topologyEdges: mw.config.edges,
|
|
1768
|
+
totalEdges: mw.config.edges.length
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
return results;
|
|
1774
|
+
} catch {
|
|
1775
|
+
return [];
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
async function getAllWorkflowDefinitions(request, reply) {
|
|
1779
|
+
const tenantId = getTenantId6(request);
|
|
1780
|
+
try {
|
|
1781
|
+
const configDefs = await getDefinitionsFromAssistants(tenantId);
|
|
1782
|
+
if (configDefs.length === 0) {
|
|
1783
|
+
return {
|
|
1784
|
+
success: true,
|
|
1785
|
+
message: "No workflow definitions found",
|
|
1786
|
+
data: { records: [] }
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
const runMap = /* @__PURE__ */ new Map();
|
|
1790
|
+
try {
|
|
1791
|
+
const store = getTrackingStore();
|
|
1792
|
+
if (store) {
|
|
1793
|
+
const runs = await store.getWorkflowRunsByTenantId(tenantId);
|
|
1794
|
+
for (const r of runs) {
|
|
1795
|
+
const entry = runMap.get(r.assistantId) || { runCount: 0 };
|
|
1796
|
+
entry.runCount++;
|
|
1797
|
+
if (!entry.lastRunAt || new Date(r.startedAt) > new Date(entry.lastRunAt)) {
|
|
1798
|
+
entry.lastRunAt = r.startedAt instanceof Date ? r.startedAt.toISOString() : String(r.startedAt);
|
|
1799
|
+
}
|
|
1800
|
+
runMap.set(r.assistantId, entry);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
} catch {
|
|
1804
|
+
}
|
|
1805
|
+
const definitions = configDefs.map((d) => {
|
|
1806
|
+
const runInfo = runMap.get(d.assistantId);
|
|
1807
|
+
return {
|
|
1808
|
+
...d,
|
|
1809
|
+
lastRunAt: runInfo?.lastRunAt || null,
|
|
1810
|
+
runCount: runInfo?.runCount || 0
|
|
1811
|
+
};
|
|
1812
|
+
});
|
|
1813
|
+
return {
|
|
1814
|
+
success: true,
|
|
1815
|
+
message: "Successfully retrieved workflow definitions",
|
|
1816
|
+
data: { records: definitions }
|
|
1817
|
+
};
|
|
1818
|
+
} catch (error) {
|
|
1819
|
+
request.log.error(error, "Failed to get workflow definitions");
|
|
1820
|
+
return reply.status(500).send({ success: false, message: "Failed to retrieve workflow definitions" });
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
async function getAllWorkflowRuns(request, reply) {
|
|
1824
|
+
const tenantId = getTenantId6(request);
|
|
1825
|
+
const { assistantId, status } = request.query;
|
|
1826
|
+
try {
|
|
1827
|
+
const store = getTrackingStore();
|
|
1828
|
+
if (!store) {
|
|
1829
|
+
return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
|
|
1830
|
+
}
|
|
1831
|
+
let runs;
|
|
1832
|
+
if (assistantId) {
|
|
1833
|
+
runs = await store.getWorkflowRunsByAssistantId(tenantId, assistantId);
|
|
1834
|
+
} else {
|
|
1835
|
+
runs = await store.getWorkflowRunsByTenantId(tenantId);
|
|
1836
|
+
}
|
|
1837
|
+
if (status) {
|
|
1838
|
+
runs = runs.filter((r) => r.status === status);
|
|
1839
|
+
}
|
|
1840
|
+
return {
|
|
1841
|
+
success: true,
|
|
1842
|
+
message: "Successfully retrieved workflow runs",
|
|
1843
|
+
data: { records: runs, total: runs.length }
|
|
1844
|
+
};
|
|
1845
|
+
} catch (error) {
|
|
1846
|
+
request.log.error(error, "Failed to get workflow runs");
|
|
1847
|
+
return reply.status(500).send({ success: false, message: "Failed to retrieve workflow runs" });
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
async function getInboxItems(request, reply) {
|
|
1851
|
+
const tenantId = getTenantId6(request);
|
|
1852
|
+
try {
|
|
1853
|
+
const store = getTrackingStore();
|
|
1854
|
+
if (!store) {
|
|
1855
|
+
return { success: true, message: "No tracking store configured", data: { records: [] } };
|
|
1856
|
+
}
|
|
1857
|
+
const nameMap = {};
|
|
1858
|
+
try {
|
|
1859
|
+
const asStoreLattice = (0, import_core13.getStoreLattice)("default", "assistant");
|
|
1860
|
+
const assistantStore = asStoreLattice.store;
|
|
1861
|
+
const assistants = await assistantStore.getAllAssistants(tenantId);
|
|
1862
|
+
for (const a of assistants) {
|
|
1863
|
+
nameMap[a.id] = a.name;
|
|
1864
|
+
}
|
|
1865
|
+
} catch {
|
|
1866
|
+
}
|
|
1867
|
+
const runs = await store.getWorkflowRunsByTenantId(tenantId);
|
|
1868
|
+
const runningRuns = runs.filter((r) => r.status === "running");
|
|
1869
|
+
if (runningRuns.length === 0) {
|
|
1870
|
+
return { success: true, message: "No running workflows", data: { records: [] } };
|
|
1871
|
+
}
|
|
1872
|
+
const inboxItems = [];
|
|
1873
|
+
for (const r of runningRuns) {
|
|
1874
|
+
try {
|
|
1875
|
+
const agent = import_core13.agentInstanceManager.getAgent({
|
|
1876
|
+
assistant_id: r.assistantId,
|
|
1877
|
+
thread_id: r.threadId,
|
|
1878
|
+
tenant_id: r.tenantId
|
|
1879
|
+
});
|
|
1880
|
+
const runStatus = await agent.getRunStatus();
|
|
1881
|
+
if (runStatus !== "interrupted") continue;
|
|
1882
|
+
const state = await agent.getCurrentState();
|
|
1883
|
+
const interrupts = state.tasks?.flatMap((t) => t.interrupts || []) || [];
|
|
1884
|
+
for (const i of interrupts) {
|
|
1885
|
+
inboxItems.push({
|
|
1886
|
+
runId: r.id,
|
|
1887
|
+
assistantId: r.assistantId,
|
|
1888
|
+
assistantName: nameMap[r.assistantId] || r.assistantId,
|
|
1889
|
+
threadId: r.threadId,
|
|
1890
|
+
tenantId: r.tenantId,
|
|
1891
|
+
interruptId: i.id,
|
|
1892
|
+
interruptValue: i.value,
|
|
1893
|
+
startedAt: r.startedAt,
|
|
1894
|
+
totalEdges: r.totalEdges,
|
|
1895
|
+
completedEdges: r.completedEdges
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
} catch {
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
inboxItems.sort(
|
|
1902
|
+
(a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
|
|
1903
|
+
);
|
|
1904
|
+
return {
|
|
1905
|
+
success: true,
|
|
1906
|
+
message: "Successfully retrieved inbox items",
|
|
1907
|
+
data: { records: inboxItems }
|
|
1908
|
+
};
|
|
1909
|
+
} catch (error) {
|
|
1910
|
+
request.log.error(error, "Failed to get inbox items");
|
|
1911
|
+
return reply.status(500).send({ success: false, message: "Failed to retrieve inbox items" });
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
async function getWorkflowDefinitions(request, reply) {
|
|
1915
|
+
const { assistantId } = request.params;
|
|
1916
|
+
const tenantId = getTenantId6(request);
|
|
1917
|
+
try {
|
|
1918
|
+
const store = getTrackingStore();
|
|
1919
|
+
if (!store) {
|
|
1920
|
+
return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
|
|
1921
|
+
}
|
|
1922
|
+
const runs = await store.getWorkflowRunsByAssistantId(tenantId, assistantId);
|
|
1923
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1924
|
+
const definitions = runs.filter((r) => {
|
|
1925
|
+
const key = JSON.stringify(r.topologyEdges);
|
|
1926
|
+
if (seen.has(key)) return false;
|
|
1927
|
+
seen.add(key);
|
|
1928
|
+
return true;
|
|
1929
|
+
}).map((r) => ({
|
|
1930
|
+
assistantId: r.assistantId,
|
|
1931
|
+
topologyEdges: r.topologyEdges,
|
|
1932
|
+
totalEdges: r.totalEdges,
|
|
1933
|
+
lastRunAt: r.startedAt
|
|
1934
|
+
}));
|
|
1935
|
+
return {
|
|
1936
|
+
success: true,
|
|
1937
|
+
message: "Successfully retrieved workflow definitions",
|
|
1938
|
+
data: { records: definitions }
|
|
1939
|
+
};
|
|
1940
|
+
} catch (error) {
|
|
1941
|
+
request.log.error(error, "Failed to get workflow definitions");
|
|
1942
|
+
return reply.status(500).send({ success: false, message: "Failed to retrieve workflow definitions" });
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
async function getWorkflowRuns(request, reply) {
|
|
1946
|
+
const { threadId } = request.params;
|
|
1947
|
+
const tenantId = getTenantId6(request);
|
|
1948
|
+
try {
|
|
1949
|
+
const store = getTrackingStore();
|
|
1950
|
+
if (!store) {
|
|
1951
|
+
return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
|
|
1952
|
+
}
|
|
1953
|
+
const runs = await store.getWorkflowRunsByThreadId(tenantId, threadId);
|
|
1954
|
+
return {
|
|
1955
|
+
success: true,
|
|
1956
|
+
message: "Successfully retrieved workflow runs",
|
|
1957
|
+
data: { records: runs, total: runs.length }
|
|
1958
|
+
};
|
|
1959
|
+
} catch (error) {
|
|
1960
|
+
request.log.error(error, "Failed to get workflow runs");
|
|
1961
|
+
return reply.status(500).send({ success: false, message: "Failed to retrieve workflow runs" });
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
async function getWorkflowRun(request, reply) {
|
|
1965
|
+
const { runId } = request.params;
|
|
1966
|
+
try {
|
|
1967
|
+
const store = getTrackingStore();
|
|
1968
|
+
if (!store) {
|
|
1969
|
+
return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
|
|
1970
|
+
}
|
|
1971
|
+
const run = await store.getWorkflowRun(runId);
|
|
1972
|
+
if (!run) {
|
|
1973
|
+
return reply.status(404).send({ success: false, message: "Workflow run not found" });
|
|
1974
|
+
}
|
|
1975
|
+
return { success: true, message: "Successfully retrieved workflow run", data: run };
|
|
1976
|
+
} catch (error) {
|
|
1977
|
+
request.log.error(error, "Failed to get workflow run");
|
|
1978
|
+
return reply.status(500).send({ success: false, message: "Failed to retrieve workflow run" });
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
async function getRunSteps(request, reply) {
|
|
1982
|
+
const { runId } = request.params;
|
|
1983
|
+
const { step_type, status: stepStatus } = request.query;
|
|
1984
|
+
try {
|
|
1985
|
+
const store = getTrackingStore();
|
|
1986
|
+
if (!store) {
|
|
1987
|
+
return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
|
|
1988
|
+
}
|
|
1989
|
+
let steps;
|
|
1990
|
+
if (step_type) {
|
|
1991
|
+
steps = await store.getRunStepsByType(runId, step_type);
|
|
1992
|
+
} else {
|
|
1993
|
+
steps = await store.getRunSteps(runId);
|
|
1994
|
+
}
|
|
1995
|
+
if (stepStatus) {
|
|
1996
|
+
steps = steps.filter((s) => s.status === stepStatus);
|
|
1997
|
+
}
|
|
1998
|
+
return {
|
|
1999
|
+
success: true,
|
|
2000
|
+
message: "Successfully retrieved run steps",
|
|
2001
|
+
data: { records: steps, total: steps.length }
|
|
2002
|
+
};
|
|
2003
|
+
} catch (error) {
|
|
2004
|
+
request.log.error(error, "Failed to get run steps");
|
|
2005
|
+
return reply.status(500).send({ success: false, message: "Failed to retrieve run steps" });
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
async function getRunTasks(request, reply) {
|
|
2009
|
+
const { runId } = request.params;
|
|
2010
|
+
try {
|
|
2011
|
+
const store = getTrackingStore();
|
|
2012
|
+
if (!store) {
|
|
2013
|
+
return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
|
|
2014
|
+
}
|
|
2015
|
+
const steps = await store.getInterruptedSteps(runId);
|
|
2016
|
+
return {
|
|
2017
|
+
success: true,
|
|
2018
|
+
message: "Successfully retrieved user tasks",
|
|
2019
|
+
data: { records: steps, total: steps.length }
|
|
2020
|
+
};
|
|
2021
|
+
} catch (error) {
|
|
2022
|
+
request.log.error(error, "Failed to get run tasks");
|
|
2023
|
+
return reply.status(500).send({ success: false, message: "Failed to retrieve user tasks" });
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
|
|
1728
2027
|
// src/schemas/data-query.ts
|
|
1729
2028
|
var dataQuerySchema = {
|
|
1730
2029
|
description: "Execute data query (semantic or SQL)",
|
|
@@ -2066,7 +2365,7 @@ var getHealthSchema = {
|
|
|
2066
2365
|
};
|
|
2067
2366
|
|
|
2068
2367
|
// src/controllers/thread_status.ts
|
|
2069
|
-
var
|
|
2368
|
+
var import_core14 = require("@axiom-lattice/core");
|
|
2070
2369
|
async function removePendingMessageHandler(request, reply) {
|
|
2071
2370
|
try {
|
|
2072
2371
|
const { assistant_id, thread_id, message_id } = request.params;
|
|
@@ -2079,7 +2378,7 @@ async function removePendingMessageHandler(request, reply) {
|
|
|
2079
2378
|
if (!assistant_id) {
|
|
2080
2379
|
return reply.code(400).send({ error: "Missing assistant_id parameter" });
|
|
2081
2380
|
}
|
|
2082
|
-
const agent =
|
|
2381
|
+
const agent = import_core14.agentInstanceManager.getAgent({
|
|
2083
2382
|
assistant_id,
|
|
2084
2383
|
thread_id,
|
|
2085
2384
|
tenant_id,
|
|
@@ -2113,7 +2412,7 @@ async function removePendingMessageHandler(request, reply) {
|
|
|
2113
2412
|
}
|
|
2114
2413
|
|
|
2115
2414
|
// src/services/sandbox_service.ts
|
|
2116
|
-
var
|
|
2415
|
+
var import_core15 = require("@axiom-lattice/core");
|
|
2117
2416
|
var ERROR_HTML = `<!DOCTYPE html>
|
|
2118
2417
|
<html lang="zh-CN">
|
|
2119
2418
|
<head>
|
|
@@ -2225,7 +2524,7 @@ var ERROR_HTML = `<!DOCTYPE html>
|
|
|
2225
2524
|
</html>`;
|
|
2226
2525
|
var SandboxService = class {
|
|
2227
2526
|
getFilesystemVmIsolation(tenantId, assistantId) {
|
|
2228
|
-
const agentLattice =
|
|
2527
|
+
const agentLattice = import_core15.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
|
|
2229
2528
|
if (!agentLattice) {
|
|
2230
2529
|
return null;
|
|
2231
2530
|
}
|
|
@@ -2239,9 +2538,9 @@ var SandboxService = class {
|
|
|
2239
2538
|
computeSandboxName(assistantId, threadId, vmIsolation, tenantId, workspaceId, projectId) {
|
|
2240
2539
|
switch (vmIsolation) {
|
|
2241
2540
|
case "agent":
|
|
2242
|
-
return (0,
|
|
2541
|
+
return (0, import_core15.normalizeSandboxName)(`${tenantId ?? "default"}-${assistantId}`);
|
|
2243
2542
|
case "project":
|
|
2244
|
-
return (0,
|
|
2543
|
+
return (0, import_core15.normalizeSandboxName)(
|
|
2245
2544
|
`${tenantId ?? "default"}-${workspaceId ?? "default"}-${projectId ?? "default"}`
|
|
2246
2545
|
);
|
|
2247
2546
|
case "global":
|
|
@@ -2297,7 +2596,7 @@ var SandboxService = class {
|
|
|
2297
2596
|
var sandboxService = new SandboxService();
|
|
2298
2597
|
|
|
2299
2598
|
// src/controllers/sandbox.ts
|
|
2300
|
-
var
|
|
2599
|
+
var import_core16 = require("@axiom-lattice/core");
|
|
2301
2600
|
function getFilenameFromPath(path3) {
|
|
2302
2601
|
const segments = path3.replace(/\/+$/, "").split("/");
|
|
2303
2602
|
return segments[segments.length - 1] || "download";
|
|
@@ -2339,7 +2638,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2339
2638
|
threadId,
|
|
2340
2639
|
vmIsolation
|
|
2341
2640
|
);
|
|
2342
|
-
const sandboxManager = (0,
|
|
2641
|
+
const sandboxManager = (0, import_core16.getSandBoxManager)();
|
|
2343
2642
|
const sandbox = await sandboxManager.createSandbox(sandboxName);
|
|
2344
2643
|
try {
|
|
2345
2644
|
const data = await request.file();
|
|
@@ -2383,7 +2682,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2383
2682
|
threadId,
|
|
2384
2683
|
vmIsolation
|
|
2385
2684
|
);
|
|
2386
|
-
const sandboxManager = (0,
|
|
2685
|
+
const sandboxManager = (0, import_core16.getSandBoxManager)();
|
|
2387
2686
|
const sandbox = await sandboxManager.createSandbox(sandboxName);
|
|
2388
2687
|
try {
|
|
2389
2688
|
const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
|
|
@@ -2409,14 +2708,14 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2409
2708
|
// src/controllers/workspace.ts
|
|
2410
2709
|
var fs = __toESM(require("fs/promises"));
|
|
2411
2710
|
var path = __toESM(require("path"));
|
|
2412
|
-
var import_core16 = require("@axiom-lattice/core");
|
|
2413
2711
|
var import_core17 = require("@axiom-lattice/core");
|
|
2414
2712
|
var import_core18 = require("@axiom-lattice/core");
|
|
2713
|
+
var import_core19 = require("@axiom-lattice/core");
|
|
2415
2714
|
var import_uuid2 = require("uuid");
|
|
2416
2715
|
var WorkspaceController = class {
|
|
2417
2716
|
constructor() {
|
|
2418
|
-
this.workspaceStore = (0,
|
|
2419
|
-
this.projectStore = (0,
|
|
2717
|
+
this.workspaceStore = (0, import_core17.getStoreLattice)("default", "workspace").store;
|
|
2718
|
+
this.projectStore = (0, import_core17.getStoreLattice)("default", "project").store;
|
|
2420
2719
|
}
|
|
2421
2720
|
getTenantId(request) {
|
|
2422
2721
|
const userTenantId = request.user?.tenantId;
|
|
@@ -2549,7 +2848,7 @@ var WorkspaceController = class {
|
|
|
2549
2848
|
throw new Error("Workspace not found");
|
|
2550
2849
|
}
|
|
2551
2850
|
if (workspace.storageType === "sandbox") {
|
|
2552
|
-
const sandboxManager = (0,
|
|
2851
|
+
const sandboxManager = (0, import_core19.getSandBoxManager)();
|
|
2553
2852
|
const volumeConfig = {
|
|
2554
2853
|
assistant_id: assistantId || "",
|
|
2555
2854
|
thread_id: "",
|
|
@@ -2563,14 +2862,14 @@ var WorkspaceController = class {
|
|
|
2563
2862
|
}
|
|
2564
2863
|
const sandbox = await sandboxManager.getSandboxFromConfig(volumeConfig);
|
|
2565
2864
|
return {
|
|
2566
|
-
backend: new
|
|
2865
|
+
backend: new import_core18.SandboxFilesystem({
|
|
2567
2866
|
sandboxInstance: sandbox
|
|
2568
2867
|
}),
|
|
2569
2868
|
workspace
|
|
2570
2869
|
};
|
|
2571
2870
|
} else {
|
|
2572
2871
|
return {
|
|
2573
|
-
backend: new
|
|
2872
|
+
backend: new import_core18.FilesystemBackend({
|
|
2574
2873
|
rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
|
|
2575
2874
|
virtualMode: true
|
|
2576
2875
|
}),
|
|
@@ -2648,7 +2947,7 @@ var WorkspaceController = class {
|
|
|
2648
2947
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId, assistantId);
|
|
2649
2948
|
const resolvedPath = filePath;
|
|
2650
2949
|
if (workspace.storageType === "sandbox") {
|
|
2651
|
-
const sandboxManager = (0,
|
|
2950
|
+
const sandboxManager = (0, import_core19.getSandBoxManager)();
|
|
2652
2951
|
const volumeConfig = {
|
|
2653
2952
|
assistant_id: assistantId || "",
|
|
2654
2953
|
thread_id: "",
|
|
@@ -2698,7 +2997,7 @@ var WorkspaceController = class {
|
|
|
2698
2997
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId, assistantId);
|
|
2699
2998
|
const resolvedPath = filePath;
|
|
2700
2999
|
if (workspace.storageType === "sandbox") {
|
|
2701
|
-
const sandboxManager = (0,
|
|
3000
|
+
const sandboxManager = (0, import_core19.getSandBoxManager)();
|
|
2702
3001
|
const volumeConfig = {
|
|
2703
3002
|
assistant_id: assistantId || "",
|
|
2704
3003
|
thread_id: "",
|
|
@@ -2832,7 +3131,7 @@ var WorkspaceController = class {
|
|
|
2832
3131
|
return reply.status(400).send({ success: false, error: "Invalid path parameter" });
|
|
2833
3132
|
}
|
|
2834
3133
|
if (workspace.storageType === "sandbox") {
|
|
2835
|
-
const sandboxManager = (0,
|
|
3134
|
+
const sandboxManager = (0, import_core19.getSandBoxManager)();
|
|
2836
3135
|
const volumeConfig = {
|
|
2837
3136
|
assistant_id: assistantId || "",
|
|
2838
3137
|
thread_id: "",
|
|
@@ -2940,9 +3239,9 @@ function registerWorkspaceRoutes(app2) {
|
|
|
2940
3239
|
}
|
|
2941
3240
|
|
|
2942
3241
|
// src/controllers/database-configs.ts
|
|
2943
|
-
var
|
|
3242
|
+
var import_core20 = require("@axiom-lattice/core");
|
|
2944
3243
|
var import_crypto3 = require("crypto");
|
|
2945
|
-
function
|
|
3244
|
+
function getTenantId7(request) {
|
|
2946
3245
|
const userTenantId = request.user?.tenantId;
|
|
2947
3246
|
if (userTenantId) {
|
|
2948
3247
|
return userTenantId;
|
|
@@ -2950,9 +3249,9 @@ function getTenantId6(request) {
|
|
|
2950
3249
|
return request.headers["x-tenant-id"] || "default";
|
|
2951
3250
|
}
|
|
2952
3251
|
async function getDatabaseConfigList(request, reply) {
|
|
2953
|
-
const tenantId =
|
|
3252
|
+
const tenantId = getTenantId7(request);
|
|
2954
3253
|
try {
|
|
2955
|
-
const storeLattice = (0,
|
|
3254
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
2956
3255
|
const store = storeLattice.store;
|
|
2957
3256
|
const configs = await store.getAllConfigs(tenantId);
|
|
2958
3257
|
console.log("Backend: getAllConfigs returned:", configs);
|
|
@@ -2980,10 +3279,10 @@ async function getDatabaseConfigList(request, reply) {
|
|
|
2980
3279
|
}
|
|
2981
3280
|
}
|
|
2982
3281
|
async function getDatabaseConfig(request, reply) {
|
|
2983
|
-
const tenantId =
|
|
3282
|
+
const tenantId = getTenantId7(request);
|
|
2984
3283
|
const { key } = request.params;
|
|
2985
3284
|
try {
|
|
2986
|
-
const storeLattice = (0,
|
|
3285
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
2987
3286
|
const store = storeLattice.store;
|
|
2988
3287
|
const config = await store.getConfigByKey(tenantId, key);
|
|
2989
3288
|
if (!config) {
|
|
@@ -3006,10 +3305,10 @@ async function getDatabaseConfig(request, reply) {
|
|
|
3006
3305
|
}
|
|
3007
3306
|
}
|
|
3008
3307
|
async function createDatabaseConfig(request, reply) {
|
|
3009
|
-
const tenantId =
|
|
3308
|
+
const tenantId = getTenantId7(request);
|
|
3010
3309
|
const body = request.body;
|
|
3011
3310
|
try {
|
|
3012
|
-
const storeLattice = (0,
|
|
3311
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
3013
3312
|
const store = storeLattice.store;
|
|
3014
3313
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3015
3314
|
if (existing) {
|
|
@@ -3022,7 +3321,7 @@ async function createDatabaseConfig(request, reply) {
|
|
|
3022
3321
|
const id = body.id || (0, import_crypto3.randomUUID)();
|
|
3023
3322
|
const config = await store.createConfig(tenantId, id, body);
|
|
3024
3323
|
try {
|
|
3025
|
-
|
|
3324
|
+
import_core20.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
|
|
3026
3325
|
} catch (error) {
|
|
3027
3326
|
console.warn("Failed to auto-register database:", error);
|
|
3028
3327
|
}
|
|
@@ -3041,11 +3340,11 @@ async function createDatabaseConfig(request, reply) {
|
|
|
3041
3340
|
}
|
|
3042
3341
|
}
|
|
3043
3342
|
async function updateDatabaseConfig(request, reply) {
|
|
3044
|
-
const tenantId =
|
|
3343
|
+
const tenantId = getTenantId7(request);
|
|
3045
3344
|
const { key } = request.params;
|
|
3046
3345
|
const updates = request.body;
|
|
3047
3346
|
try {
|
|
3048
|
-
const storeLattice = (0,
|
|
3347
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
3049
3348
|
const store = storeLattice.store;
|
|
3050
3349
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3051
3350
|
if (!existing) {
|
|
@@ -3064,7 +3363,7 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
3064
3363
|
}
|
|
3065
3364
|
if (updates.config) {
|
|
3066
3365
|
try {
|
|
3067
|
-
|
|
3366
|
+
import_core20.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
|
|
3068
3367
|
} catch (error) {
|
|
3069
3368
|
console.warn("Failed to re-register database:", error);
|
|
3070
3369
|
}
|
|
@@ -3083,10 +3382,10 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
3083
3382
|
}
|
|
3084
3383
|
}
|
|
3085
3384
|
async function deleteDatabaseConfig(request, reply) {
|
|
3086
|
-
const tenantId =
|
|
3385
|
+
const tenantId = getTenantId7(request);
|
|
3087
3386
|
const { keyOrId } = request.params;
|
|
3088
3387
|
try {
|
|
3089
|
-
const storeLattice = (0,
|
|
3388
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
3090
3389
|
const store = storeLattice.store;
|
|
3091
3390
|
console.log("Delete request - keyOrId:", keyOrId);
|
|
3092
3391
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
@@ -3113,8 +3412,8 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
3113
3412
|
};
|
|
3114
3413
|
}
|
|
3115
3414
|
try {
|
|
3116
|
-
if (
|
|
3117
|
-
await
|
|
3415
|
+
if (import_core20.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
|
|
3416
|
+
await import_core20.sqlDatabaseManager.removeDatabase(tenantId, configKey);
|
|
3118
3417
|
}
|
|
3119
3418
|
} catch (error) {
|
|
3120
3419
|
console.warn("Failed to remove from SqlDatabaseManager:", error);
|
|
@@ -3132,10 +3431,10 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
3132
3431
|
}
|
|
3133
3432
|
}
|
|
3134
3433
|
async function testDatabaseConnection(request, reply) {
|
|
3135
|
-
const tenantId =
|
|
3434
|
+
const tenantId = getTenantId7(request);
|
|
3136
3435
|
const { key } = request.params;
|
|
3137
3436
|
try {
|
|
3138
|
-
const storeLattice = (0,
|
|
3437
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
3139
3438
|
const store = storeLattice.store;
|
|
3140
3439
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3141
3440
|
if (!config) {
|
|
@@ -3146,16 +3445,16 @@ async function testDatabaseConnection(request, reply) {
|
|
|
3146
3445
|
};
|
|
3147
3446
|
}
|
|
3148
3447
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
3149
|
-
|
|
3448
|
+
import_core20.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
|
|
3150
3449
|
const startTime = Date.now();
|
|
3151
|
-
const db = await
|
|
3450
|
+
const db = await import_core20.sqlDatabaseManager.getDatabase(tenantId, testKey);
|
|
3152
3451
|
try {
|
|
3153
3452
|
await db.connect();
|
|
3154
3453
|
await db.listTables();
|
|
3155
3454
|
const latency = Date.now() - startTime;
|
|
3156
3455
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3157
3456
|
await db.disconnect();
|
|
3158
|
-
await
|
|
3457
|
+
await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
3159
3458
|
return {
|
|
3160
3459
|
success: true,
|
|
3161
3460
|
message: "Connection test successful",
|
|
@@ -3167,7 +3466,7 @@ async function testDatabaseConnection(request, reply) {
|
|
|
3167
3466
|
} catch (error) {
|
|
3168
3467
|
try {
|
|
3169
3468
|
await db.disconnect();
|
|
3170
|
-
await
|
|
3469
|
+
await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
3171
3470
|
} catch {
|
|
3172
3471
|
}
|
|
3173
3472
|
return {
|
|
@@ -3219,9 +3518,9 @@ function registerDatabaseConfigRoutes(app2) {
|
|
|
3219
3518
|
}
|
|
3220
3519
|
|
|
3221
3520
|
// src/controllers/metrics-configs.ts
|
|
3222
|
-
var
|
|
3521
|
+
var import_core21 = require("@axiom-lattice/core");
|
|
3223
3522
|
var import_crypto4 = require("crypto");
|
|
3224
|
-
function
|
|
3523
|
+
function getTenantId8(request) {
|
|
3225
3524
|
const userTenantId = request.user?.tenantId;
|
|
3226
3525
|
if (userTenantId) {
|
|
3227
3526
|
return userTenantId;
|
|
@@ -3229,9 +3528,9 @@ function getTenantId7(request) {
|
|
|
3229
3528
|
return request.headers["x-tenant-id"] || "default";
|
|
3230
3529
|
}
|
|
3231
3530
|
async function getMetricsServerConfigList(request, reply) {
|
|
3232
|
-
const tenantId =
|
|
3531
|
+
const tenantId = getTenantId8(request);
|
|
3233
3532
|
try {
|
|
3234
|
-
const storeLattice = (0,
|
|
3533
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3235
3534
|
const store = storeLattice.store;
|
|
3236
3535
|
const configs = await store.getAllConfigs(tenantId);
|
|
3237
3536
|
return {
|
|
@@ -3255,10 +3554,10 @@ async function getMetricsServerConfigList(request, reply) {
|
|
|
3255
3554
|
}
|
|
3256
3555
|
}
|
|
3257
3556
|
async function getMetricsServerConfig(request, reply) {
|
|
3258
|
-
const tenantId =
|
|
3557
|
+
const tenantId = getTenantId8(request);
|
|
3259
3558
|
const { key } = request.params;
|
|
3260
3559
|
try {
|
|
3261
|
-
const storeLattice = (0,
|
|
3560
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3262
3561
|
const store = storeLattice.store;
|
|
3263
3562
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3264
3563
|
if (!config) {
|
|
@@ -3281,10 +3580,10 @@ async function getMetricsServerConfig(request, reply) {
|
|
|
3281
3580
|
}
|
|
3282
3581
|
}
|
|
3283
3582
|
async function createMetricsServerConfig(request, reply) {
|
|
3284
|
-
const tenantId =
|
|
3583
|
+
const tenantId = getTenantId8(request);
|
|
3285
3584
|
const body = request.body;
|
|
3286
3585
|
try {
|
|
3287
|
-
const storeLattice = (0,
|
|
3586
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3288
3587
|
const store = storeLattice.store;
|
|
3289
3588
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3290
3589
|
if (existing) {
|
|
@@ -3313,7 +3612,7 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
3313
3612
|
};
|
|
3314
3613
|
const config = await store.createConfig(tenantId, id, configData);
|
|
3315
3614
|
try {
|
|
3316
|
-
|
|
3615
|
+
import_core21.metricsServerManager.registerServer(tenantId, config.key, config.config);
|
|
3317
3616
|
} catch (error) {
|
|
3318
3617
|
console.warn("Failed to auto-register metrics server:", error);
|
|
3319
3618
|
}
|
|
@@ -3332,11 +3631,11 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
3332
3631
|
}
|
|
3333
3632
|
}
|
|
3334
3633
|
async function updateMetricsServerConfig(request, reply) {
|
|
3335
|
-
const tenantId =
|
|
3634
|
+
const tenantId = getTenantId8(request);
|
|
3336
3635
|
const { key } = request.params;
|
|
3337
3636
|
const updates = request.body;
|
|
3338
3637
|
try {
|
|
3339
|
-
const storeLattice = (0,
|
|
3638
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3340
3639
|
const store = storeLattice.store;
|
|
3341
3640
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3342
3641
|
if (!existing) {
|
|
@@ -3364,7 +3663,7 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
3364
3663
|
}
|
|
3365
3664
|
if (updates.config) {
|
|
3366
3665
|
try {
|
|
3367
|
-
|
|
3666
|
+
import_core21.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
|
|
3368
3667
|
} catch (error) {
|
|
3369
3668
|
console.warn("Failed to re-register metrics server:", error);
|
|
3370
3669
|
}
|
|
@@ -3383,10 +3682,10 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
3383
3682
|
}
|
|
3384
3683
|
}
|
|
3385
3684
|
async function deleteMetricsServerConfig(request, reply) {
|
|
3386
|
-
const tenantId =
|
|
3685
|
+
const tenantId = getTenantId8(request);
|
|
3387
3686
|
const { keyOrId } = request.params;
|
|
3388
3687
|
try {
|
|
3389
|
-
const storeLattice = (0,
|
|
3688
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3390
3689
|
const store = storeLattice.store;
|
|
3391
3690
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
3392
3691
|
let configKey = keyOrId;
|
|
@@ -3411,8 +3710,8 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
3411
3710
|
};
|
|
3412
3711
|
}
|
|
3413
3712
|
try {
|
|
3414
|
-
if (
|
|
3415
|
-
|
|
3713
|
+
if (import_core21.metricsServerManager.hasServer(tenantId, configKey)) {
|
|
3714
|
+
import_core21.metricsServerManager.removeServer(tenantId, configKey);
|
|
3416
3715
|
}
|
|
3417
3716
|
} catch (error) {
|
|
3418
3717
|
console.warn("Failed to remove from MetricsServerManager:", error);
|
|
@@ -3430,10 +3729,10 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
3430
3729
|
}
|
|
3431
3730
|
}
|
|
3432
3731
|
async function testMetricsServerConnection(request, reply) {
|
|
3433
|
-
const tenantId =
|
|
3732
|
+
const tenantId = getTenantId8(request);
|
|
3434
3733
|
const { key } = request.params;
|
|
3435
3734
|
try {
|
|
3436
|
-
const storeLattice = (0,
|
|
3735
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3437
3736
|
const store = storeLattice.store;
|
|
3438
3737
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3439
3738
|
if (!config) {
|
|
@@ -3444,11 +3743,11 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3444
3743
|
};
|
|
3445
3744
|
}
|
|
3446
3745
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
3447
|
-
|
|
3746
|
+
import_core21.metricsServerManager.registerServer(tenantId, testKey, config.config);
|
|
3448
3747
|
try {
|
|
3449
|
-
const client =
|
|
3748
|
+
const client = import_core21.metricsServerManager.getClient(tenantId, testKey);
|
|
3450
3749
|
const result = await client.testConnection();
|
|
3451
|
-
|
|
3750
|
+
import_core21.metricsServerManager.removeServer(tenantId, testKey);
|
|
3452
3751
|
return {
|
|
3453
3752
|
success: true,
|
|
3454
3753
|
message: result.connected ? "Connection test successful" : "Connection test failed",
|
|
@@ -3456,7 +3755,7 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3456
3755
|
};
|
|
3457
3756
|
} catch (error) {
|
|
3458
3757
|
try {
|
|
3459
|
-
|
|
3758
|
+
import_core21.metricsServerManager.removeServer(tenantId, testKey);
|
|
3460
3759
|
} catch {
|
|
3461
3760
|
}
|
|
3462
3761
|
return {
|
|
@@ -3481,10 +3780,10 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3481
3780
|
}
|
|
3482
3781
|
}
|
|
3483
3782
|
async function listAvailableMetrics(request, reply) {
|
|
3484
|
-
const tenantId =
|
|
3783
|
+
const tenantId = getTenantId8(request);
|
|
3485
3784
|
const { key } = request.params;
|
|
3486
3785
|
try {
|
|
3487
|
-
const storeLattice = (0,
|
|
3786
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3488
3787
|
const store = storeLattice.store;
|
|
3489
3788
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3490
3789
|
if (!config) {
|
|
@@ -3494,10 +3793,10 @@ async function listAvailableMetrics(request, reply) {
|
|
|
3494
3793
|
message: "Metrics server configuration not found"
|
|
3495
3794
|
};
|
|
3496
3795
|
}
|
|
3497
|
-
if (!
|
|
3498
|
-
|
|
3796
|
+
if (!import_core21.metricsServerManager.hasServer(tenantId, key)) {
|
|
3797
|
+
import_core21.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
3499
3798
|
}
|
|
3500
|
-
const client =
|
|
3799
|
+
const client = import_core21.metricsServerManager.getClient(tenantId, key);
|
|
3501
3800
|
const metrics = await client.listMetrics();
|
|
3502
3801
|
return {
|
|
3503
3802
|
success: true,
|
|
@@ -3519,11 +3818,11 @@ async function listAvailableMetrics(request, reply) {
|
|
|
3519
3818
|
}
|
|
3520
3819
|
}
|
|
3521
3820
|
async function queryMetricsData(request, reply) {
|
|
3522
|
-
const tenantId =
|
|
3821
|
+
const tenantId = getTenantId8(request);
|
|
3523
3822
|
const { key } = request.params;
|
|
3524
3823
|
const { metricName, startTime, endTime, step, labels } = request.body;
|
|
3525
3824
|
try {
|
|
3526
|
-
const storeLattice = (0,
|
|
3825
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3527
3826
|
const store = storeLattice.store;
|
|
3528
3827
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3529
3828
|
if (!config) {
|
|
@@ -3540,10 +3839,10 @@ async function queryMetricsData(request, reply) {
|
|
|
3540
3839
|
message: "metricName is required"
|
|
3541
3840
|
};
|
|
3542
3841
|
}
|
|
3543
|
-
if (!
|
|
3544
|
-
|
|
3842
|
+
if (!import_core21.metricsServerManager.hasServer(tenantId, key)) {
|
|
3843
|
+
import_core21.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
3545
3844
|
}
|
|
3546
|
-
const client =
|
|
3845
|
+
const client = import_core21.metricsServerManager.getClient(tenantId, key);
|
|
3547
3846
|
const result = await client.queryMetricData(metricName, {
|
|
3548
3847
|
startTime,
|
|
3549
3848
|
endTime,
|
|
@@ -3567,10 +3866,10 @@ async function queryMetricsData(request, reply) {
|
|
|
3567
3866
|
}
|
|
3568
3867
|
}
|
|
3569
3868
|
async function getDataSources(request, reply) {
|
|
3570
|
-
const tenantId =
|
|
3869
|
+
const tenantId = getTenantId8(request);
|
|
3571
3870
|
const { key } = request.params;
|
|
3572
3871
|
try {
|
|
3573
|
-
const storeLattice = (0,
|
|
3872
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3574
3873
|
const store = storeLattice.store;
|
|
3575
3874
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3576
3875
|
if (!config) {
|
|
@@ -3588,7 +3887,7 @@ async function getDataSources(request, reply) {
|
|
|
3588
3887
|
};
|
|
3589
3888
|
}
|
|
3590
3889
|
const semanticConfig = config.config;
|
|
3591
|
-
const client = new
|
|
3890
|
+
const client = new import_core21.SemanticMetricsClient(semanticConfig);
|
|
3592
3891
|
const allDatasources = await client.getDataSources();
|
|
3593
3892
|
const selectedIds = semanticConfig.selectedDataSources || [];
|
|
3594
3893
|
const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
|
|
@@ -3608,10 +3907,10 @@ async function getDataSources(request, reply) {
|
|
|
3608
3907
|
}
|
|
3609
3908
|
}
|
|
3610
3909
|
async function getDatasourceMetrics(request, reply) {
|
|
3611
|
-
const tenantId =
|
|
3910
|
+
const tenantId = getTenantId8(request);
|
|
3612
3911
|
const { key, datasourceId } = request.params;
|
|
3613
3912
|
try {
|
|
3614
|
-
const storeLattice = (0,
|
|
3913
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3615
3914
|
const store = storeLattice.store;
|
|
3616
3915
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3617
3916
|
if (!config) {
|
|
@@ -3629,7 +3928,7 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
3629
3928
|
};
|
|
3630
3929
|
}
|
|
3631
3930
|
const semanticConfig = config.config;
|
|
3632
|
-
const client = new
|
|
3931
|
+
const client = new import_core21.SemanticMetricsClient(semanticConfig);
|
|
3633
3932
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
3634
3933
|
return {
|
|
3635
3934
|
success: true,
|
|
@@ -3645,11 +3944,11 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
3645
3944
|
}
|
|
3646
3945
|
}
|
|
3647
3946
|
async function querySemanticMetrics(request, reply) {
|
|
3648
|
-
const tenantId =
|
|
3947
|
+
const tenantId = getTenantId8(request);
|
|
3649
3948
|
const { key } = request.params;
|
|
3650
3949
|
const body = request.body;
|
|
3651
3950
|
try {
|
|
3652
|
-
const storeLattice = (0,
|
|
3951
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3653
3952
|
const store = storeLattice.store;
|
|
3654
3953
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3655
3954
|
if (!config) {
|
|
@@ -3674,7 +3973,7 @@ async function querySemanticMetrics(request, reply) {
|
|
|
3674
3973
|
};
|
|
3675
3974
|
}
|
|
3676
3975
|
const semanticConfig = config.config;
|
|
3677
|
-
const client = new
|
|
3976
|
+
const client = new import_core21.SemanticMetricsClient(semanticConfig);
|
|
3678
3977
|
const result = await client.semanticQuery(body);
|
|
3679
3978
|
const columnNames = result.columns.map((col) => col.name);
|
|
3680
3979
|
const allDataPoints = [];
|
|
@@ -3734,7 +4033,7 @@ async function testSemanticDataSources(request, reply) {
|
|
|
3734
4033
|
password: body.password,
|
|
3735
4034
|
headers: body.headers
|
|
3736
4035
|
};
|
|
3737
|
-
const client = new
|
|
4036
|
+
const client = new import_core21.SemanticMetricsClient(testConfig);
|
|
3738
4037
|
const datasources = await client.getDataSources();
|
|
3739
4038
|
return {
|
|
3740
4039
|
success: true,
|
|
@@ -3770,7 +4069,7 @@ async function testDatasourceMetrics(request, reply) {
|
|
|
3770
4069
|
password: body.password,
|
|
3771
4070
|
headers: body.headers
|
|
3772
4071
|
};
|
|
3773
|
-
const client = new
|
|
4072
|
+
const client = new import_core21.SemanticMetricsClient(testConfig);
|
|
3774
4073
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
3775
4074
|
return {
|
|
3776
4075
|
success: true,
|
|
@@ -3802,9 +4101,9 @@ function registerMetricsServerConfigRoutes(app2) {
|
|
|
3802
4101
|
}
|
|
3803
4102
|
|
|
3804
4103
|
// src/controllers/mcp-configs.ts
|
|
3805
|
-
var
|
|
4104
|
+
var import_core22 = require("@axiom-lattice/core");
|
|
3806
4105
|
var import_crypto5 = require("crypto");
|
|
3807
|
-
function
|
|
4106
|
+
function getTenantId9(request) {
|
|
3808
4107
|
const userTenantId = request.user?.tenantId;
|
|
3809
4108
|
if (userTenantId) {
|
|
3810
4109
|
return userTenantId;
|
|
@@ -3812,9 +4111,9 @@ function getTenantId8(request) {
|
|
|
3812
4111
|
return request.headers["x-tenant-id"] || "default";
|
|
3813
4112
|
}
|
|
3814
4113
|
async function getMcpServerConfigList(request, reply) {
|
|
3815
|
-
const tenantId =
|
|
4114
|
+
const tenantId = getTenantId9(request);
|
|
3816
4115
|
try {
|
|
3817
|
-
const storeLattice = (0,
|
|
4116
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3818
4117
|
const store = storeLattice.store;
|
|
3819
4118
|
const configs = await store.getAllConfigs(tenantId);
|
|
3820
4119
|
return {
|
|
@@ -3838,10 +4137,10 @@ async function getMcpServerConfigList(request, reply) {
|
|
|
3838
4137
|
}
|
|
3839
4138
|
}
|
|
3840
4139
|
async function getMcpServerConfig(request, reply) {
|
|
3841
|
-
const tenantId =
|
|
4140
|
+
const tenantId = getTenantId9(request);
|
|
3842
4141
|
const { key } = request.params;
|
|
3843
4142
|
try {
|
|
3844
|
-
const storeLattice = (0,
|
|
4143
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3845
4144
|
const store = storeLattice.store;
|
|
3846
4145
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3847
4146
|
if (!config) {
|
|
@@ -3864,10 +4163,10 @@ async function getMcpServerConfig(request, reply) {
|
|
|
3864
4163
|
}
|
|
3865
4164
|
}
|
|
3866
4165
|
async function createMcpServerConfig(request, reply) {
|
|
3867
|
-
const tenantId =
|
|
4166
|
+
const tenantId = getTenantId9(request);
|
|
3868
4167
|
const body = request.body;
|
|
3869
4168
|
try {
|
|
3870
|
-
const storeLattice = (0,
|
|
4169
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3871
4170
|
const store = storeLattice.store;
|
|
3872
4171
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3873
4172
|
if (existing) {
|
|
@@ -3903,11 +4202,11 @@ async function createMcpServerConfig(request, reply) {
|
|
|
3903
4202
|
}
|
|
3904
4203
|
}
|
|
3905
4204
|
async function updateMcpServerConfig(request, reply) {
|
|
3906
|
-
const tenantId =
|
|
4205
|
+
const tenantId = getTenantId9(request);
|
|
3907
4206
|
const { key } = request.params;
|
|
3908
4207
|
const updates = request.body;
|
|
3909
4208
|
try {
|
|
3910
|
-
const storeLattice = (0,
|
|
4209
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3911
4210
|
const store = storeLattice.store;
|
|
3912
4211
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3913
4212
|
if (!existing) {
|
|
@@ -3927,8 +4226,8 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
3927
4226
|
}
|
|
3928
4227
|
if (shouldReconnect) {
|
|
3929
4228
|
try {
|
|
3930
|
-
if (
|
|
3931
|
-
await
|
|
4229
|
+
if (import_core22.mcpManager.hasServer(key)) {
|
|
4230
|
+
await import_core22.mcpManager.removeServer(key);
|
|
3932
4231
|
}
|
|
3933
4232
|
await connectAndRegisterTools(updated);
|
|
3934
4233
|
await store.updateConfig(tenantId, existing.id, { status: "connected" });
|
|
@@ -3953,10 +4252,10 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
3953
4252
|
}
|
|
3954
4253
|
}
|
|
3955
4254
|
async function deleteMcpServerConfig(request, reply) {
|
|
3956
|
-
const tenantId =
|
|
4255
|
+
const tenantId = getTenantId9(request);
|
|
3957
4256
|
const { keyOrId } = request.params;
|
|
3958
4257
|
try {
|
|
3959
|
-
const storeLattice = (0,
|
|
4258
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3960
4259
|
const store = storeLattice.store;
|
|
3961
4260
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
3962
4261
|
let configKey = keyOrId;
|
|
@@ -3974,8 +4273,8 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
3974
4273
|
};
|
|
3975
4274
|
}
|
|
3976
4275
|
try {
|
|
3977
|
-
if (
|
|
3978
|
-
await
|
|
4276
|
+
if (import_core22.mcpManager.hasServer(configKey)) {
|
|
4277
|
+
await import_core22.mcpManager.removeServer(configKey);
|
|
3979
4278
|
}
|
|
3980
4279
|
} catch (error) {
|
|
3981
4280
|
console.warn("Failed to remove from MCP manager:", error);
|
|
@@ -4000,10 +4299,10 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
4000
4299
|
}
|
|
4001
4300
|
}
|
|
4002
4301
|
async function testMcpServerConnection(request, reply) {
|
|
4003
|
-
const tenantId =
|
|
4302
|
+
const tenantId = getTenantId9(request);
|
|
4004
4303
|
const { key } = request.params;
|
|
4005
4304
|
try {
|
|
4006
|
-
const storeLattice = (0,
|
|
4305
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4007
4306
|
const store = storeLattice.store;
|
|
4008
4307
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4009
4308
|
if (!config) {
|
|
@@ -4017,11 +4316,11 @@ async function testMcpServerConnection(request, reply) {
|
|
|
4017
4316
|
try {
|
|
4018
4317
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
4019
4318
|
const connection = convertToConnection(config.config);
|
|
4020
|
-
|
|
4021
|
-
await
|
|
4022
|
-
const tools = await
|
|
4319
|
+
import_core22.mcpManager.addServer(testKey, connection);
|
|
4320
|
+
await import_core22.mcpManager.connect();
|
|
4321
|
+
const tools = await import_core22.mcpManager.getAllTools();
|
|
4023
4322
|
const latency = Date.now() - startTime;
|
|
4024
|
-
await
|
|
4323
|
+
await import_core22.mcpManager.removeServer(testKey);
|
|
4025
4324
|
return {
|
|
4026
4325
|
success: true,
|
|
4027
4326
|
message: "Connection test successful",
|
|
@@ -4053,10 +4352,10 @@ async function testMcpServerConnection(request, reply) {
|
|
|
4053
4352
|
}
|
|
4054
4353
|
}
|
|
4055
4354
|
async function listMcpServerTools(request, reply) {
|
|
4056
|
-
const tenantId =
|
|
4355
|
+
const tenantId = getTenantId9(request);
|
|
4057
4356
|
const { key } = request.params;
|
|
4058
4357
|
try {
|
|
4059
|
-
const storeLattice = (0,
|
|
4358
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4060
4359
|
const store = storeLattice.store;
|
|
4061
4360
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4062
4361
|
if (!config) {
|
|
@@ -4066,10 +4365,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
4066
4365
|
message: "MCP server configuration not found"
|
|
4067
4366
|
};
|
|
4068
4367
|
}
|
|
4069
|
-
if (!
|
|
4368
|
+
if (!import_core22.mcpManager.hasServer(key)) {
|
|
4070
4369
|
await connectAndRegisterTools(config);
|
|
4071
4370
|
}
|
|
4072
|
-
const tools = await
|
|
4371
|
+
const tools = await import_core22.mcpManager.getAllTools();
|
|
4073
4372
|
return {
|
|
4074
4373
|
success: true,
|
|
4075
4374
|
message: "Tools retrieved successfully",
|
|
@@ -4086,10 +4385,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
4086
4385
|
}
|
|
4087
4386
|
}
|
|
4088
4387
|
async function connectMcpServer(request, reply) {
|
|
4089
|
-
const tenantId =
|
|
4388
|
+
const tenantId = getTenantId9(request);
|
|
4090
4389
|
const { key } = request.params;
|
|
4091
4390
|
try {
|
|
4092
|
-
const storeLattice = (0,
|
|
4391
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4093
4392
|
const store = storeLattice.store;
|
|
4094
4393
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4095
4394
|
if (!config) {
|
|
@@ -4110,7 +4409,7 @@ async function connectMcpServer(request, reply) {
|
|
|
4110
4409
|
};
|
|
4111
4410
|
} catch (error) {
|
|
4112
4411
|
console.error("Failed to connect MCP server:", error);
|
|
4113
|
-
const storeLattice = (0,
|
|
4412
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4114
4413
|
const store = storeLattice.store;
|
|
4115
4414
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4116
4415
|
if (config) {
|
|
@@ -4123,10 +4422,10 @@ async function connectMcpServer(request, reply) {
|
|
|
4123
4422
|
}
|
|
4124
4423
|
}
|
|
4125
4424
|
async function disconnectMcpServer(request, reply) {
|
|
4126
|
-
const tenantId =
|
|
4425
|
+
const tenantId = getTenantId9(request);
|
|
4127
4426
|
const { key } = request.params;
|
|
4128
4427
|
try {
|
|
4129
|
-
const storeLattice = (0,
|
|
4428
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4130
4429
|
const store = storeLattice.store;
|
|
4131
4430
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4132
4431
|
if (!config) {
|
|
@@ -4136,8 +4435,8 @@ async function disconnectMcpServer(request, reply) {
|
|
|
4136
4435
|
message: "MCP server configuration not found"
|
|
4137
4436
|
};
|
|
4138
4437
|
}
|
|
4139
|
-
if (
|
|
4140
|
-
await
|
|
4438
|
+
if (import_core22.mcpManager.hasServer(key)) {
|
|
4439
|
+
await import_core22.mcpManager.removeServer(key);
|
|
4141
4440
|
}
|
|
4142
4441
|
const updated = await store.updateConfig(tenantId, config.id, {
|
|
4143
4442
|
status: "disconnected"
|
|
@@ -4167,10 +4466,10 @@ async function testMcpServerTools(request, reply) {
|
|
|
4167
4466
|
}
|
|
4168
4467
|
const testKey = `__test_${Date.now()}`;
|
|
4169
4468
|
const connection = convertToConnection(body.config);
|
|
4170
|
-
|
|
4171
|
-
await
|
|
4172
|
-
const tools = await
|
|
4173
|
-
await
|
|
4469
|
+
import_core22.mcpManager.addServer(testKey, connection);
|
|
4470
|
+
await import_core22.mcpManager.connect();
|
|
4471
|
+
const tools = await import_core22.mcpManager.getAllTools();
|
|
4472
|
+
await import_core22.mcpManager.removeServer(testKey);
|
|
4174
4473
|
return {
|
|
4175
4474
|
success: true,
|
|
4176
4475
|
message: "Tools retrieved successfully",
|
|
@@ -4207,14 +4506,14 @@ function convertToConnection(config) {
|
|
|
4207
4506
|
}
|
|
4208
4507
|
async function connectAndRegisterTools(config) {
|
|
4209
4508
|
const connection = convertToConnection(config.config);
|
|
4210
|
-
|
|
4211
|
-
await
|
|
4212
|
-
const allTools = await
|
|
4509
|
+
import_core22.mcpManager.addServer(config.key, connection);
|
|
4510
|
+
await import_core22.mcpManager.connect();
|
|
4511
|
+
const allTools = await import_core22.mcpManager.getAllTools();
|
|
4213
4512
|
const selectedTools = allTools.filter(
|
|
4214
4513
|
(tool) => config.selectedTools.includes(tool.name)
|
|
4215
4514
|
);
|
|
4216
4515
|
for (const tool of selectedTools) {
|
|
4217
|
-
|
|
4516
|
+
import_core22.toolLatticeManager.registerExistingTool(tool.name, tool);
|
|
4218
4517
|
}
|
|
4219
4518
|
}
|
|
4220
4519
|
function registerMcpServerConfigRoutes(app2) {
|
|
@@ -4231,11 +4530,11 @@ function registerMcpServerConfigRoutes(app2) {
|
|
|
4231
4530
|
}
|
|
4232
4531
|
|
|
4233
4532
|
// src/controllers/users.ts
|
|
4234
|
-
var
|
|
4533
|
+
var import_core23 = require("@axiom-lattice/core");
|
|
4235
4534
|
var import_uuid3 = require("uuid");
|
|
4236
4535
|
var UsersController = class {
|
|
4237
4536
|
constructor() {
|
|
4238
|
-
this.userStore = (0,
|
|
4537
|
+
this.userStore = (0, import_core23.getStoreLattice)("default", "user").store;
|
|
4239
4538
|
}
|
|
4240
4539
|
async listUsers(request, reply) {
|
|
4241
4540
|
const { email } = request.query;
|
|
@@ -4313,11 +4612,11 @@ function registerUserRoutes(app2) {
|
|
|
4313
4612
|
}
|
|
4314
4613
|
|
|
4315
4614
|
// src/controllers/tenants.ts
|
|
4316
|
-
var
|
|
4615
|
+
var import_core24 = require("@axiom-lattice/core");
|
|
4317
4616
|
var import_uuid4 = require("uuid");
|
|
4318
4617
|
var TenantsController = class {
|
|
4319
4618
|
constructor() {
|
|
4320
|
-
this.tenantStore = (0,
|
|
4619
|
+
this.tenantStore = (0, import_core24.getStoreLattice)("default", "tenant").store;
|
|
4321
4620
|
}
|
|
4322
4621
|
// ==================== Tenant CRUD ====================
|
|
4323
4622
|
async listTenants(request, reply) {
|
|
@@ -4381,7 +4680,7 @@ function registerTenantRoutes(app2) {
|
|
|
4381
4680
|
}
|
|
4382
4681
|
|
|
4383
4682
|
// src/controllers/auth.ts
|
|
4384
|
-
var
|
|
4683
|
+
var import_core25 = require("@axiom-lattice/core");
|
|
4385
4684
|
var import_uuid5 = require("uuid");
|
|
4386
4685
|
var defaultAuthConfig = {
|
|
4387
4686
|
autoApproveUsers: true,
|
|
@@ -4390,9 +4689,9 @@ var defaultAuthConfig = {
|
|
|
4390
4689
|
};
|
|
4391
4690
|
var AuthController = class {
|
|
4392
4691
|
constructor(config = {}) {
|
|
4393
|
-
this.userStore = (0,
|
|
4394
|
-
this.tenantStore = (0,
|
|
4395
|
-
this.userTenantLinkStore = (0,
|
|
4692
|
+
this.userStore = (0, import_core25.getStoreLattice)("default", "user").store;
|
|
4693
|
+
this.tenantStore = (0, import_core25.getStoreLattice)("default", "tenant").store;
|
|
4694
|
+
this.userTenantLinkStore = (0, import_core25.getStoreLattice)("default", "userTenantLink").store;
|
|
4396
4695
|
this.config = { ...defaultAuthConfig, ...config };
|
|
4397
4696
|
}
|
|
4398
4697
|
async register(request, reply) {
|
|
@@ -4764,7 +5063,7 @@ function registerAuthRoutes(app2, config) {
|
|
|
4764
5063
|
}
|
|
4765
5064
|
|
|
4766
5065
|
// src/channels/lark/routes.ts
|
|
4767
|
-
var
|
|
5066
|
+
var import_core27 = require("@axiom-lattice/core");
|
|
4768
5067
|
var import_pg_stores = require("@axiom-lattice/pg-stores");
|
|
4769
5068
|
|
|
4770
5069
|
// src/channels/lark/parser.ts
|
|
@@ -5012,7 +5311,7 @@ function resolveSubjectType(mappingMode, chatType) {
|
|
|
5012
5311
|
}
|
|
5013
5312
|
|
|
5014
5313
|
// src/channels/lark/runner.ts
|
|
5015
|
-
var
|
|
5314
|
+
var import_core26 = require("@axiom-lattice/core");
|
|
5016
5315
|
var import_protocols4 = require("@axiom-lattice/protocols");
|
|
5017
5316
|
|
|
5018
5317
|
// src/channels/lark/aggregator.ts
|
|
@@ -5025,7 +5324,7 @@ function aggregateLarkReply(messageId, chunks) {
|
|
|
5025
5324
|
|
|
5026
5325
|
// src/channels/lark/runner.ts
|
|
5027
5326
|
async function runAgentAndCollectLarkReply(input) {
|
|
5028
|
-
const agent =
|
|
5327
|
+
const agent = import_core26.agentInstanceManager.getAgent({
|
|
5029
5328
|
tenant_id: input.tenantId,
|
|
5030
5329
|
assistant_id: input.assistantId,
|
|
5031
5330
|
thread_id: input.threadId,
|
|
@@ -5137,7 +5436,7 @@ function createDefaultLarkDependencies() {
|
|
|
5137
5436
|
const installationStore = new import_pg_stores.PostgreSQLChannelInstallationStore({
|
|
5138
5437
|
poolConfig: getDatabaseUrl()
|
|
5139
5438
|
});
|
|
5140
|
-
const threadStore = (0,
|
|
5439
|
+
const threadStore = (0, import_core27.getStoreLattice)("default", "thread").store;
|
|
5141
5440
|
const mappingStore = new import_pg_stores.ChannelIdentityMappingStore({
|
|
5142
5441
|
poolConfig: getDatabaseUrl()
|
|
5143
5442
|
});
|
|
@@ -5218,7 +5517,7 @@ function registerChannelRoutes(app2, dependencies = {}) {
|
|
|
5218
5517
|
|
|
5219
5518
|
// src/controllers/channel-installations.ts
|
|
5220
5519
|
var import_crypto8 = require("crypto");
|
|
5221
|
-
function
|
|
5520
|
+
function getTenantId10(request) {
|
|
5222
5521
|
const userTenantId = request.user?.tenantId;
|
|
5223
5522
|
if (userTenantId) {
|
|
5224
5523
|
return userTenantId;
|
|
@@ -5236,7 +5535,7 @@ async function getInstallationStore() {
|
|
|
5236
5535
|
});
|
|
5237
5536
|
}
|
|
5238
5537
|
async function getChannelInstallationList(request, reply) {
|
|
5239
|
-
const tenantId =
|
|
5538
|
+
const tenantId = getTenantId10(request);
|
|
5240
5539
|
const { channel } = request.query;
|
|
5241
5540
|
try {
|
|
5242
5541
|
const store = await getInstallationStore();
|
|
@@ -5262,7 +5561,7 @@ async function getChannelInstallationList(request, reply) {
|
|
|
5262
5561
|
}
|
|
5263
5562
|
}
|
|
5264
5563
|
async function getChannelInstallation(request, reply) {
|
|
5265
|
-
const tenantId =
|
|
5564
|
+
const tenantId = getTenantId10(request);
|
|
5266
5565
|
const { installationId } = request.params;
|
|
5267
5566
|
try {
|
|
5268
5567
|
const store = await getInstallationStore();
|
|
@@ -5295,7 +5594,7 @@ async function getChannelInstallation(request, reply) {
|
|
|
5295
5594
|
}
|
|
5296
5595
|
}
|
|
5297
5596
|
async function createChannelInstallation(request, reply) {
|
|
5298
|
-
const tenantId =
|
|
5597
|
+
const tenantId = getTenantId10(request);
|
|
5299
5598
|
const body = request.body;
|
|
5300
5599
|
try {
|
|
5301
5600
|
if (!body.channel) {
|
|
@@ -5358,7 +5657,7 @@ async function createChannelInstallation(request, reply) {
|
|
|
5358
5657
|
}
|
|
5359
5658
|
}
|
|
5360
5659
|
async function updateChannelInstallation(request, reply) {
|
|
5361
|
-
const tenantId =
|
|
5660
|
+
const tenantId = getTenantId10(request);
|
|
5362
5661
|
const { installationId } = request.params;
|
|
5363
5662
|
const body = request.body;
|
|
5364
5663
|
try {
|
|
@@ -5404,7 +5703,7 @@ async function updateChannelInstallation(request, reply) {
|
|
|
5404
5703
|
}
|
|
5405
5704
|
}
|
|
5406
5705
|
async function deleteChannelInstallation(request, reply) {
|
|
5407
|
-
const tenantId =
|
|
5706
|
+
const tenantId = getTenantId10(request);
|
|
5408
5707
|
const { installationId } = request.params;
|
|
5409
5708
|
try {
|
|
5410
5709
|
const store = await getInstallationStore();
|
|
@@ -5590,6 +5889,29 @@ var registerLatticeRoutes = (app2) => {
|
|
|
5590
5889
|
});
|
|
5591
5890
|
registerChannelRoutes(app2);
|
|
5592
5891
|
registerChannelInstallationRoutes(app2);
|
|
5892
|
+
app2.get(
|
|
5893
|
+
"/api/workflows/definitions",
|
|
5894
|
+
getAllWorkflowDefinitions
|
|
5895
|
+
);
|
|
5896
|
+
app2.get(
|
|
5897
|
+
"/api/workflows/runs",
|
|
5898
|
+
getAllWorkflowRuns
|
|
5899
|
+
);
|
|
5900
|
+
app2.get(
|
|
5901
|
+
"/api/workflows/inbox",
|
|
5902
|
+
getInboxItems
|
|
5903
|
+
);
|
|
5904
|
+
app2.get(
|
|
5905
|
+
"/api/assistants/:assistantId/workflows/definitions",
|
|
5906
|
+
getWorkflowDefinitions
|
|
5907
|
+
);
|
|
5908
|
+
app2.get(
|
|
5909
|
+
"/api/assistants/:assistantId/threads/:threadId/workflows/runs",
|
|
5910
|
+
getWorkflowRuns
|
|
5911
|
+
);
|
|
5912
|
+
app2.get("/api/workflows/runs/:runId", getWorkflowRun);
|
|
5913
|
+
app2.get("/api/workflows/runs/:runId/steps", getRunSteps);
|
|
5914
|
+
app2.get("/api/workflows/runs/:runId/tasks", getRunTasks);
|
|
5593
5915
|
app2.delete(
|
|
5594
5916
|
"/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
|
|
5595
5917
|
removePendingMessageHandler
|
|
@@ -5659,7 +5981,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
|
|
|
5659
5981
|
};
|
|
5660
5982
|
|
|
5661
5983
|
// src/services/agent_task_consumer.ts
|
|
5662
|
-
var
|
|
5984
|
+
var import_core28 = require("@axiom-lattice/core");
|
|
5663
5985
|
var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
5664
5986
|
const {
|
|
5665
5987
|
assistant_id,
|
|
@@ -5668,24 +5990,55 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
5668
5990
|
"x-tenant-id": tenant_id,
|
|
5669
5991
|
command,
|
|
5670
5992
|
callback_event,
|
|
5671
|
-
runConfig
|
|
5993
|
+
runConfig,
|
|
5994
|
+
main_thread_id,
|
|
5995
|
+
main_tenant_id,
|
|
5996
|
+
main_assistant_id
|
|
5672
5997
|
} = taskRequest;
|
|
5673
5998
|
try {
|
|
5674
5999
|
console.log(
|
|
5675
6000
|
`\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
5676
6001
|
);
|
|
5677
|
-
const agent =
|
|
5678
|
-
await agent.addMessage({ input, command, custom_run_config: runConfig },
|
|
6002
|
+
const agent = import_core28.agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
|
|
6003
|
+
await agent.addMessage({ input, command, custom_run_config: runConfig }, import_core28.QueueMode.STEER);
|
|
5679
6004
|
if (callback_event) {
|
|
5680
6005
|
agent.subscribeOnce("message:completed", (evt) => {
|
|
5681
|
-
|
|
6006
|
+
import_core28.eventBus.publish(callback_event, {
|
|
5682
6007
|
success: true,
|
|
5683
6008
|
state: evt.state,
|
|
5684
6009
|
config: { assistant_id, thread_id, tenant_id }
|
|
5685
6010
|
});
|
|
6011
|
+
if (main_thread_id && main_tenant_id) {
|
|
6012
|
+
try {
|
|
6013
|
+
const mainAgent = import_core28.agentInstanceManager.getAgent({
|
|
6014
|
+
assistant_id: main_assistant_id ?? assistant_id,
|
|
6015
|
+
thread_id: main_thread_id,
|
|
6016
|
+
tenant_id: main_tenant_id
|
|
6017
|
+
});
|
|
6018
|
+
if (mainAgent) {
|
|
6019
|
+
const messages = evt.state?.values?.messages;
|
|
6020
|
+
const lastAIMessage = messages?.filter((m) => m.type === "ai" || m.getType?.() === "ai").pop();
|
|
6021
|
+
const summary = lastAIMessage?.content?.substring(0, 500) ?? "(no output)";
|
|
6022
|
+
mainAgent.addMessage(
|
|
6023
|
+
{
|
|
6024
|
+
input: {
|
|
6025
|
+
message: `[Async task completed]
|
|
6026
|
+
task_id: ${thread_id}
|
|
6027
|
+
${summary}`
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
6030
|
+
).catch((err) => {
|
|
6031
|
+
console.error("Failed to notify main thread:", err);
|
|
6032
|
+
});
|
|
6033
|
+
mainAgent.updateAsyncTaskStatus(thread_id, "completed");
|
|
6034
|
+
}
|
|
6035
|
+
} catch (err) {
|
|
6036
|
+
console.error("Failed to notify main thread:", err);
|
|
6037
|
+
}
|
|
6038
|
+
}
|
|
5686
6039
|
});
|
|
5687
6040
|
agent.subscribeOnce("message:interrupted", (evt) => {
|
|
5688
|
-
|
|
6041
|
+
import_core28.eventBus.publish(callback_event, {
|
|
5689
6042
|
success: true,
|
|
5690
6043
|
state: evt.state,
|
|
5691
6044
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -5709,7 +6062,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
5709
6062
|
return handleAgentTask(taskRequest, nextRetryCount);
|
|
5710
6063
|
}
|
|
5711
6064
|
if (callback_event) {
|
|
5712
|
-
|
|
6065
|
+
import_core28.eventBus.publish(callback_event, {
|
|
5713
6066
|
success: false,
|
|
5714
6067
|
error: error instanceof Error ? error.message : String(error),
|
|
5715
6068
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -5747,7 +6100,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
5747
6100
|
* 初始化事件监听和队列轮询
|
|
5748
6101
|
*/
|
|
5749
6102
|
initialize() {
|
|
5750
|
-
|
|
6103
|
+
import_core28.eventBus.subscribe(import_core28.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
|
|
5751
6104
|
this.startPollingQueue();
|
|
5752
6105
|
console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
|
|
5753
6106
|
}
|
|
@@ -5866,7 +6219,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
5866
6219
|
handleAgentTask(taskRequest).catch((error) => {
|
|
5867
6220
|
console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
|
|
5868
6221
|
if (taskRequest.callback_event) {
|
|
5869
|
-
|
|
6222
|
+
import_core28.eventBus.publish(taskRequest.callback_event, {
|
|
5870
6223
|
success: false,
|
|
5871
6224
|
error: error instanceof Error ? error.message : String(error),
|
|
5872
6225
|
config: {
|
|
@@ -5886,7 +6239,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
|
|
|
5886
6239
|
var AgentTaskConsumer = _AgentTaskConsumer;
|
|
5887
6240
|
|
|
5888
6241
|
// src/index.ts
|
|
5889
|
-
var
|
|
6242
|
+
var import_core29 = require("@axiom-lattice/core");
|
|
5890
6243
|
var import_protocols5 = require("@axiom-lattice/protocols");
|
|
5891
6244
|
var import_meta = {};
|
|
5892
6245
|
process.on("unhandledRejection", (reason, promise) => {
|
|
@@ -5902,11 +6255,11 @@ var DEFAULT_LOGGER_CONFIG = {
|
|
|
5902
6255
|
var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
|
|
5903
6256
|
var logger = loggerLattice.client;
|
|
5904
6257
|
function initializeLogger(config) {
|
|
5905
|
-
if (
|
|
5906
|
-
|
|
6258
|
+
if (import_core29.loggerLatticeManager.hasLattice("default")) {
|
|
6259
|
+
import_core29.loggerLatticeManager.removeLattice("default");
|
|
5907
6260
|
}
|
|
5908
|
-
(0,
|
|
5909
|
-
return (0,
|
|
6261
|
+
(0, import_core29.registerLoggerLattice)("default", config);
|
|
6262
|
+
return (0, import_core29.getLoggerLattice)("default");
|
|
5910
6263
|
}
|
|
5911
6264
|
var app = (0, import_fastify.default)({
|
|
5912
6265
|
logger: false,
|
|
@@ -6002,7 +6355,7 @@ app.setErrorHandler((error, request, reply) => {
|
|
|
6002
6355
|
});
|
|
6003
6356
|
function getConfiguredSandboxProvider() {
|
|
6004
6357
|
const sandboxProviderType = process.env.SANDBOX_PROVIDER_TYPE || "microsandbox-remote";
|
|
6005
|
-
return (0,
|
|
6358
|
+
return (0, import_core29.createSandboxProvider)({
|
|
6006
6359
|
type: sandboxProviderType,
|
|
6007
6360
|
remoteBaseURL: process.env.SANDBOX_BASE_URL,
|
|
6008
6361
|
microsandboxServiceBaseURL: process.env.MICROSANDBOX_SERVICE_BASE_URL,
|
|
@@ -6031,17 +6384,32 @@ var start = async (config) => {
|
|
|
6031
6384
|
app.decorate("loggerLattice", loggerLattice);
|
|
6032
6385
|
registerLatticeRoutes(app);
|
|
6033
6386
|
try {
|
|
6034
|
-
const storeLattice = (0,
|
|
6387
|
+
const storeLattice = (0, import_core29.getStoreLattice)("default", "database");
|
|
6035
6388
|
const store = storeLattice.store;
|
|
6036
|
-
|
|
6389
|
+
import_core29.sqlDatabaseManager.setConfigStore(store);
|
|
6037
6390
|
logger.info("Database config store set for SqlDatabaseManager");
|
|
6038
6391
|
} catch (error) {
|
|
6039
6392
|
logger.warn("Failed to set database config store: " + (error instanceof Error ? error.message : String(error)));
|
|
6040
6393
|
}
|
|
6041
|
-
if (!
|
|
6042
|
-
|
|
6394
|
+
if (!import_core29.sandboxLatticeManager.hasLattice("default")) {
|
|
6395
|
+
import_core29.sandboxLatticeManager.registerLattice("default", getConfiguredSandboxProvider());
|
|
6043
6396
|
logger.info("Registered sandbox manager from env configuration");
|
|
6044
6397
|
}
|
|
6398
|
+
if (process.env.DATABASE_URL) {
|
|
6399
|
+
try {
|
|
6400
|
+
const { PostgreSQLWorkflowTrackingStore } = await import("@axiom-lattice/pg-stores");
|
|
6401
|
+
const pgStore = new PostgreSQLWorkflowTrackingStore({
|
|
6402
|
+
poolConfig: process.env.DATABASE_URL
|
|
6403
|
+
});
|
|
6404
|
+
if (import_core29.storeLatticeManager.hasLattice("default", "workflowTracking")) {
|
|
6405
|
+
import_core29.storeLatticeManager.removeLattice("default", "workflowTracking");
|
|
6406
|
+
}
|
|
6407
|
+
import_core29.storeLatticeManager.registerLattice("default", "workflowTracking", pgStore);
|
|
6408
|
+
logger.info("Workflow tracking store switched to PostgreSQL");
|
|
6409
|
+
} catch (error) {
|
|
6410
|
+
logger.warn("Failed to switch workflow tracking to PostgreSQL, keeping in-memory: " + (error instanceof Error ? error.message : String(error)));
|
|
6411
|
+
}
|
|
6412
|
+
}
|
|
6045
6413
|
const target_port = config?.port || Number(process.env.PORT) || 4001;
|
|
6046
6414
|
await app.listen({ port: target_port, host: "0.0.0.0" });
|
|
6047
6415
|
logger.info(`Lattice Gateway is running on port: ${target_port}`);
|
|
@@ -6060,7 +6428,7 @@ var start = async (config) => {
|
|
|
6060
6428
|
}
|
|
6061
6429
|
try {
|
|
6062
6430
|
logger.info("Starting agent instance recovery...");
|
|
6063
|
-
const restoreStats = await
|
|
6431
|
+
const restoreStats = await import_core29.agentInstanceManager.restore();
|
|
6064
6432
|
logger.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
|
|
6065
6433
|
} catch (error) {
|
|
6066
6434
|
logger.error("Agent recovery failed", { error });
|