@axiom-lattice/gateway 2.1.63 → 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 +8 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +521 -162
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +449 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- 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
|
@@ -1734,6 +1734,296 @@ async function executeSqlQuery(client, body, reply) {
|
|
|
1734
1734
|
};
|
|
1735
1735
|
}
|
|
1736
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
|
+
|
|
1737
2027
|
// src/schemas/data-query.ts
|
|
1738
2028
|
var dataQuerySchema = {
|
|
1739
2029
|
description: "Execute data query (semantic or SQL)",
|
|
@@ -2075,7 +2365,7 @@ var getHealthSchema = {
|
|
|
2075
2365
|
};
|
|
2076
2366
|
|
|
2077
2367
|
// src/controllers/thread_status.ts
|
|
2078
|
-
var
|
|
2368
|
+
var import_core14 = require("@axiom-lattice/core");
|
|
2079
2369
|
async function removePendingMessageHandler(request, reply) {
|
|
2080
2370
|
try {
|
|
2081
2371
|
const { assistant_id, thread_id, message_id } = request.params;
|
|
@@ -2088,7 +2378,7 @@ async function removePendingMessageHandler(request, reply) {
|
|
|
2088
2378
|
if (!assistant_id) {
|
|
2089
2379
|
return reply.code(400).send({ error: "Missing assistant_id parameter" });
|
|
2090
2380
|
}
|
|
2091
|
-
const agent =
|
|
2381
|
+
const agent = import_core14.agentInstanceManager.getAgent({
|
|
2092
2382
|
assistant_id,
|
|
2093
2383
|
thread_id,
|
|
2094
2384
|
tenant_id,
|
|
@@ -2122,7 +2412,7 @@ async function removePendingMessageHandler(request, reply) {
|
|
|
2122
2412
|
}
|
|
2123
2413
|
|
|
2124
2414
|
// src/services/sandbox_service.ts
|
|
2125
|
-
var
|
|
2415
|
+
var import_core15 = require("@axiom-lattice/core");
|
|
2126
2416
|
var ERROR_HTML = `<!DOCTYPE html>
|
|
2127
2417
|
<html lang="zh-CN">
|
|
2128
2418
|
<head>
|
|
@@ -2234,7 +2524,7 @@ var ERROR_HTML = `<!DOCTYPE html>
|
|
|
2234
2524
|
</html>`;
|
|
2235
2525
|
var SandboxService = class {
|
|
2236
2526
|
getFilesystemVmIsolation(tenantId, assistantId) {
|
|
2237
|
-
const agentLattice =
|
|
2527
|
+
const agentLattice = import_core15.agentLatticeManager.getAgentLatticeWithTenant(tenantId, assistantId);
|
|
2238
2528
|
if (!agentLattice) {
|
|
2239
2529
|
return null;
|
|
2240
2530
|
}
|
|
@@ -2248,9 +2538,9 @@ var SandboxService = class {
|
|
|
2248
2538
|
computeSandboxName(assistantId, threadId, vmIsolation, tenantId, workspaceId, projectId) {
|
|
2249
2539
|
switch (vmIsolation) {
|
|
2250
2540
|
case "agent":
|
|
2251
|
-
return (0,
|
|
2541
|
+
return (0, import_core15.normalizeSandboxName)(`${tenantId ?? "default"}-${assistantId}`);
|
|
2252
2542
|
case "project":
|
|
2253
|
-
return (0,
|
|
2543
|
+
return (0, import_core15.normalizeSandboxName)(
|
|
2254
2544
|
`${tenantId ?? "default"}-${workspaceId ?? "default"}-${projectId ?? "default"}`
|
|
2255
2545
|
);
|
|
2256
2546
|
case "global":
|
|
@@ -2306,7 +2596,7 @@ var SandboxService = class {
|
|
|
2306
2596
|
var sandboxService = new SandboxService();
|
|
2307
2597
|
|
|
2308
2598
|
// src/controllers/sandbox.ts
|
|
2309
|
-
var
|
|
2599
|
+
var import_core16 = require("@axiom-lattice/core");
|
|
2310
2600
|
function getFilenameFromPath(path3) {
|
|
2311
2601
|
const segments = path3.replace(/\/+$/, "").split("/");
|
|
2312
2602
|
return segments[segments.length - 1] || "download";
|
|
@@ -2348,7 +2638,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2348
2638
|
threadId,
|
|
2349
2639
|
vmIsolation
|
|
2350
2640
|
);
|
|
2351
|
-
const sandboxManager = (0,
|
|
2641
|
+
const sandboxManager = (0, import_core16.getSandBoxManager)();
|
|
2352
2642
|
const sandbox = await sandboxManager.createSandbox(sandboxName);
|
|
2353
2643
|
try {
|
|
2354
2644
|
const data = await request.file();
|
|
@@ -2392,7 +2682,7 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2392
2682
|
threadId,
|
|
2393
2683
|
vmIsolation
|
|
2394
2684
|
);
|
|
2395
|
-
const sandboxManager = (0,
|
|
2685
|
+
const sandboxManager = (0, import_core16.getSandBoxManager)();
|
|
2396
2686
|
const sandbox = await sandboxManager.createSandbox(sandboxName);
|
|
2397
2687
|
try {
|
|
2398
2688
|
const resolvedPath = filePath.startsWith("/") ? filePath : `/${filePath}`;
|
|
@@ -2418,14 +2708,14 @@ function registerSandboxProxyRoutes(app2) {
|
|
|
2418
2708
|
// src/controllers/workspace.ts
|
|
2419
2709
|
var fs = __toESM(require("fs/promises"));
|
|
2420
2710
|
var path = __toESM(require("path"));
|
|
2421
|
-
var import_core16 = require("@axiom-lattice/core");
|
|
2422
2711
|
var import_core17 = require("@axiom-lattice/core");
|
|
2423
2712
|
var import_core18 = require("@axiom-lattice/core");
|
|
2713
|
+
var import_core19 = require("@axiom-lattice/core");
|
|
2424
2714
|
var import_uuid2 = require("uuid");
|
|
2425
2715
|
var WorkspaceController = class {
|
|
2426
2716
|
constructor() {
|
|
2427
|
-
this.workspaceStore = (0,
|
|
2428
|
-
this.projectStore = (0,
|
|
2717
|
+
this.workspaceStore = (0, import_core17.getStoreLattice)("default", "workspace").store;
|
|
2718
|
+
this.projectStore = (0, import_core17.getStoreLattice)("default", "project").store;
|
|
2429
2719
|
}
|
|
2430
2720
|
getTenantId(request) {
|
|
2431
2721
|
const userTenantId = request.user?.tenantId;
|
|
@@ -2558,7 +2848,7 @@ var WorkspaceController = class {
|
|
|
2558
2848
|
throw new Error("Workspace not found");
|
|
2559
2849
|
}
|
|
2560
2850
|
if (workspace.storageType === "sandbox") {
|
|
2561
|
-
const sandboxManager = (0,
|
|
2851
|
+
const sandboxManager = (0, import_core19.getSandBoxManager)();
|
|
2562
2852
|
const volumeConfig = {
|
|
2563
2853
|
assistant_id: assistantId || "",
|
|
2564
2854
|
thread_id: "",
|
|
@@ -2572,14 +2862,14 @@ var WorkspaceController = class {
|
|
|
2572
2862
|
}
|
|
2573
2863
|
const sandbox = await sandboxManager.getSandboxFromConfig(volumeConfig);
|
|
2574
2864
|
return {
|
|
2575
|
-
backend: new
|
|
2865
|
+
backend: new import_core18.SandboxFilesystem({
|
|
2576
2866
|
sandboxInstance: sandbox
|
|
2577
2867
|
}),
|
|
2578
2868
|
workspace
|
|
2579
2869
|
};
|
|
2580
2870
|
} else {
|
|
2581
2871
|
return {
|
|
2582
|
-
backend: new
|
|
2872
|
+
backend: new import_core18.FilesystemBackend({
|
|
2583
2873
|
rootDir: `/lattice_store/tenants/${tenantId}/workspaces/${workspaceId}/${projectId}`,
|
|
2584
2874
|
virtualMode: true
|
|
2585
2875
|
}),
|
|
@@ -2657,7 +2947,7 @@ var WorkspaceController = class {
|
|
|
2657
2947
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId, assistantId);
|
|
2658
2948
|
const resolvedPath = filePath;
|
|
2659
2949
|
if (workspace.storageType === "sandbox") {
|
|
2660
|
-
const sandboxManager = (0,
|
|
2950
|
+
const sandboxManager = (0, import_core19.getSandBoxManager)();
|
|
2661
2951
|
const volumeConfig = {
|
|
2662
2952
|
assistant_id: assistantId || "",
|
|
2663
2953
|
thread_id: "",
|
|
@@ -2707,7 +2997,7 @@ var WorkspaceController = class {
|
|
|
2707
2997
|
const { workspace } = await this.getBackend(tenantId, workspaceId, projectId, assistantId);
|
|
2708
2998
|
const resolvedPath = filePath;
|
|
2709
2999
|
if (workspace.storageType === "sandbox") {
|
|
2710
|
-
const sandboxManager = (0,
|
|
3000
|
+
const sandboxManager = (0, import_core19.getSandBoxManager)();
|
|
2711
3001
|
const volumeConfig = {
|
|
2712
3002
|
assistant_id: assistantId || "",
|
|
2713
3003
|
thread_id: "",
|
|
@@ -2841,7 +3131,7 @@ var WorkspaceController = class {
|
|
|
2841
3131
|
return reply.status(400).send({ success: false, error: "Invalid path parameter" });
|
|
2842
3132
|
}
|
|
2843
3133
|
if (workspace.storageType === "sandbox") {
|
|
2844
|
-
const sandboxManager = (0,
|
|
3134
|
+
const sandboxManager = (0, import_core19.getSandBoxManager)();
|
|
2845
3135
|
const volumeConfig = {
|
|
2846
3136
|
assistant_id: assistantId || "",
|
|
2847
3137
|
thread_id: "",
|
|
@@ -2949,9 +3239,9 @@ function registerWorkspaceRoutes(app2) {
|
|
|
2949
3239
|
}
|
|
2950
3240
|
|
|
2951
3241
|
// src/controllers/database-configs.ts
|
|
2952
|
-
var
|
|
3242
|
+
var import_core20 = require("@axiom-lattice/core");
|
|
2953
3243
|
var import_crypto3 = require("crypto");
|
|
2954
|
-
function
|
|
3244
|
+
function getTenantId7(request) {
|
|
2955
3245
|
const userTenantId = request.user?.tenantId;
|
|
2956
3246
|
if (userTenantId) {
|
|
2957
3247
|
return userTenantId;
|
|
@@ -2959,9 +3249,9 @@ function getTenantId6(request) {
|
|
|
2959
3249
|
return request.headers["x-tenant-id"] || "default";
|
|
2960
3250
|
}
|
|
2961
3251
|
async function getDatabaseConfigList(request, reply) {
|
|
2962
|
-
const tenantId =
|
|
3252
|
+
const tenantId = getTenantId7(request);
|
|
2963
3253
|
try {
|
|
2964
|
-
const storeLattice = (0,
|
|
3254
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
2965
3255
|
const store = storeLattice.store;
|
|
2966
3256
|
const configs = await store.getAllConfigs(tenantId);
|
|
2967
3257
|
console.log("Backend: getAllConfigs returned:", configs);
|
|
@@ -2989,10 +3279,10 @@ async function getDatabaseConfigList(request, reply) {
|
|
|
2989
3279
|
}
|
|
2990
3280
|
}
|
|
2991
3281
|
async function getDatabaseConfig(request, reply) {
|
|
2992
|
-
const tenantId =
|
|
3282
|
+
const tenantId = getTenantId7(request);
|
|
2993
3283
|
const { key } = request.params;
|
|
2994
3284
|
try {
|
|
2995
|
-
const storeLattice = (0,
|
|
3285
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
2996
3286
|
const store = storeLattice.store;
|
|
2997
3287
|
const config = await store.getConfigByKey(tenantId, key);
|
|
2998
3288
|
if (!config) {
|
|
@@ -3015,10 +3305,10 @@ async function getDatabaseConfig(request, reply) {
|
|
|
3015
3305
|
}
|
|
3016
3306
|
}
|
|
3017
3307
|
async function createDatabaseConfig(request, reply) {
|
|
3018
|
-
const tenantId =
|
|
3308
|
+
const tenantId = getTenantId7(request);
|
|
3019
3309
|
const body = request.body;
|
|
3020
3310
|
try {
|
|
3021
|
-
const storeLattice = (0,
|
|
3311
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
3022
3312
|
const store = storeLattice.store;
|
|
3023
3313
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3024
3314
|
if (existing) {
|
|
@@ -3031,7 +3321,7 @@ async function createDatabaseConfig(request, reply) {
|
|
|
3031
3321
|
const id = body.id || (0, import_crypto3.randomUUID)();
|
|
3032
3322
|
const config = await store.createConfig(tenantId, id, body);
|
|
3033
3323
|
try {
|
|
3034
|
-
|
|
3324
|
+
import_core20.sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
|
|
3035
3325
|
} catch (error) {
|
|
3036
3326
|
console.warn("Failed to auto-register database:", error);
|
|
3037
3327
|
}
|
|
@@ -3050,11 +3340,11 @@ async function createDatabaseConfig(request, reply) {
|
|
|
3050
3340
|
}
|
|
3051
3341
|
}
|
|
3052
3342
|
async function updateDatabaseConfig(request, reply) {
|
|
3053
|
-
const tenantId =
|
|
3343
|
+
const tenantId = getTenantId7(request);
|
|
3054
3344
|
const { key } = request.params;
|
|
3055
3345
|
const updates = request.body;
|
|
3056
3346
|
try {
|
|
3057
|
-
const storeLattice = (0,
|
|
3347
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
3058
3348
|
const store = storeLattice.store;
|
|
3059
3349
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3060
3350
|
if (!existing) {
|
|
@@ -3073,7 +3363,7 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
3073
3363
|
}
|
|
3074
3364
|
if (updates.config) {
|
|
3075
3365
|
try {
|
|
3076
|
-
|
|
3366
|
+
import_core20.sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
|
|
3077
3367
|
} catch (error) {
|
|
3078
3368
|
console.warn("Failed to re-register database:", error);
|
|
3079
3369
|
}
|
|
@@ -3092,10 +3382,10 @@ async function updateDatabaseConfig(request, reply) {
|
|
|
3092
3382
|
}
|
|
3093
3383
|
}
|
|
3094
3384
|
async function deleteDatabaseConfig(request, reply) {
|
|
3095
|
-
const tenantId =
|
|
3385
|
+
const tenantId = getTenantId7(request);
|
|
3096
3386
|
const { keyOrId } = request.params;
|
|
3097
3387
|
try {
|
|
3098
|
-
const storeLattice = (0,
|
|
3388
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
3099
3389
|
const store = storeLattice.store;
|
|
3100
3390
|
console.log("Delete request - keyOrId:", keyOrId);
|
|
3101
3391
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
@@ -3122,8 +3412,8 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
3122
3412
|
};
|
|
3123
3413
|
}
|
|
3124
3414
|
try {
|
|
3125
|
-
if (
|
|
3126
|
-
await
|
|
3415
|
+
if (import_core20.sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
|
|
3416
|
+
await import_core20.sqlDatabaseManager.removeDatabase(tenantId, configKey);
|
|
3127
3417
|
}
|
|
3128
3418
|
} catch (error) {
|
|
3129
3419
|
console.warn("Failed to remove from SqlDatabaseManager:", error);
|
|
@@ -3141,10 +3431,10 @@ async function deleteDatabaseConfig(request, reply) {
|
|
|
3141
3431
|
}
|
|
3142
3432
|
}
|
|
3143
3433
|
async function testDatabaseConnection(request, reply) {
|
|
3144
|
-
const tenantId =
|
|
3434
|
+
const tenantId = getTenantId7(request);
|
|
3145
3435
|
const { key } = request.params;
|
|
3146
3436
|
try {
|
|
3147
|
-
const storeLattice = (0,
|
|
3437
|
+
const storeLattice = (0, import_core20.getStoreLattice)("default", "database");
|
|
3148
3438
|
const store = storeLattice.store;
|
|
3149
3439
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3150
3440
|
if (!config) {
|
|
@@ -3155,16 +3445,16 @@ async function testDatabaseConnection(request, reply) {
|
|
|
3155
3445
|
};
|
|
3156
3446
|
}
|
|
3157
3447
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
3158
|
-
|
|
3448
|
+
import_core20.sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
|
|
3159
3449
|
const startTime = Date.now();
|
|
3160
|
-
const db = await
|
|
3450
|
+
const db = await import_core20.sqlDatabaseManager.getDatabase(tenantId, testKey);
|
|
3161
3451
|
try {
|
|
3162
3452
|
await db.connect();
|
|
3163
3453
|
await db.listTables();
|
|
3164
3454
|
const latency = Date.now() - startTime;
|
|
3165
3455
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3166
3456
|
await db.disconnect();
|
|
3167
|
-
await
|
|
3457
|
+
await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
3168
3458
|
return {
|
|
3169
3459
|
success: true,
|
|
3170
3460
|
message: "Connection test successful",
|
|
@@ -3176,7 +3466,7 @@ async function testDatabaseConnection(request, reply) {
|
|
|
3176
3466
|
} catch (error) {
|
|
3177
3467
|
try {
|
|
3178
3468
|
await db.disconnect();
|
|
3179
|
-
await
|
|
3469
|
+
await import_core20.sqlDatabaseManager.removeDatabase(tenantId, testKey);
|
|
3180
3470
|
} catch {
|
|
3181
3471
|
}
|
|
3182
3472
|
return {
|
|
@@ -3228,9 +3518,9 @@ function registerDatabaseConfigRoutes(app2) {
|
|
|
3228
3518
|
}
|
|
3229
3519
|
|
|
3230
3520
|
// src/controllers/metrics-configs.ts
|
|
3231
|
-
var
|
|
3521
|
+
var import_core21 = require("@axiom-lattice/core");
|
|
3232
3522
|
var import_crypto4 = require("crypto");
|
|
3233
|
-
function
|
|
3523
|
+
function getTenantId8(request) {
|
|
3234
3524
|
const userTenantId = request.user?.tenantId;
|
|
3235
3525
|
if (userTenantId) {
|
|
3236
3526
|
return userTenantId;
|
|
@@ -3238,9 +3528,9 @@ function getTenantId7(request) {
|
|
|
3238
3528
|
return request.headers["x-tenant-id"] || "default";
|
|
3239
3529
|
}
|
|
3240
3530
|
async function getMetricsServerConfigList(request, reply) {
|
|
3241
|
-
const tenantId =
|
|
3531
|
+
const tenantId = getTenantId8(request);
|
|
3242
3532
|
try {
|
|
3243
|
-
const storeLattice = (0,
|
|
3533
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3244
3534
|
const store = storeLattice.store;
|
|
3245
3535
|
const configs = await store.getAllConfigs(tenantId);
|
|
3246
3536
|
return {
|
|
@@ -3264,10 +3554,10 @@ async function getMetricsServerConfigList(request, reply) {
|
|
|
3264
3554
|
}
|
|
3265
3555
|
}
|
|
3266
3556
|
async function getMetricsServerConfig(request, reply) {
|
|
3267
|
-
const tenantId =
|
|
3557
|
+
const tenantId = getTenantId8(request);
|
|
3268
3558
|
const { key } = request.params;
|
|
3269
3559
|
try {
|
|
3270
|
-
const storeLattice = (0,
|
|
3560
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3271
3561
|
const store = storeLattice.store;
|
|
3272
3562
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3273
3563
|
if (!config) {
|
|
@@ -3290,10 +3580,10 @@ async function getMetricsServerConfig(request, reply) {
|
|
|
3290
3580
|
}
|
|
3291
3581
|
}
|
|
3292
3582
|
async function createMetricsServerConfig(request, reply) {
|
|
3293
|
-
const tenantId =
|
|
3583
|
+
const tenantId = getTenantId8(request);
|
|
3294
3584
|
const body = request.body;
|
|
3295
3585
|
try {
|
|
3296
|
-
const storeLattice = (0,
|
|
3586
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3297
3587
|
const store = storeLattice.store;
|
|
3298
3588
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3299
3589
|
if (existing) {
|
|
@@ -3322,7 +3612,7 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
3322
3612
|
};
|
|
3323
3613
|
const config = await store.createConfig(tenantId, id, configData);
|
|
3324
3614
|
try {
|
|
3325
|
-
|
|
3615
|
+
import_core21.metricsServerManager.registerServer(tenantId, config.key, config.config);
|
|
3326
3616
|
} catch (error) {
|
|
3327
3617
|
console.warn("Failed to auto-register metrics server:", error);
|
|
3328
3618
|
}
|
|
@@ -3341,11 +3631,11 @@ async function createMetricsServerConfig(request, reply) {
|
|
|
3341
3631
|
}
|
|
3342
3632
|
}
|
|
3343
3633
|
async function updateMetricsServerConfig(request, reply) {
|
|
3344
|
-
const tenantId =
|
|
3634
|
+
const tenantId = getTenantId8(request);
|
|
3345
3635
|
const { key } = request.params;
|
|
3346
3636
|
const updates = request.body;
|
|
3347
3637
|
try {
|
|
3348
|
-
const storeLattice = (0,
|
|
3638
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3349
3639
|
const store = storeLattice.store;
|
|
3350
3640
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3351
3641
|
if (!existing) {
|
|
@@ -3373,7 +3663,7 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
3373
3663
|
}
|
|
3374
3664
|
if (updates.config) {
|
|
3375
3665
|
try {
|
|
3376
|
-
|
|
3666
|
+
import_core21.metricsServerManager.registerServer(tenantId, updated.key, updated.config);
|
|
3377
3667
|
} catch (error) {
|
|
3378
3668
|
console.warn("Failed to re-register metrics server:", error);
|
|
3379
3669
|
}
|
|
@@ -3392,10 +3682,10 @@ async function updateMetricsServerConfig(request, reply) {
|
|
|
3392
3682
|
}
|
|
3393
3683
|
}
|
|
3394
3684
|
async function deleteMetricsServerConfig(request, reply) {
|
|
3395
|
-
const tenantId =
|
|
3685
|
+
const tenantId = getTenantId8(request);
|
|
3396
3686
|
const { keyOrId } = request.params;
|
|
3397
3687
|
try {
|
|
3398
|
-
const storeLattice = (0,
|
|
3688
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3399
3689
|
const store = storeLattice.store;
|
|
3400
3690
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
3401
3691
|
let configKey = keyOrId;
|
|
@@ -3420,8 +3710,8 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
3420
3710
|
};
|
|
3421
3711
|
}
|
|
3422
3712
|
try {
|
|
3423
|
-
if (
|
|
3424
|
-
|
|
3713
|
+
if (import_core21.metricsServerManager.hasServer(tenantId, configKey)) {
|
|
3714
|
+
import_core21.metricsServerManager.removeServer(tenantId, configKey);
|
|
3425
3715
|
}
|
|
3426
3716
|
} catch (error) {
|
|
3427
3717
|
console.warn("Failed to remove from MetricsServerManager:", error);
|
|
@@ -3439,10 +3729,10 @@ async function deleteMetricsServerConfig(request, reply) {
|
|
|
3439
3729
|
}
|
|
3440
3730
|
}
|
|
3441
3731
|
async function testMetricsServerConnection(request, reply) {
|
|
3442
|
-
const tenantId =
|
|
3732
|
+
const tenantId = getTenantId8(request);
|
|
3443
3733
|
const { key } = request.params;
|
|
3444
3734
|
try {
|
|
3445
|
-
const storeLattice = (0,
|
|
3735
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3446
3736
|
const store = storeLattice.store;
|
|
3447
3737
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3448
3738
|
if (!config) {
|
|
@@ -3453,11 +3743,11 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3453
3743
|
};
|
|
3454
3744
|
}
|
|
3455
3745
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
3456
|
-
|
|
3746
|
+
import_core21.metricsServerManager.registerServer(tenantId, testKey, config.config);
|
|
3457
3747
|
try {
|
|
3458
|
-
const client =
|
|
3748
|
+
const client = import_core21.metricsServerManager.getClient(tenantId, testKey);
|
|
3459
3749
|
const result = await client.testConnection();
|
|
3460
|
-
|
|
3750
|
+
import_core21.metricsServerManager.removeServer(tenantId, testKey);
|
|
3461
3751
|
return {
|
|
3462
3752
|
success: true,
|
|
3463
3753
|
message: result.connected ? "Connection test successful" : "Connection test failed",
|
|
@@ -3465,7 +3755,7 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3465
3755
|
};
|
|
3466
3756
|
} catch (error) {
|
|
3467
3757
|
try {
|
|
3468
|
-
|
|
3758
|
+
import_core21.metricsServerManager.removeServer(tenantId, testKey);
|
|
3469
3759
|
} catch {
|
|
3470
3760
|
}
|
|
3471
3761
|
return {
|
|
@@ -3490,10 +3780,10 @@ async function testMetricsServerConnection(request, reply) {
|
|
|
3490
3780
|
}
|
|
3491
3781
|
}
|
|
3492
3782
|
async function listAvailableMetrics(request, reply) {
|
|
3493
|
-
const tenantId =
|
|
3783
|
+
const tenantId = getTenantId8(request);
|
|
3494
3784
|
const { key } = request.params;
|
|
3495
3785
|
try {
|
|
3496
|
-
const storeLattice = (0,
|
|
3786
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3497
3787
|
const store = storeLattice.store;
|
|
3498
3788
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3499
3789
|
if (!config) {
|
|
@@ -3503,10 +3793,10 @@ async function listAvailableMetrics(request, reply) {
|
|
|
3503
3793
|
message: "Metrics server configuration not found"
|
|
3504
3794
|
};
|
|
3505
3795
|
}
|
|
3506
|
-
if (!
|
|
3507
|
-
|
|
3796
|
+
if (!import_core21.metricsServerManager.hasServer(tenantId, key)) {
|
|
3797
|
+
import_core21.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
3508
3798
|
}
|
|
3509
|
-
const client =
|
|
3799
|
+
const client = import_core21.metricsServerManager.getClient(tenantId, key);
|
|
3510
3800
|
const metrics = await client.listMetrics();
|
|
3511
3801
|
return {
|
|
3512
3802
|
success: true,
|
|
@@ -3528,11 +3818,11 @@ async function listAvailableMetrics(request, reply) {
|
|
|
3528
3818
|
}
|
|
3529
3819
|
}
|
|
3530
3820
|
async function queryMetricsData(request, reply) {
|
|
3531
|
-
const tenantId =
|
|
3821
|
+
const tenantId = getTenantId8(request);
|
|
3532
3822
|
const { key } = request.params;
|
|
3533
3823
|
const { metricName, startTime, endTime, step, labels } = request.body;
|
|
3534
3824
|
try {
|
|
3535
|
-
const storeLattice = (0,
|
|
3825
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3536
3826
|
const store = storeLattice.store;
|
|
3537
3827
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3538
3828
|
if (!config) {
|
|
@@ -3549,10 +3839,10 @@ async function queryMetricsData(request, reply) {
|
|
|
3549
3839
|
message: "metricName is required"
|
|
3550
3840
|
};
|
|
3551
3841
|
}
|
|
3552
|
-
if (!
|
|
3553
|
-
|
|
3842
|
+
if (!import_core21.metricsServerManager.hasServer(tenantId, key)) {
|
|
3843
|
+
import_core21.metricsServerManager.registerServer(tenantId, key, config.config);
|
|
3554
3844
|
}
|
|
3555
|
-
const client =
|
|
3845
|
+
const client = import_core21.metricsServerManager.getClient(tenantId, key);
|
|
3556
3846
|
const result = await client.queryMetricData(metricName, {
|
|
3557
3847
|
startTime,
|
|
3558
3848
|
endTime,
|
|
@@ -3576,10 +3866,10 @@ async function queryMetricsData(request, reply) {
|
|
|
3576
3866
|
}
|
|
3577
3867
|
}
|
|
3578
3868
|
async function getDataSources(request, reply) {
|
|
3579
|
-
const tenantId =
|
|
3869
|
+
const tenantId = getTenantId8(request);
|
|
3580
3870
|
const { key } = request.params;
|
|
3581
3871
|
try {
|
|
3582
|
-
const storeLattice = (0,
|
|
3872
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3583
3873
|
const store = storeLattice.store;
|
|
3584
3874
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3585
3875
|
if (!config) {
|
|
@@ -3597,7 +3887,7 @@ async function getDataSources(request, reply) {
|
|
|
3597
3887
|
};
|
|
3598
3888
|
}
|
|
3599
3889
|
const semanticConfig = config.config;
|
|
3600
|
-
const client = new
|
|
3890
|
+
const client = new import_core21.SemanticMetricsClient(semanticConfig);
|
|
3601
3891
|
const allDatasources = await client.getDataSources();
|
|
3602
3892
|
const selectedIds = semanticConfig.selectedDataSources || [];
|
|
3603
3893
|
const filteredDatasources = selectedIds.length > 0 ? allDatasources.filter((ds) => selectedIds.includes(String(ds.id))) : allDatasources;
|
|
@@ -3617,10 +3907,10 @@ async function getDataSources(request, reply) {
|
|
|
3617
3907
|
}
|
|
3618
3908
|
}
|
|
3619
3909
|
async function getDatasourceMetrics(request, reply) {
|
|
3620
|
-
const tenantId =
|
|
3910
|
+
const tenantId = getTenantId8(request);
|
|
3621
3911
|
const { key, datasourceId } = request.params;
|
|
3622
3912
|
try {
|
|
3623
|
-
const storeLattice = (0,
|
|
3913
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3624
3914
|
const store = storeLattice.store;
|
|
3625
3915
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3626
3916
|
if (!config) {
|
|
@@ -3638,7 +3928,7 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
3638
3928
|
};
|
|
3639
3929
|
}
|
|
3640
3930
|
const semanticConfig = config.config;
|
|
3641
|
-
const client = new
|
|
3931
|
+
const client = new import_core21.SemanticMetricsClient(semanticConfig);
|
|
3642
3932
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
3643
3933
|
return {
|
|
3644
3934
|
success: true,
|
|
@@ -3654,11 +3944,11 @@ async function getDatasourceMetrics(request, reply) {
|
|
|
3654
3944
|
}
|
|
3655
3945
|
}
|
|
3656
3946
|
async function querySemanticMetrics(request, reply) {
|
|
3657
|
-
const tenantId =
|
|
3947
|
+
const tenantId = getTenantId8(request);
|
|
3658
3948
|
const { key } = request.params;
|
|
3659
3949
|
const body = request.body;
|
|
3660
3950
|
try {
|
|
3661
|
-
const storeLattice = (0,
|
|
3951
|
+
const storeLattice = (0, import_core21.getStoreLattice)("default", "metrics");
|
|
3662
3952
|
const store = storeLattice.store;
|
|
3663
3953
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3664
3954
|
if (!config) {
|
|
@@ -3683,7 +3973,7 @@ async function querySemanticMetrics(request, reply) {
|
|
|
3683
3973
|
};
|
|
3684
3974
|
}
|
|
3685
3975
|
const semanticConfig = config.config;
|
|
3686
|
-
const client = new
|
|
3976
|
+
const client = new import_core21.SemanticMetricsClient(semanticConfig);
|
|
3687
3977
|
const result = await client.semanticQuery(body);
|
|
3688
3978
|
const columnNames = result.columns.map((col) => col.name);
|
|
3689
3979
|
const allDataPoints = [];
|
|
@@ -3743,7 +4033,7 @@ async function testSemanticDataSources(request, reply) {
|
|
|
3743
4033
|
password: body.password,
|
|
3744
4034
|
headers: body.headers
|
|
3745
4035
|
};
|
|
3746
|
-
const client = new
|
|
4036
|
+
const client = new import_core21.SemanticMetricsClient(testConfig);
|
|
3747
4037
|
const datasources = await client.getDataSources();
|
|
3748
4038
|
return {
|
|
3749
4039
|
success: true,
|
|
@@ -3779,7 +4069,7 @@ async function testDatasourceMetrics(request, reply) {
|
|
|
3779
4069
|
password: body.password,
|
|
3780
4070
|
headers: body.headers
|
|
3781
4071
|
};
|
|
3782
|
-
const client = new
|
|
4072
|
+
const client = new import_core21.SemanticMetricsClient(testConfig);
|
|
3783
4073
|
const metrics = await client.getDatasourceMetrics(datasourceId);
|
|
3784
4074
|
return {
|
|
3785
4075
|
success: true,
|
|
@@ -3811,9 +4101,9 @@ function registerMetricsServerConfigRoutes(app2) {
|
|
|
3811
4101
|
}
|
|
3812
4102
|
|
|
3813
4103
|
// src/controllers/mcp-configs.ts
|
|
3814
|
-
var
|
|
4104
|
+
var import_core22 = require("@axiom-lattice/core");
|
|
3815
4105
|
var import_crypto5 = require("crypto");
|
|
3816
|
-
function
|
|
4106
|
+
function getTenantId9(request) {
|
|
3817
4107
|
const userTenantId = request.user?.tenantId;
|
|
3818
4108
|
if (userTenantId) {
|
|
3819
4109
|
return userTenantId;
|
|
@@ -3821,9 +4111,9 @@ function getTenantId8(request) {
|
|
|
3821
4111
|
return request.headers["x-tenant-id"] || "default";
|
|
3822
4112
|
}
|
|
3823
4113
|
async function getMcpServerConfigList(request, reply) {
|
|
3824
|
-
const tenantId =
|
|
4114
|
+
const tenantId = getTenantId9(request);
|
|
3825
4115
|
try {
|
|
3826
|
-
const storeLattice = (0,
|
|
4116
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3827
4117
|
const store = storeLattice.store;
|
|
3828
4118
|
const configs = await store.getAllConfigs(tenantId);
|
|
3829
4119
|
return {
|
|
@@ -3847,10 +4137,10 @@ async function getMcpServerConfigList(request, reply) {
|
|
|
3847
4137
|
}
|
|
3848
4138
|
}
|
|
3849
4139
|
async function getMcpServerConfig(request, reply) {
|
|
3850
|
-
const tenantId =
|
|
4140
|
+
const tenantId = getTenantId9(request);
|
|
3851
4141
|
const { key } = request.params;
|
|
3852
4142
|
try {
|
|
3853
|
-
const storeLattice = (0,
|
|
4143
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3854
4144
|
const store = storeLattice.store;
|
|
3855
4145
|
const config = await store.getConfigByKey(tenantId, key);
|
|
3856
4146
|
if (!config) {
|
|
@@ -3873,10 +4163,10 @@ async function getMcpServerConfig(request, reply) {
|
|
|
3873
4163
|
}
|
|
3874
4164
|
}
|
|
3875
4165
|
async function createMcpServerConfig(request, reply) {
|
|
3876
|
-
const tenantId =
|
|
4166
|
+
const tenantId = getTenantId9(request);
|
|
3877
4167
|
const body = request.body;
|
|
3878
4168
|
try {
|
|
3879
|
-
const storeLattice = (0,
|
|
4169
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3880
4170
|
const store = storeLattice.store;
|
|
3881
4171
|
const existing = await store.getConfigByKey(tenantId, body.key);
|
|
3882
4172
|
if (existing) {
|
|
@@ -3912,11 +4202,11 @@ async function createMcpServerConfig(request, reply) {
|
|
|
3912
4202
|
}
|
|
3913
4203
|
}
|
|
3914
4204
|
async function updateMcpServerConfig(request, reply) {
|
|
3915
|
-
const tenantId =
|
|
4205
|
+
const tenantId = getTenantId9(request);
|
|
3916
4206
|
const { key } = request.params;
|
|
3917
4207
|
const updates = request.body;
|
|
3918
4208
|
try {
|
|
3919
|
-
const storeLattice = (0,
|
|
4209
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3920
4210
|
const store = storeLattice.store;
|
|
3921
4211
|
const existing = await store.getConfigByKey(tenantId, key);
|
|
3922
4212
|
if (!existing) {
|
|
@@ -3936,8 +4226,8 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
3936
4226
|
}
|
|
3937
4227
|
if (shouldReconnect) {
|
|
3938
4228
|
try {
|
|
3939
|
-
if (
|
|
3940
|
-
await
|
|
4229
|
+
if (import_core22.mcpManager.hasServer(key)) {
|
|
4230
|
+
await import_core22.mcpManager.removeServer(key);
|
|
3941
4231
|
}
|
|
3942
4232
|
await connectAndRegisterTools(updated);
|
|
3943
4233
|
await store.updateConfig(tenantId, existing.id, { status: "connected" });
|
|
@@ -3962,10 +4252,10 @@ async function updateMcpServerConfig(request, reply) {
|
|
|
3962
4252
|
}
|
|
3963
4253
|
}
|
|
3964
4254
|
async function deleteMcpServerConfig(request, reply) {
|
|
3965
|
-
const tenantId =
|
|
4255
|
+
const tenantId = getTenantId9(request);
|
|
3966
4256
|
const { keyOrId } = request.params;
|
|
3967
4257
|
try {
|
|
3968
|
-
const storeLattice = (0,
|
|
4258
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
3969
4259
|
const store = storeLattice.store;
|
|
3970
4260
|
let config = await store.getConfigByKey(tenantId, keyOrId);
|
|
3971
4261
|
let configKey = keyOrId;
|
|
@@ -3983,8 +4273,8 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
3983
4273
|
};
|
|
3984
4274
|
}
|
|
3985
4275
|
try {
|
|
3986
|
-
if (
|
|
3987
|
-
await
|
|
4276
|
+
if (import_core22.mcpManager.hasServer(configKey)) {
|
|
4277
|
+
await import_core22.mcpManager.removeServer(configKey);
|
|
3988
4278
|
}
|
|
3989
4279
|
} catch (error) {
|
|
3990
4280
|
console.warn("Failed to remove from MCP manager:", error);
|
|
@@ -4009,10 +4299,10 @@ async function deleteMcpServerConfig(request, reply) {
|
|
|
4009
4299
|
}
|
|
4010
4300
|
}
|
|
4011
4301
|
async function testMcpServerConnection(request, reply) {
|
|
4012
|
-
const tenantId =
|
|
4302
|
+
const tenantId = getTenantId9(request);
|
|
4013
4303
|
const { key } = request.params;
|
|
4014
4304
|
try {
|
|
4015
|
-
const storeLattice = (0,
|
|
4305
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4016
4306
|
const store = storeLattice.store;
|
|
4017
4307
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4018
4308
|
if (!config) {
|
|
@@ -4026,11 +4316,11 @@ async function testMcpServerConnection(request, reply) {
|
|
|
4026
4316
|
try {
|
|
4027
4317
|
const testKey = `__test_${key}_${Date.now()}`;
|
|
4028
4318
|
const connection = convertToConnection(config.config);
|
|
4029
|
-
|
|
4030
|
-
await
|
|
4031
|
-
const tools = await
|
|
4319
|
+
import_core22.mcpManager.addServer(testKey, connection);
|
|
4320
|
+
await import_core22.mcpManager.connect();
|
|
4321
|
+
const tools = await import_core22.mcpManager.getAllTools();
|
|
4032
4322
|
const latency = Date.now() - startTime;
|
|
4033
|
-
await
|
|
4323
|
+
await import_core22.mcpManager.removeServer(testKey);
|
|
4034
4324
|
return {
|
|
4035
4325
|
success: true,
|
|
4036
4326
|
message: "Connection test successful",
|
|
@@ -4062,10 +4352,10 @@ async function testMcpServerConnection(request, reply) {
|
|
|
4062
4352
|
}
|
|
4063
4353
|
}
|
|
4064
4354
|
async function listMcpServerTools(request, reply) {
|
|
4065
|
-
const tenantId =
|
|
4355
|
+
const tenantId = getTenantId9(request);
|
|
4066
4356
|
const { key } = request.params;
|
|
4067
4357
|
try {
|
|
4068
|
-
const storeLattice = (0,
|
|
4358
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4069
4359
|
const store = storeLattice.store;
|
|
4070
4360
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4071
4361
|
if (!config) {
|
|
@@ -4075,10 +4365,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
4075
4365
|
message: "MCP server configuration not found"
|
|
4076
4366
|
};
|
|
4077
4367
|
}
|
|
4078
|
-
if (!
|
|
4368
|
+
if (!import_core22.mcpManager.hasServer(key)) {
|
|
4079
4369
|
await connectAndRegisterTools(config);
|
|
4080
4370
|
}
|
|
4081
|
-
const tools = await
|
|
4371
|
+
const tools = await import_core22.mcpManager.getAllTools();
|
|
4082
4372
|
return {
|
|
4083
4373
|
success: true,
|
|
4084
4374
|
message: "Tools retrieved successfully",
|
|
@@ -4095,10 +4385,10 @@ async function listMcpServerTools(request, reply) {
|
|
|
4095
4385
|
}
|
|
4096
4386
|
}
|
|
4097
4387
|
async function connectMcpServer(request, reply) {
|
|
4098
|
-
const tenantId =
|
|
4388
|
+
const tenantId = getTenantId9(request);
|
|
4099
4389
|
const { key } = request.params;
|
|
4100
4390
|
try {
|
|
4101
|
-
const storeLattice = (0,
|
|
4391
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4102
4392
|
const store = storeLattice.store;
|
|
4103
4393
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4104
4394
|
if (!config) {
|
|
@@ -4119,7 +4409,7 @@ async function connectMcpServer(request, reply) {
|
|
|
4119
4409
|
};
|
|
4120
4410
|
} catch (error) {
|
|
4121
4411
|
console.error("Failed to connect MCP server:", error);
|
|
4122
|
-
const storeLattice = (0,
|
|
4412
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4123
4413
|
const store = storeLattice.store;
|
|
4124
4414
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4125
4415
|
if (config) {
|
|
@@ -4132,10 +4422,10 @@ async function connectMcpServer(request, reply) {
|
|
|
4132
4422
|
}
|
|
4133
4423
|
}
|
|
4134
4424
|
async function disconnectMcpServer(request, reply) {
|
|
4135
|
-
const tenantId =
|
|
4425
|
+
const tenantId = getTenantId9(request);
|
|
4136
4426
|
const { key } = request.params;
|
|
4137
4427
|
try {
|
|
4138
|
-
const storeLattice = (0,
|
|
4428
|
+
const storeLattice = (0, import_core22.getStoreLattice)("default", "mcp");
|
|
4139
4429
|
const store = storeLattice.store;
|
|
4140
4430
|
const config = await store.getConfigByKey(tenantId, key);
|
|
4141
4431
|
if (!config) {
|
|
@@ -4145,8 +4435,8 @@ async function disconnectMcpServer(request, reply) {
|
|
|
4145
4435
|
message: "MCP server configuration not found"
|
|
4146
4436
|
};
|
|
4147
4437
|
}
|
|
4148
|
-
if (
|
|
4149
|
-
await
|
|
4438
|
+
if (import_core22.mcpManager.hasServer(key)) {
|
|
4439
|
+
await import_core22.mcpManager.removeServer(key);
|
|
4150
4440
|
}
|
|
4151
4441
|
const updated = await store.updateConfig(tenantId, config.id, {
|
|
4152
4442
|
status: "disconnected"
|
|
@@ -4176,10 +4466,10 @@ async function testMcpServerTools(request, reply) {
|
|
|
4176
4466
|
}
|
|
4177
4467
|
const testKey = `__test_${Date.now()}`;
|
|
4178
4468
|
const connection = convertToConnection(body.config);
|
|
4179
|
-
|
|
4180
|
-
await
|
|
4181
|
-
const tools = await
|
|
4182
|
-
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);
|
|
4183
4473
|
return {
|
|
4184
4474
|
success: true,
|
|
4185
4475
|
message: "Tools retrieved successfully",
|
|
@@ -4216,14 +4506,14 @@ function convertToConnection(config) {
|
|
|
4216
4506
|
}
|
|
4217
4507
|
async function connectAndRegisterTools(config) {
|
|
4218
4508
|
const connection = convertToConnection(config.config);
|
|
4219
|
-
|
|
4220
|
-
await
|
|
4221
|
-
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();
|
|
4222
4512
|
const selectedTools = allTools.filter(
|
|
4223
4513
|
(tool) => config.selectedTools.includes(tool.name)
|
|
4224
4514
|
);
|
|
4225
4515
|
for (const tool of selectedTools) {
|
|
4226
|
-
|
|
4516
|
+
import_core22.toolLatticeManager.registerExistingTool(tool.name, tool);
|
|
4227
4517
|
}
|
|
4228
4518
|
}
|
|
4229
4519
|
function registerMcpServerConfigRoutes(app2) {
|
|
@@ -4240,11 +4530,11 @@ function registerMcpServerConfigRoutes(app2) {
|
|
|
4240
4530
|
}
|
|
4241
4531
|
|
|
4242
4532
|
// src/controllers/users.ts
|
|
4243
|
-
var
|
|
4533
|
+
var import_core23 = require("@axiom-lattice/core");
|
|
4244
4534
|
var import_uuid3 = require("uuid");
|
|
4245
4535
|
var UsersController = class {
|
|
4246
4536
|
constructor() {
|
|
4247
|
-
this.userStore = (0,
|
|
4537
|
+
this.userStore = (0, import_core23.getStoreLattice)("default", "user").store;
|
|
4248
4538
|
}
|
|
4249
4539
|
async listUsers(request, reply) {
|
|
4250
4540
|
const { email } = request.query;
|
|
@@ -4322,11 +4612,11 @@ function registerUserRoutes(app2) {
|
|
|
4322
4612
|
}
|
|
4323
4613
|
|
|
4324
4614
|
// src/controllers/tenants.ts
|
|
4325
|
-
var
|
|
4615
|
+
var import_core24 = require("@axiom-lattice/core");
|
|
4326
4616
|
var import_uuid4 = require("uuid");
|
|
4327
4617
|
var TenantsController = class {
|
|
4328
4618
|
constructor() {
|
|
4329
|
-
this.tenantStore = (0,
|
|
4619
|
+
this.tenantStore = (0, import_core24.getStoreLattice)("default", "tenant").store;
|
|
4330
4620
|
}
|
|
4331
4621
|
// ==================== Tenant CRUD ====================
|
|
4332
4622
|
async listTenants(request, reply) {
|
|
@@ -4390,7 +4680,7 @@ function registerTenantRoutes(app2) {
|
|
|
4390
4680
|
}
|
|
4391
4681
|
|
|
4392
4682
|
// src/controllers/auth.ts
|
|
4393
|
-
var
|
|
4683
|
+
var import_core25 = require("@axiom-lattice/core");
|
|
4394
4684
|
var import_uuid5 = require("uuid");
|
|
4395
4685
|
var defaultAuthConfig = {
|
|
4396
4686
|
autoApproveUsers: true,
|
|
@@ -4399,9 +4689,9 @@ var defaultAuthConfig = {
|
|
|
4399
4689
|
};
|
|
4400
4690
|
var AuthController = class {
|
|
4401
4691
|
constructor(config = {}) {
|
|
4402
|
-
this.userStore = (0,
|
|
4403
|
-
this.tenantStore = (0,
|
|
4404
|
-
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;
|
|
4405
4695
|
this.config = { ...defaultAuthConfig, ...config };
|
|
4406
4696
|
}
|
|
4407
4697
|
async register(request, reply) {
|
|
@@ -4773,7 +5063,7 @@ function registerAuthRoutes(app2, config) {
|
|
|
4773
5063
|
}
|
|
4774
5064
|
|
|
4775
5065
|
// src/channels/lark/routes.ts
|
|
4776
|
-
var
|
|
5066
|
+
var import_core27 = require("@axiom-lattice/core");
|
|
4777
5067
|
var import_pg_stores = require("@axiom-lattice/pg-stores");
|
|
4778
5068
|
|
|
4779
5069
|
// src/channels/lark/parser.ts
|
|
@@ -5021,7 +5311,7 @@ function resolveSubjectType(mappingMode, chatType) {
|
|
|
5021
5311
|
}
|
|
5022
5312
|
|
|
5023
5313
|
// src/channels/lark/runner.ts
|
|
5024
|
-
var
|
|
5314
|
+
var import_core26 = require("@axiom-lattice/core");
|
|
5025
5315
|
var import_protocols4 = require("@axiom-lattice/protocols");
|
|
5026
5316
|
|
|
5027
5317
|
// src/channels/lark/aggregator.ts
|
|
@@ -5034,7 +5324,7 @@ function aggregateLarkReply(messageId, chunks) {
|
|
|
5034
5324
|
|
|
5035
5325
|
// src/channels/lark/runner.ts
|
|
5036
5326
|
async function runAgentAndCollectLarkReply(input) {
|
|
5037
|
-
const agent =
|
|
5327
|
+
const agent = import_core26.agentInstanceManager.getAgent({
|
|
5038
5328
|
tenant_id: input.tenantId,
|
|
5039
5329
|
assistant_id: input.assistantId,
|
|
5040
5330
|
thread_id: input.threadId,
|
|
@@ -5146,7 +5436,7 @@ function createDefaultLarkDependencies() {
|
|
|
5146
5436
|
const installationStore = new import_pg_stores.PostgreSQLChannelInstallationStore({
|
|
5147
5437
|
poolConfig: getDatabaseUrl()
|
|
5148
5438
|
});
|
|
5149
|
-
const threadStore = (0,
|
|
5439
|
+
const threadStore = (0, import_core27.getStoreLattice)("default", "thread").store;
|
|
5150
5440
|
const mappingStore = new import_pg_stores.ChannelIdentityMappingStore({
|
|
5151
5441
|
poolConfig: getDatabaseUrl()
|
|
5152
5442
|
});
|
|
@@ -5227,7 +5517,7 @@ function registerChannelRoutes(app2, dependencies = {}) {
|
|
|
5227
5517
|
|
|
5228
5518
|
// src/controllers/channel-installations.ts
|
|
5229
5519
|
var import_crypto8 = require("crypto");
|
|
5230
|
-
function
|
|
5520
|
+
function getTenantId10(request) {
|
|
5231
5521
|
const userTenantId = request.user?.tenantId;
|
|
5232
5522
|
if (userTenantId) {
|
|
5233
5523
|
return userTenantId;
|
|
@@ -5245,7 +5535,7 @@ async function getInstallationStore() {
|
|
|
5245
5535
|
});
|
|
5246
5536
|
}
|
|
5247
5537
|
async function getChannelInstallationList(request, reply) {
|
|
5248
|
-
const tenantId =
|
|
5538
|
+
const tenantId = getTenantId10(request);
|
|
5249
5539
|
const { channel } = request.query;
|
|
5250
5540
|
try {
|
|
5251
5541
|
const store = await getInstallationStore();
|
|
@@ -5271,7 +5561,7 @@ async function getChannelInstallationList(request, reply) {
|
|
|
5271
5561
|
}
|
|
5272
5562
|
}
|
|
5273
5563
|
async function getChannelInstallation(request, reply) {
|
|
5274
|
-
const tenantId =
|
|
5564
|
+
const tenantId = getTenantId10(request);
|
|
5275
5565
|
const { installationId } = request.params;
|
|
5276
5566
|
try {
|
|
5277
5567
|
const store = await getInstallationStore();
|
|
@@ -5304,7 +5594,7 @@ async function getChannelInstallation(request, reply) {
|
|
|
5304
5594
|
}
|
|
5305
5595
|
}
|
|
5306
5596
|
async function createChannelInstallation(request, reply) {
|
|
5307
|
-
const tenantId =
|
|
5597
|
+
const tenantId = getTenantId10(request);
|
|
5308
5598
|
const body = request.body;
|
|
5309
5599
|
try {
|
|
5310
5600
|
if (!body.channel) {
|
|
@@ -5367,7 +5657,7 @@ async function createChannelInstallation(request, reply) {
|
|
|
5367
5657
|
}
|
|
5368
5658
|
}
|
|
5369
5659
|
async function updateChannelInstallation(request, reply) {
|
|
5370
|
-
const tenantId =
|
|
5660
|
+
const tenantId = getTenantId10(request);
|
|
5371
5661
|
const { installationId } = request.params;
|
|
5372
5662
|
const body = request.body;
|
|
5373
5663
|
try {
|
|
@@ -5413,7 +5703,7 @@ async function updateChannelInstallation(request, reply) {
|
|
|
5413
5703
|
}
|
|
5414
5704
|
}
|
|
5415
5705
|
async function deleteChannelInstallation(request, reply) {
|
|
5416
|
-
const tenantId =
|
|
5706
|
+
const tenantId = getTenantId10(request);
|
|
5417
5707
|
const { installationId } = request.params;
|
|
5418
5708
|
try {
|
|
5419
5709
|
const store = await getInstallationStore();
|
|
@@ -5599,6 +5889,29 @@ var registerLatticeRoutes = (app2) => {
|
|
|
5599
5889
|
});
|
|
5600
5890
|
registerChannelRoutes(app2);
|
|
5601
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);
|
|
5602
5915
|
app2.delete(
|
|
5603
5916
|
"/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
|
|
5604
5917
|
removePendingMessageHandler
|
|
@@ -5668,7 +5981,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
|
|
|
5668
5981
|
};
|
|
5669
5982
|
|
|
5670
5983
|
// src/services/agent_task_consumer.ts
|
|
5671
|
-
var
|
|
5984
|
+
var import_core28 = require("@axiom-lattice/core");
|
|
5672
5985
|
var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
5673
5986
|
const {
|
|
5674
5987
|
assistant_id,
|
|
@@ -5677,24 +5990,55 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
5677
5990
|
"x-tenant-id": tenant_id,
|
|
5678
5991
|
command,
|
|
5679
5992
|
callback_event,
|
|
5680
|
-
runConfig
|
|
5993
|
+
runConfig,
|
|
5994
|
+
main_thread_id,
|
|
5995
|
+
main_tenant_id,
|
|
5996
|
+
main_assistant_id
|
|
5681
5997
|
} = taskRequest;
|
|
5682
5998
|
try {
|
|
5683
5999
|
console.log(
|
|
5684
6000
|
`\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
|
|
5685
6001
|
);
|
|
5686
|
-
const agent =
|
|
5687
|
-
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);
|
|
5688
6004
|
if (callback_event) {
|
|
5689
6005
|
agent.subscribeOnce("message:completed", (evt) => {
|
|
5690
|
-
|
|
6006
|
+
import_core28.eventBus.publish(callback_event, {
|
|
5691
6007
|
success: true,
|
|
5692
6008
|
state: evt.state,
|
|
5693
6009
|
config: { assistant_id, thread_id, tenant_id }
|
|
5694
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
|
+
}
|
|
5695
6039
|
});
|
|
5696
6040
|
agent.subscribeOnce("message:interrupted", (evt) => {
|
|
5697
|
-
|
|
6041
|
+
import_core28.eventBus.publish(callback_event, {
|
|
5698
6042
|
success: true,
|
|
5699
6043
|
state: evt.state,
|
|
5700
6044
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -5718,7 +6062,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
|
|
|
5718
6062
|
return handleAgentTask(taskRequest, nextRetryCount);
|
|
5719
6063
|
}
|
|
5720
6064
|
if (callback_event) {
|
|
5721
|
-
|
|
6065
|
+
import_core28.eventBus.publish(callback_event, {
|
|
5722
6066
|
success: false,
|
|
5723
6067
|
error: error instanceof Error ? error.message : String(error),
|
|
5724
6068
|
config: { assistant_id, thread_id, tenant_id }
|
|
@@ -5756,7 +6100,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
5756
6100
|
* 初始化事件监听和队列轮询
|
|
5757
6101
|
*/
|
|
5758
6102
|
initialize() {
|
|
5759
|
-
|
|
6103
|
+
import_core28.eventBus.subscribe(import_core28.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
|
|
5760
6104
|
this.startPollingQueue();
|
|
5761
6105
|
console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
|
|
5762
6106
|
}
|
|
@@ -5875,7 +6219,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
|
|
|
5875
6219
|
handleAgentTask(taskRequest).catch((error) => {
|
|
5876
6220
|
console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
|
|
5877
6221
|
if (taskRequest.callback_event) {
|
|
5878
|
-
|
|
6222
|
+
import_core28.eventBus.publish(taskRequest.callback_event, {
|
|
5879
6223
|
success: false,
|
|
5880
6224
|
error: error instanceof Error ? error.message : String(error),
|
|
5881
6225
|
config: {
|
|
@@ -5895,7 +6239,7 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
|
|
|
5895
6239
|
var AgentTaskConsumer = _AgentTaskConsumer;
|
|
5896
6240
|
|
|
5897
6241
|
// src/index.ts
|
|
5898
|
-
var
|
|
6242
|
+
var import_core29 = require("@axiom-lattice/core");
|
|
5899
6243
|
var import_protocols5 = require("@axiom-lattice/protocols");
|
|
5900
6244
|
var import_meta = {};
|
|
5901
6245
|
process.on("unhandledRejection", (reason, promise) => {
|
|
@@ -5911,11 +6255,11 @@ var DEFAULT_LOGGER_CONFIG = {
|
|
|
5911
6255
|
var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
|
|
5912
6256
|
var logger = loggerLattice.client;
|
|
5913
6257
|
function initializeLogger(config) {
|
|
5914
|
-
if (
|
|
5915
|
-
|
|
6258
|
+
if (import_core29.loggerLatticeManager.hasLattice("default")) {
|
|
6259
|
+
import_core29.loggerLatticeManager.removeLattice("default");
|
|
5916
6260
|
}
|
|
5917
|
-
(0,
|
|
5918
|
-
return (0,
|
|
6261
|
+
(0, import_core29.registerLoggerLattice)("default", config);
|
|
6262
|
+
return (0, import_core29.getLoggerLattice)("default");
|
|
5919
6263
|
}
|
|
5920
6264
|
var app = (0, import_fastify.default)({
|
|
5921
6265
|
logger: false,
|
|
@@ -6011,7 +6355,7 @@ app.setErrorHandler((error, request, reply) => {
|
|
|
6011
6355
|
});
|
|
6012
6356
|
function getConfiguredSandboxProvider() {
|
|
6013
6357
|
const sandboxProviderType = process.env.SANDBOX_PROVIDER_TYPE || "microsandbox-remote";
|
|
6014
|
-
return (0,
|
|
6358
|
+
return (0, import_core29.createSandboxProvider)({
|
|
6015
6359
|
type: sandboxProviderType,
|
|
6016
6360
|
remoteBaseURL: process.env.SANDBOX_BASE_URL,
|
|
6017
6361
|
microsandboxServiceBaseURL: process.env.MICROSANDBOX_SERVICE_BASE_URL,
|
|
@@ -6040,17 +6384,32 @@ var start = async (config) => {
|
|
|
6040
6384
|
app.decorate("loggerLattice", loggerLattice);
|
|
6041
6385
|
registerLatticeRoutes(app);
|
|
6042
6386
|
try {
|
|
6043
|
-
const storeLattice = (0,
|
|
6387
|
+
const storeLattice = (0, import_core29.getStoreLattice)("default", "database");
|
|
6044
6388
|
const store = storeLattice.store;
|
|
6045
|
-
|
|
6389
|
+
import_core29.sqlDatabaseManager.setConfigStore(store);
|
|
6046
6390
|
logger.info("Database config store set for SqlDatabaseManager");
|
|
6047
6391
|
} catch (error) {
|
|
6048
6392
|
logger.warn("Failed to set database config store: " + (error instanceof Error ? error.message : String(error)));
|
|
6049
6393
|
}
|
|
6050
|
-
if (!
|
|
6051
|
-
|
|
6394
|
+
if (!import_core29.sandboxLatticeManager.hasLattice("default")) {
|
|
6395
|
+
import_core29.sandboxLatticeManager.registerLattice("default", getConfiguredSandboxProvider());
|
|
6052
6396
|
logger.info("Registered sandbox manager from env configuration");
|
|
6053
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
|
+
}
|
|
6054
6413
|
const target_port = config?.port || Number(process.env.PORT) || 4001;
|
|
6055
6414
|
await app.listen({ port: target_port, host: "0.0.0.0" });
|
|
6056
6415
|
logger.info(`Lattice Gateway is running on port: ${target_port}`);
|
|
@@ -6069,7 +6428,7 @@ var start = async (config) => {
|
|
|
6069
6428
|
}
|
|
6070
6429
|
try {
|
|
6071
6430
|
logger.info("Starting agent instance recovery...");
|
|
6072
|
-
const restoreStats = await
|
|
6431
|
+
const restoreStats = await import_core29.agentInstanceManager.restore();
|
|
6073
6432
|
logger.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
|
|
6074
6433
|
} catch (error) {
|
|
6075
6434
|
logger.error("Agent recovery failed", { error });
|