@axiom-lattice/gateway 2.1.106 → 2.1.108

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/dist/index.mjs CHANGED
@@ -1,3 +1,6 @@
1
+ import {
2
+ registerMcpServerConfigRoutes
3
+ } from "./chunk-K4XELOSO.mjs";
1
4
  import {
2
5
  Logger,
3
6
  getQrCode,
@@ -196,6 +199,21 @@ async function deleteAssistant(request, reply) {
196
199
  });
197
200
  }
198
201
  eventBus.publish("assistant:deleted", { id, tenantId });
202
+ const userId = getUserId(request);
203
+ if (userId) {
204
+ try {
205
+ const linkStore = getStoreLattice("default", "userTenantLink").store;
206
+ const link = await linkStore.getLink(userId, tenantId);
207
+ const meta = link?.metadata || {};
208
+ if (meta.personalAssistantId === id) {
209
+ delete meta.personalAssistantId;
210
+ delete meta.personalProjectId;
211
+ delete meta.personalWorkspaceId;
212
+ await linkStore.updateLink(userId, tenantId, { metadata: meta });
213
+ }
214
+ } catch {
215
+ }
216
+ }
199
217
  return {
200
218
  success: true,
201
219
  message: "Successfully deleted assistant"
@@ -278,7 +296,7 @@ var createRun = async (request, reply) => {
278
296
  command,
279
297
  custom_run_config: mergedConfig
280
298
  }, mode);
281
- const stream = agent.chunkStream(result.messageId, [MessageChunkTypes.MESSAGE_COMPLETED]);
299
+ const stream = agent.chunkStream(result.messageId, [MessageChunkTypes.MESSAGE_COMPLETED, MessageChunkTypes.INTERRUPT, MessageChunkTypes.MESSAGE_FAILED]);
282
300
  for await (const chunk of stream) {
283
301
  const success = reply.raw.write(`data: ${JSON.stringify(chunk)}
284
302
 
@@ -1548,6 +1566,442 @@ async function filterSkillsByLicense(request, reply) {
1548
1566
  }
1549
1567
  }
1550
1568
 
1569
+ // src/services/collection_service.ts
1570
+ import { v4 as uuidv4 } from "uuid";
1571
+ import { Document } from "@langchain/core/documents";
1572
+ import {
1573
+ collectionLatticeManager,
1574
+ embeddingsLatticeManager,
1575
+ getOrCreateCollectionVectorStore,
1576
+ getCollectionEntryCount,
1577
+ listCollectionEntries,
1578
+ removeCollectionVectorStore
1579
+ } from "@axiom-lattice/core";
1580
+ function getTenantId5(request) {
1581
+ return request.user?.tenantId || request.headers["x-tenant-id"] || "default";
1582
+ }
1583
+ var CollectionService = class {
1584
+ // ─── Collection CRUD ──────────────────────────────────────────
1585
+ async getAllCollections(request) {
1586
+ const tenantId = getTenantId5(request);
1587
+ const collections = await collectionLatticeManager.getAllCollections(tenantId);
1588
+ for (const c of collections) {
1589
+ try {
1590
+ c._entryCount = await getCollectionEntryCount(c.name, c.embeddingKey, c.tenantId);
1591
+ } catch {
1592
+ c._entryCount = 0;
1593
+ }
1594
+ }
1595
+ return collections;
1596
+ }
1597
+ async getCollectionByName(request, name) {
1598
+ const tenantId = getTenantId5(request);
1599
+ return collectionLatticeManager.getCollection(tenantId, name);
1600
+ }
1601
+ async createCollection(request, data) {
1602
+ const tenantId = getTenantId5(request);
1603
+ const collection = await collectionLatticeManager.registerCollection(tenantId, data);
1604
+ try {
1605
+ await getOrCreateCollectionVectorStore(data.name, data.embeddingKey, tenantId);
1606
+ } catch (err) {
1607
+ console.warn(`[CollectionService] Failed to init vector store for ${data.name}:`, err);
1608
+ }
1609
+ return collection;
1610
+ }
1611
+ async updateCollection(request, name, updates) {
1612
+ const tenantId = getTenantId5(request);
1613
+ return collectionLatticeManager.updateCollection(tenantId, name, updates);
1614
+ }
1615
+ async deleteCollection(request, name) {
1616
+ const tenantId = getTenantId5(request);
1617
+ await removeCollectionVectorStore(name, tenantId);
1618
+ return collectionLatticeManager.removeCollection(tenantId, name);
1619
+ }
1620
+ // ─── Entry CRUD ───────────────────────────────────────────────
1621
+ async getEntries(request, collectionName) {
1622
+ const collection = await this.getCollectionByName(request, collectionName);
1623
+ if (!collection) throw new Error(`Collection "${collectionName}" not found`);
1624
+ const docs = await listCollectionEntries(collectionName, collection.embeddingKey, collection.tenantId);
1625
+ return docs.map((doc) => ({
1626
+ id: doc.metadata._id || "",
1627
+ content: doc.pageContent,
1628
+ metadata: Object.fromEntries(
1629
+ Object.entries(doc.metadata).filter(([k]) => !k.startsWith("_"))
1630
+ )
1631
+ }));
1632
+ }
1633
+ async createEntry(request, collectionName, data) {
1634
+ const collection = await this.getCollectionByName(request, collectionName);
1635
+ if (!collection) throw new Error(`Collection "${collectionName}" not found`);
1636
+ const vectorStore = await getOrCreateCollectionVectorStore(
1637
+ collectionName,
1638
+ collection.embeddingKey,
1639
+ collection.tenantId
1640
+ );
1641
+ const entryId = uuidv4();
1642
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1643
+ const doc = new Document({
1644
+ pageContent: data.content,
1645
+ metadata: {
1646
+ _id: entryId,
1647
+ _created_at: now,
1648
+ _updated_at: now,
1649
+ ...data.metadata || {}
1650
+ }
1651
+ });
1652
+ await vectorStore.addDocuments([doc]);
1653
+ return { id: entryId, content: data.content, metadata: data.metadata || {} };
1654
+ }
1655
+ async getEntry(request, collectionName, entryId) {
1656
+ const collection = await this.getCollectionByName(request, collectionName);
1657
+ if (!collection) throw new Error(`Collection "${collectionName}" not found`);
1658
+ const docs = await listCollectionEntries(collectionName, collection.embeddingKey, collection.tenantId);
1659
+ const doc = docs.find((d) => d.metadata._id === entryId);
1660
+ if (!doc) return null;
1661
+ return {
1662
+ id: entryId,
1663
+ content: doc.pageContent,
1664
+ metadata: Object.fromEntries(
1665
+ Object.entries(doc.metadata).filter(([k]) => !k.startsWith("_"))
1666
+ )
1667
+ };
1668
+ }
1669
+ async updateEntry(request, collectionName, entryId, data) {
1670
+ const existing = await this.getEntry(request, collectionName, entryId);
1671
+ if (!existing) return null;
1672
+ const collection = await this.getCollectionByName(request, collectionName);
1673
+ if (!collection) throw new Error(`Collection "${collectionName}" not found`);
1674
+ const vectorStore = await getOrCreateCollectionVectorStore(
1675
+ collectionName,
1676
+ collection.embeddingKey,
1677
+ collection.tenantId
1678
+ );
1679
+ try {
1680
+ await vectorStore.delete({ filter: { _id: entryId } });
1681
+ } catch {
1682
+ }
1683
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1684
+ const mergedMetadata = { ...existing.metadata, ...data.metadata || {} };
1685
+ const doc = new Document({
1686
+ pageContent: data.content ?? existing.content,
1687
+ metadata: { _id: entryId, _created_at: now, _updated_at: now, ...mergedMetadata }
1688
+ });
1689
+ await vectorStore.addDocuments([doc]);
1690
+ return { id: entryId, content: data.content ?? existing.content, metadata: mergedMetadata };
1691
+ }
1692
+ async deleteEntry(request, collectionName, entryId) {
1693
+ const collection = await this.getCollectionByName(request, collectionName);
1694
+ if (!collection) throw new Error(`Collection "${collectionName}" not found`);
1695
+ const vectorStore = await getOrCreateCollectionVectorStore(
1696
+ collectionName,
1697
+ collection.embeddingKey,
1698
+ collection.tenantId
1699
+ );
1700
+ try {
1701
+ await vectorStore.delete({ filter: { _id: entryId } });
1702
+ return true;
1703
+ } catch {
1704
+ return false;
1705
+ }
1706
+ }
1707
+ async searchEntries(request, collectionName, params) {
1708
+ const collection = await this.getCollectionByName(request, collectionName);
1709
+ if (!collection) throw new Error(`Collection "${collectionName}" not found`);
1710
+ const vectorStore = await getOrCreateCollectionVectorStore(
1711
+ collectionName,
1712
+ collection.embeddingKey,
1713
+ collection.tenantId
1714
+ );
1715
+ let embeddings;
1716
+ try {
1717
+ embeddings = embeddingsLatticeManager.getEmbeddingsClient(collection.embeddingKey);
1718
+ } catch {
1719
+ embeddings = embeddingsLatticeManager.getEmbeddingsClient("default");
1720
+ }
1721
+ const queryVector = await embeddings.embedQuery(params.query);
1722
+ const results = await vectorStore.similaritySearchVectorWithScore(
1723
+ queryVector,
1724
+ params.top_k || 5,
1725
+ params.filter
1726
+ );
1727
+ return results.map(([doc, score]) => ({
1728
+ id: doc.metadata._id || uuidv4(),
1729
+ content: doc.pageContent,
1730
+ metadata: Object.fromEntries(
1731
+ Object.entries(doc.metadata).filter(([k]) => !k.startsWith("_"))
1732
+ ),
1733
+ score
1734
+ }));
1735
+ }
1736
+ };
1737
+
1738
+ // src/controllers/collections.ts
1739
+ var collectionService = new CollectionService();
1740
+ function serializeCollection(collection) {
1741
+ return {
1742
+ id: collection.id,
1743
+ name: collection.name,
1744
+ label: collection.label,
1745
+ embeddingKey: collection.embeddingKey,
1746
+ schema: collection.schema,
1747
+ entryCount: collection._entryCount ?? 0,
1748
+ createdAt: collection.createdAt instanceof Date ? collection.createdAt.toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
1749
+ updatedAt: collection.updatedAt instanceof Date ? collection.updatedAt.toISOString() : (/* @__PURE__ */ new Date()).toISOString()
1750
+ };
1751
+ }
1752
+ async function getCollectionList(request, reply) {
1753
+ try {
1754
+ const collections = await collectionService.getAllCollections(request);
1755
+ return {
1756
+ success: true,
1757
+ message: "Successfully retrieved collection list",
1758
+ data: {
1759
+ records: collections.map(serializeCollection),
1760
+ total: collections.length
1761
+ }
1762
+ };
1763
+ } catch (error) {
1764
+ return reply.status(500).send({
1765
+ success: false,
1766
+ message: `Failed to retrieve collections: ${error.message}`,
1767
+ data: { records: [], total: 0 }
1768
+ });
1769
+ }
1770
+ }
1771
+ async function getCollection(request, reply) {
1772
+ try {
1773
+ const { name } = request.params;
1774
+ const collection = await collectionService.getCollectionByName(request, name);
1775
+ if (!collection) {
1776
+ return reply.status(404).send({ success: false, message: "Collection not found" });
1777
+ }
1778
+ return {
1779
+ success: true,
1780
+ message: "Successfully retrieved collection",
1781
+ data: serializeCollection(collection)
1782
+ };
1783
+ } catch (error) {
1784
+ return reply.status(500).send({
1785
+ success: false,
1786
+ message: `Failed to retrieve collection: ${error.message}`
1787
+ });
1788
+ }
1789
+ }
1790
+ async function createCollection(request, reply) {
1791
+ try {
1792
+ const data = request.body;
1793
+ if (!data.name) {
1794
+ return reply.status(400).send({ success: false, message: "name is required" });
1795
+ }
1796
+ if (!data.label) {
1797
+ return reply.status(400).send({ success: false, message: "label is required" });
1798
+ }
1799
+ if (!data.embeddingKey) {
1800
+ return reply.status(400).send({ success: false, message: "embeddingKey is required" });
1801
+ }
1802
+ const collection = await collectionService.createCollection(request, data);
1803
+ return reply.status(201).send({
1804
+ success: true,
1805
+ message: "Successfully created collection",
1806
+ data: serializeCollection(collection)
1807
+ });
1808
+ } catch (error) {
1809
+ if (error.message?.includes("already exists")) {
1810
+ return reply.status(409).send({ success: false, message: error.message });
1811
+ }
1812
+ return reply.status(500).send({
1813
+ success: false,
1814
+ message: `Failed to create collection: ${error.message}`
1815
+ });
1816
+ }
1817
+ }
1818
+ async function updateCollection(request, reply) {
1819
+ try {
1820
+ const { name } = request.params;
1821
+ const updates = request.body;
1822
+ const collection = await collectionService.updateCollection(
1823
+ request,
1824
+ name,
1825
+ updates
1826
+ );
1827
+ if (!collection) {
1828
+ return reply.status(404).send({ success: false, message: "Collection not found" });
1829
+ }
1830
+ return {
1831
+ success: true,
1832
+ message: "Successfully updated collection",
1833
+ data: serializeCollection(collection)
1834
+ };
1835
+ } catch (error) {
1836
+ return reply.status(500).send({
1837
+ success: false,
1838
+ message: `Failed to update collection: ${error.message}`
1839
+ });
1840
+ }
1841
+ }
1842
+ async function deleteCollection(request, reply) {
1843
+ try {
1844
+ const { name } = request.params;
1845
+ const result = await collectionService.deleteCollection(request, name);
1846
+ if (!result) {
1847
+ return reply.status(404).send({ success: false, message: "Collection not found" });
1848
+ }
1849
+ return { success: true, message: "Successfully deleted collection" };
1850
+ } catch (error) {
1851
+ return reply.status(500).send({
1852
+ success: false,
1853
+ message: `Failed to delete collection: ${error.message}`
1854
+ });
1855
+ }
1856
+ }
1857
+
1858
+ // src/controllers/embeddings.ts
1859
+ import { embeddingsLatticeManager as embeddingsLatticeManager2 } from "@axiom-lattice/core";
1860
+ async function listEmbeddings(_request, _reply) {
1861
+ try {
1862
+ const info = embeddingsLatticeManager2.getAllEmbeddingsInfo();
1863
+ return {
1864
+ success: true,
1865
+ message: "Successfully retrieved embedding models",
1866
+ data: { records: info, total: info.length }
1867
+ };
1868
+ } catch (error) {
1869
+ return {
1870
+ success: false,
1871
+ message: `Failed to retrieve embeddings: ${error.message}`,
1872
+ data: { records: [], total: 0 }
1873
+ };
1874
+ }
1875
+ }
1876
+
1877
+ // src/controllers/entries.ts
1878
+ var collectionService2 = new CollectionService();
1879
+ async function listEntries(request, reply) {
1880
+ try {
1881
+ const { name } = request.params;
1882
+ const entries = await collectionService2.getEntries(request, name);
1883
+ return {
1884
+ success: true,
1885
+ message: "Successfully retrieved entries",
1886
+ data: { records: entries, total: entries.length }
1887
+ };
1888
+ } catch (error) {
1889
+ return reply.status(500).send({
1890
+ success: false,
1891
+ message: `Failed to retrieve entries: ${error.message}`,
1892
+ data: { records: [], total: 0 }
1893
+ });
1894
+ }
1895
+ }
1896
+ async function createEntry(request, reply) {
1897
+ try {
1898
+ const { name } = request.params;
1899
+ const data = request.body;
1900
+ if (!data.content) {
1901
+ return reply.status(400).send({ success: false, message: "content is required" });
1902
+ }
1903
+ const entry = await collectionService2.createEntry(request, name, data);
1904
+ return reply.status(201).send({
1905
+ success: true,
1906
+ message: "Successfully created entry",
1907
+ data: entry
1908
+ });
1909
+ } catch (error) {
1910
+ if (error.message?.includes("not found")) {
1911
+ return reply.status(404).send({ success: false, message: error.message });
1912
+ }
1913
+ return reply.status(500).send({
1914
+ success: false,
1915
+ message: `Failed to create entry: ${error.message}`
1916
+ });
1917
+ }
1918
+ }
1919
+ async function getEntry(request, reply) {
1920
+ try {
1921
+ const { name, id } = request.params;
1922
+ const entry = await collectionService2.getEntry(request, name, id);
1923
+ if (!entry) {
1924
+ return reply.status(404).send({ success: false, message: "Entry not found" });
1925
+ }
1926
+ return {
1927
+ success: true,
1928
+ message: "Successfully retrieved entry",
1929
+ data: entry
1930
+ };
1931
+ } catch (error) {
1932
+ return reply.status(500).send({
1933
+ success: false,
1934
+ message: `Failed to retrieve entry: ${error.message}`
1935
+ });
1936
+ }
1937
+ }
1938
+ async function updateEntry(request, reply) {
1939
+ try {
1940
+ const { name, id } = request.params;
1941
+ const data = request.body;
1942
+ const entry = await collectionService2.updateEntry(request, name, id, data);
1943
+ if (!entry) {
1944
+ return reply.status(404).send({ success: false, message: "Entry not found" });
1945
+ }
1946
+ return {
1947
+ success: true,
1948
+ message: "Successfully updated entry",
1949
+ data: entry
1950
+ };
1951
+ } catch (error) {
1952
+ if (error.message?.includes("not found")) {
1953
+ return reply.status(404).send({ success: false, message: error.message });
1954
+ }
1955
+ return reply.status(500).send({
1956
+ success: false,
1957
+ message: `Failed to update entry: ${error.message}`
1958
+ });
1959
+ }
1960
+ }
1961
+ async function deleteEntry(request, reply) {
1962
+ try {
1963
+ const { name, id } = request.params;
1964
+ const result = await collectionService2.deleteEntry(request, name, id);
1965
+ if (!result) {
1966
+ return reply.status(404).send({ success: false, message: "Entry not found" });
1967
+ }
1968
+ return { success: true, message: "Successfully deleted entry" };
1969
+ } catch (error) {
1970
+ return reply.status(500).send({
1971
+ success: false,
1972
+ message: `Failed to delete entry: ${error.message}`
1973
+ });
1974
+ }
1975
+ }
1976
+ async function searchEntries(request, reply) {
1977
+ try {
1978
+ const { name } = request.params;
1979
+ const { query, filter, top_k } = request.body;
1980
+ if (!query) {
1981
+ return reply.status(400).send({ success: false, message: "query is required" });
1982
+ }
1983
+ const entries = await collectionService2.searchEntries(request, name, {
1984
+ query,
1985
+ filter,
1986
+ top_k
1987
+ });
1988
+ return {
1989
+ success: true,
1990
+ message: "Search completed",
1991
+ data: { records: entries, total: entries.length }
1992
+ };
1993
+ } catch (error) {
1994
+ if (error.message?.includes("not found")) {
1995
+ return reply.status(404).send({ success: false, message: error.message });
1996
+ }
1997
+ return reply.status(500).send({
1998
+ success: false,
1999
+ message: `Search failed: ${error.message}`,
2000
+ data: { records: [], total: 0 }
2001
+ });
2002
+ }
2003
+ }
2004
+
1551
2005
  // src/controllers/tools.ts
1552
2006
  import { toolLatticeManager } from "@axiom-lattice/core";
1553
2007
  function serializeSchema(schema) {
@@ -1635,11 +2089,11 @@ import {
1635
2089
  getStoreLattice as getStoreLattice3,
1636
2090
  metricsServerManager
1637
2091
  } from "@axiom-lattice/core";
1638
- function getTenantId5(request) {
2092
+ function getTenantId6(request) {
1639
2093
  return request.headers["x-tenant-id"] || "default";
1640
2094
  }
1641
2095
  async function executeDataQuery(request, reply) {
1642
- const tenantId = getTenantId5(request);
2096
+ const tenantId = getTenantId6(request);
1643
2097
  const body = request.body;
1644
2098
  try {
1645
2099
  if (!body.serverKey && !body.datasourceId) {
@@ -1696,14 +2150,16 @@ async function executeDataQuery(request, reply) {
1696
2150
  message: "datasourceId is required"
1697
2151
  };
1698
2152
  }
1699
- if (!metricsServerManager.hasServer(tenantId, body.serverKey)) {
2153
+ let client;
2154
+ try {
2155
+ client = await metricsServerManager.getClient(tenantId, body.serverKey);
2156
+ } catch {
1700
2157
  reply.code(400);
1701
2158
  return {
1702
2159
  success: false,
1703
2160
  message: `Metrics server not registered: ${body.serverKey}. Please register the server first.`
1704
2161
  };
1705
2162
  }
1706
- const client = await metricsServerManager.getClient(tenantId, body.serverKey);
1707
2163
  if (isSemanticQuery) {
1708
2164
  return await executeSemanticQuery(client, body, reply);
1709
2165
  } else {
@@ -1773,7 +2229,7 @@ async function executeSqlQuery(client, body, reply) {
1773
2229
  // src/controllers/workflow-tracking.ts
1774
2230
  import { getStoreLattice as getStoreLattice4, agentInstanceManager as agentInstanceManager4, ThreadStatus as ThreadStatus2 } from "@axiom-lattice/core";
1775
2231
  import { MessageChunkTypes as MessageChunkTypes2 } from "@axiom-lattice/protocols";
1776
- function getTenantId6(request) {
2232
+ function getTenantId7(request) {
1777
2233
  const userTenantId = request.user?.tenantId;
1778
2234
  if (userTenantId) return userTenantId;
1779
2235
  return request.headers["x-tenant-id"] || "default";
@@ -1814,7 +2270,7 @@ async function getDefinitionsFromAssistants(tenantId) {
1814
2270
  }
1815
2271
  }
1816
2272
  async function getAllWorkflowDefinitions(request, reply) {
1817
- const tenantId = getTenantId6(request);
2273
+ const tenantId = getTenantId7(request);
1818
2274
  try {
1819
2275
  const configDefs = await getDefinitionsFromAssistants(tenantId);
1820
2276
  if (configDefs.length === 0) {
@@ -1859,7 +2315,7 @@ async function getAllWorkflowDefinitions(request, reply) {
1859
2315
  }
1860
2316
  }
1861
2317
  async function getAllWorkflowRuns(request, reply) {
1862
- const tenantId = getTenantId6(request);
2318
+ const tenantId = getTenantId7(request);
1863
2319
  const { assistantId, status } = request.query;
1864
2320
  try {
1865
2321
  const store = getTrackingStore();
@@ -1911,7 +2367,7 @@ async function getAllWorkflowRuns(request, reply) {
1911
2367
  }
1912
2368
  }
1913
2369
  async function getInboxItems(request, reply) {
1914
- const tenantId = getTenantId6(request);
2370
+ const tenantId = getTenantId7(request);
1915
2371
  try {
1916
2372
  const store = getTrackingStore();
1917
2373
  if (!store) {
@@ -2002,7 +2458,7 @@ async function getInboxItems(request, reply) {
2002
2458
  }
2003
2459
  async function getWorkflowDefinitions(request, reply) {
2004
2460
  const { assistantId } = request.params;
2005
- const tenantId = getTenantId6(request);
2461
+ const tenantId = getTenantId7(request);
2006
2462
  try {
2007
2463
  const store = getTrackingStore();
2008
2464
  if (!store) {
@@ -2033,7 +2489,7 @@ async function getWorkflowDefinitions(request, reply) {
2033
2489
  }
2034
2490
  async function getWorkflowRuns(request, reply) {
2035
2491
  const { threadId } = request.params;
2036
- const tenantId = getTenantId6(request);
2492
+ const tenantId = getTenantId7(request);
2037
2493
  try {
2038
2494
  const store = getTrackingStore();
2039
2495
  if (!store) {
@@ -2069,7 +2525,7 @@ async function getWorkflowRun(request, reply) {
2069
2525
  }
2070
2526
  async function deleteWorkflowRun(request, reply) {
2071
2527
  const { runId } = request.params;
2072
- const tenantId = getTenantId6(request);
2528
+ const tenantId = getTenantId7(request);
2073
2529
  try {
2074
2530
  const store = getTrackingStore();
2075
2531
  if (!store) {
@@ -2152,7 +2608,7 @@ async function getRunTasks(request, reply) {
2152
2608
  }
2153
2609
  async function replyInboxTask(request, reply) {
2154
2610
  const { runId, answers } = request.body;
2155
- const tenantId = getTenantId6(request);
2611
+ const tenantId = getTenantId7(request);
2156
2612
  try {
2157
2613
  const store = getTrackingStore();
2158
2614
  if (!store) {
@@ -2233,7 +2689,7 @@ import { randomUUID as randomUUID3 } from "crypto";
2233
2689
  function getWorkspaceId2(request) {
2234
2690
  return request.headers["x-workspace-id"] || "default";
2235
2691
  }
2236
- function getTenantId7(request) {
2692
+ function getTenantId8(request) {
2237
2693
  const userTenantId = request.user?.tenantId;
2238
2694
  if (userTenantId) return userTenantId;
2239
2695
  return request.headers["x-tenant-id"] || "default";
@@ -2260,7 +2716,7 @@ async function updateLinkMeta(userId, tenantId, meta) {
2260
2716
  await getLinkStore().updateLink(userId, tenantId, { metadata: meta });
2261
2717
  }
2262
2718
  async function createPersonalAssistant(request, reply) {
2263
- const tenantId = getTenantId7(request);
2719
+ const tenantId = getTenantId8(request);
2264
2720
  const userId = getUserId3(request);
2265
2721
  const { name, personality } = request.body;
2266
2722
  if (!name || !personality) {
@@ -2296,7 +2752,7 @@ async function createPersonalAssistant(request, reply) {
2296
2752
  });
2297
2753
  }
2298
2754
  async function getPersonalAssistant(request, reply) {
2299
- const tenantId = getTenantId7(request);
2755
+ const tenantId = getTenantId8(request);
2300
2756
  const userId = getUserId3(request);
2301
2757
  const store = getAssistantStore();
2302
2758
  const assistant = await store.getByOwner(tenantId, userId);
@@ -2313,7 +2769,7 @@ async function getPersonalAssistant(request, reply) {
2313
2769
  };
2314
2770
  }
2315
2771
  async function deletePersonalAssistant(request, reply) {
2316
- const tenantId = getTenantId7(request);
2772
+ const tenantId = getTenantId8(request);
2317
2773
  const userId = getUserId3(request);
2318
2774
  const store = getAssistantStore();
2319
2775
  const assistant = await store.getByOwner(tenantId, userId);
@@ -2350,7 +2806,7 @@ async function deletePersonalAssistant(request, reply) {
2350
2806
 
2351
2807
  // src/controllers/tasks.ts
2352
2808
  import { getStoreLattice as getStoreLattice6 } from "@axiom-lattice/core";
2353
- function getTenantId8(request) {
2809
+ function getTenantId9(request) {
2354
2810
  const userTenantId = request.user?.tenantId;
2355
2811
  if (userTenantId) return userTenantId;
2356
2812
  return request.headers["x-tenant-id"] || "default";
@@ -2365,7 +2821,7 @@ function getStore() {
2365
2821
  }
2366
2822
  async function listTasks(request, reply) {
2367
2823
  try {
2368
- const tenantId = getTenantId8(request);
2824
+ const tenantId = getTenantId9(request);
2369
2825
  const userId = getUserId4(request);
2370
2826
  const query = request.query;
2371
2827
  const store = getStore();
@@ -2386,7 +2842,7 @@ async function listTasks(request, reply) {
2386
2842
  }
2387
2843
  async function getTask(request, reply) {
2388
2844
  try {
2389
- const tenantId = getTenantId8(request);
2845
+ const tenantId = getTenantId9(request);
2390
2846
  const userId = getUserId4(request);
2391
2847
  const { id } = request.params;
2392
2848
  const store = getStore();
@@ -2404,7 +2860,7 @@ async function getTask(request, reply) {
2404
2860
  }
2405
2861
  async function createTask(request, reply) {
2406
2862
  try {
2407
- const tenantId = getTenantId8(request);
2863
+ const tenantId = getTenantId9(request);
2408
2864
  const userId = getUserId4(request);
2409
2865
  const body = request.body;
2410
2866
  if (!body.title) {
@@ -2424,7 +2880,7 @@ async function createTask(request, reply) {
2424
2880
  }
2425
2881
  async function updateTask(request, reply) {
2426
2882
  try {
2427
- const tenantId = getTenantId8(request);
2883
+ const tenantId = getTenantId9(request);
2428
2884
  const userId = getUserId4(request);
2429
2885
  const { id } = request.params;
2430
2886
  const store = getStore();
@@ -2446,7 +2902,7 @@ async function updateTask(request, reply) {
2446
2902
  }
2447
2903
  async function deleteTask(request, reply) {
2448
2904
  try {
2449
- const tenantId = getTenantId8(request);
2905
+ const tenantId = getTenantId9(request);
2450
2906
  const userId = getUserId4(request);
2451
2907
  const { id } = request.params;
2452
2908
  const store = getStore();
@@ -2468,7 +2924,7 @@ async function deleteTask(request, reply) {
2468
2924
  }
2469
2925
  async function completeTask(request, reply) {
2470
2926
  try {
2471
- const tenantId = getTenantId8(request);
2927
+ const tenantId = getTenantId9(request);
2472
2928
  const userId = getUserId4(request);
2473
2929
  const { id } = request.params;
2474
2930
  const store = getStore();
@@ -3159,7 +3615,7 @@ import * as path from "path";
3159
3615
  import { getStoreLattice as getStoreLattice7 } from "@axiom-lattice/core";
3160
3616
  import { SandboxFilesystem, FilesystemBackend } from "@axiom-lattice/core";
3161
3617
  import { getSandBoxManager as getSandBoxManager3 } from "@axiom-lattice/core";
3162
- import { v4 as uuidv4 } from "uuid";
3618
+ import { v4 as uuidv42 } from "uuid";
3163
3619
  var WorkspaceController = class {
3164
3620
  constructor() {
3165
3621
  this.workspaceStore = getStoreLattice7("default", "workspace").store;
@@ -3185,7 +3641,7 @@ var WorkspaceController = class {
3185
3641
  async createWorkspace(request, reply) {
3186
3642
  const tenantId = this.getTenantId(request);
3187
3643
  const data = request.body;
3188
- const id = uuidv4();
3644
+ const id = uuidv42();
3189
3645
  const workspace = await this.workspaceStore.createWorkspace(
3190
3646
  tenantId,
3191
3647
  id,
@@ -3245,7 +3701,7 @@ var WorkspaceController = class {
3245
3701
  const tenantId = this.getTenantId(request);
3246
3702
  const { workspaceId } = request.params;
3247
3703
  const data = request.body;
3248
- const id = uuidv4();
3704
+ const id = uuidv42();
3249
3705
  const project = await this.projectStore.createProject(
3250
3706
  tenantId,
3251
3707
  workspaceId,
@@ -3683,7 +4139,7 @@ import {
3683
4139
  sqlDatabaseManager
3684
4140
  } from "@axiom-lattice/core";
3685
4141
  import { randomUUID as randomUUID4 } from "crypto";
3686
- function getTenantId9(request) {
4142
+ function getTenantId10(request) {
3687
4143
  const userTenantId = request.user?.tenantId;
3688
4144
  if (userTenantId) {
3689
4145
  return userTenantId;
@@ -3691,7 +4147,7 @@ function getTenantId9(request) {
3691
4147
  return request.headers["x-tenant-id"] || "default";
3692
4148
  }
3693
4149
  async function getDatabaseConfigList(request, reply) {
3694
- const tenantId = getTenantId9(request);
4150
+ const tenantId = getTenantId10(request);
3695
4151
  try {
3696
4152
  const storeLattice = getStoreLattice8("default", "database");
3697
4153
  const store = storeLattice.store;
@@ -3721,7 +4177,7 @@ async function getDatabaseConfigList(request, reply) {
3721
4177
  }
3722
4178
  }
3723
4179
  async function getDatabaseConfig(request, reply) {
3724
- const tenantId = getTenantId9(request);
4180
+ const tenantId = getTenantId10(request);
3725
4181
  const { key } = request.params;
3726
4182
  try {
3727
4183
  const storeLattice = getStoreLattice8("default", "database");
@@ -3747,7 +4203,7 @@ async function getDatabaseConfig(request, reply) {
3747
4203
  }
3748
4204
  }
3749
4205
  async function createDatabaseConfig(request, reply) {
3750
- const tenantId = getTenantId9(request);
4206
+ const tenantId = getTenantId10(request);
3751
4207
  const body = request.body;
3752
4208
  try {
3753
4209
  const storeLattice = getStoreLattice8("default", "database");
@@ -3782,7 +4238,7 @@ async function createDatabaseConfig(request, reply) {
3782
4238
  }
3783
4239
  }
3784
4240
  async function updateDatabaseConfig(request, reply) {
3785
- const tenantId = getTenantId9(request);
4241
+ const tenantId = getTenantId10(request);
3786
4242
  const { key } = request.params;
3787
4243
  const updates = request.body;
3788
4244
  try {
@@ -3824,7 +4280,7 @@ async function updateDatabaseConfig(request, reply) {
3824
4280
  }
3825
4281
  }
3826
4282
  async function deleteDatabaseConfig(request, reply) {
3827
- const tenantId = getTenantId9(request);
4283
+ const tenantId = getTenantId10(request);
3828
4284
  const { keyOrId } = request.params;
3829
4285
  try {
3830
4286
  const storeLattice = getStoreLattice8("default", "database");
@@ -3873,7 +4329,7 @@ async function deleteDatabaseConfig(request, reply) {
3873
4329
  }
3874
4330
  }
3875
4331
  async function testDatabaseConnection(request, reply) {
3876
- const tenantId = getTenantId9(request);
4332
+ const tenantId = getTenantId10(request);
3877
4333
  const { key } = request.params;
3878
4334
  try {
3879
4335
  const storeLattice = getStoreLattice8("default", "database");
@@ -3966,7 +4422,7 @@ import {
3966
4422
  SemanticMetricsClient as SemanticMetricsClient2
3967
4423
  } from "@axiom-lattice/core";
3968
4424
  import { randomUUID as randomUUID5 } from "crypto";
3969
- function getTenantId10(request) {
4425
+ function getTenantId11(request) {
3970
4426
  const userTenantId = request.user?.tenantId;
3971
4427
  if (userTenantId) {
3972
4428
  return userTenantId;
@@ -3974,7 +4430,7 @@ function getTenantId10(request) {
3974
4430
  return request.headers["x-tenant-id"] || "default";
3975
4431
  }
3976
4432
  async function getMetricsServerConfigList(request, reply) {
3977
- const tenantId = getTenantId10(request);
4433
+ const tenantId = getTenantId11(request);
3978
4434
  try {
3979
4435
  const storeLattice = getStoreLattice9("default", "metrics");
3980
4436
  const store = storeLattice.store;
@@ -4000,7 +4456,7 @@ async function getMetricsServerConfigList(request, reply) {
4000
4456
  }
4001
4457
  }
4002
4458
  async function getMetricsServerConfig(request, reply) {
4003
- const tenantId = getTenantId10(request);
4459
+ const tenantId = getTenantId11(request);
4004
4460
  const { key } = request.params;
4005
4461
  try {
4006
4462
  const storeLattice = getStoreLattice9("default", "metrics");
@@ -4026,7 +4482,7 @@ async function getMetricsServerConfig(request, reply) {
4026
4482
  }
4027
4483
  }
4028
4484
  async function createMetricsServerConfig(request, reply) {
4029
- const tenantId = getTenantId10(request);
4485
+ const tenantId = getTenantId11(request);
4030
4486
  const body = request.body;
4031
4487
  try {
4032
4488
  const storeLattice = getStoreLattice9("default", "metrics");
@@ -4077,7 +4533,7 @@ async function createMetricsServerConfig(request, reply) {
4077
4533
  }
4078
4534
  }
4079
4535
  async function updateMetricsServerConfig(request, reply) {
4080
- const tenantId = getTenantId10(request);
4536
+ const tenantId = getTenantId11(request);
4081
4537
  const { key } = request.params;
4082
4538
  const updates = request.body;
4083
4539
  try {
@@ -4128,7 +4584,7 @@ async function updateMetricsServerConfig(request, reply) {
4128
4584
  }
4129
4585
  }
4130
4586
  async function deleteMetricsServerConfig(request, reply) {
4131
- const tenantId = getTenantId10(request);
4587
+ const tenantId = getTenantId11(request);
4132
4588
  const { keyOrId } = request.params;
4133
4589
  try {
4134
4590
  const storeLattice = getStoreLattice9("default", "metrics");
@@ -4175,7 +4631,7 @@ async function deleteMetricsServerConfig(request, reply) {
4175
4631
  }
4176
4632
  }
4177
4633
  async function testMetricsServerConnection(request, reply) {
4178
- const tenantId = getTenantId10(request);
4634
+ const tenantId = getTenantId11(request);
4179
4635
  const { key } = request.params;
4180
4636
  try {
4181
4637
  const storeLattice = getStoreLattice9("default", "metrics");
@@ -4226,7 +4682,7 @@ async function testMetricsServerConnection(request, reply) {
4226
4682
  }
4227
4683
  }
4228
4684
  async function listAvailableMetrics(request, reply) {
4229
- const tenantId = getTenantId10(request);
4685
+ const tenantId = getTenantId11(request);
4230
4686
  const { key } = request.params;
4231
4687
  try {
4232
4688
  const storeLattice = getStoreLattice9("default", "metrics");
@@ -4264,7 +4720,7 @@ async function listAvailableMetrics(request, reply) {
4264
4720
  }
4265
4721
  }
4266
4722
  async function queryMetricsData(request, reply) {
4267
- const tenantId = getTenantId10(request);
4723
+ const tenantId = getTenantId11(request);
4268
4724
  const { key } = request.params;
4269
4725
  const { metricName, startTime, endTime, step, labels } = request.body;
4270
4726
  try {
@@ -4312,7 +4768,7 @@ async function queryMetricsData(request, reply) {
4312
4768
  }
4313
4769
  }
4314
4770
  async function getDataSources(request, reply) {
4315
- const tenantId = getTenantId10(request);
4771
+ const tenantId = getTenantId11(request);
4316
4772
  const { key } = request.params;
4317
4773
  try {
4318
4774
  const storeLattice = getStoreLattice9("default", "metrics");
@@ -4353,7 +4809,7 @@ async function getDataSources(request, reply) {
4353
4809
  }
4354
4810
  }
4355
4811
  async function getDatasourceMetrics(request, reply) {
4356
- const tenantId = getTenantId10(request);
4812
+ const tenantId = getTenantId11(request);
4357
4813
  const { key, datasourceId } = request.params;
4358
4814
  try {
4359
4815
  const storeLattice = getStoreLattice9("default", "metrics");
@@ -4390,7 +4846,7 @@ async function getDatasourceMetrics(request, reply) {
4390
4846
  }
4391
4847
  }
4392
4848
  async function querySemanticMetrics(request, reply) {
4393
- const tenantId = getTenantId10(request);
4849
+ const tenantId = getTenantId11(request);
4394
4850
  const { key } = request.params;
4395
4851
  const body = request.body;
4396
4852
  try {
@@ -4546,448 +5002,15 @@ function registerMetricsServerConfigRoutes(app2) {
4546
5002
  app2.post("/api/metrics-configs/test-datasources/:datasourceId/meta", testDatasourceMetrics);
4547
5003
  }
4548
5004
 
4549
- // src/controllers/mcp-configs.ts
4550
- import {
4551
- getStoreLattice as getStoreLattice10,
4552
- mcpManager,
4553
- toolLatticeManager as toolLatticeManager2
4554
- } from "@axiom-lattice/core";
4555
- import { randomUUID as randomUUID6 } from "crypto";
4556
- function getTenantId11(request) {
4557
- const userTenantId = request.user?.tenantId;
4558
- if (userTenantId) {
4559
- return userTenantId;
4560
- }
4561
- return request.headers["x-tenant-id"] || "default";
4562
- }
4563
- async function getMcpServerConfigList(request, reply) {
4564
- const tenantId = getTenantId11(request);
4565
- try {
4566
- const storeLattice = getStoreLattice10("default", "mcp");
4567
- const store = storeLattice.store;
4568
- const configs = await store.getAllConfigs(tenantId);
4569
- return {
4570
- success: true,
4571
- message: "MCP server configurations retrieved successfully",
4572
- data: {
4573
- records: configs,
4574
- total: configs.length
4575
- }
4576
- };
4577
- } catch (error) {
4578
- console.error("Failed to get MCP server configs:", error);
4579
- return {
4580
- success: false,
4581
- message: "Failed to retrieve MCP server configurations",
4582
- data: {
4583
- records: [],
4584
- total: 0
4585
- }
4586
- };
4587
- }
4588
- }
4589
- async function getMcpServerConfig(request, reply) {
4590
- const tenantId = getTenantId11(request);
4591
- const { key } = request.params;
4592
- try {
4593
- const storeLattice = getStoreLattice10("default", "mcp");
4594
- const store = storeLattice.store;
4595
- const config = await store.getConfigByKey(tenantId, key);
4596
- if (!config) {
4597
- return {
4598
- success: false,
4599
- message: "MCP server configuration not found"
4600
- };
4601
- }
4602
- return {
4603
- success: true,
4604
- message: "MCP server configuration retrieved successfully",
4605
- data: config
4606
- };
4607
- } catch (error) {
4608
- console.error("Failed to get MCP server config:", error);
4609
- return {
4610
- success: false,
4611
- message: "Failed to retrieve MCP server configuration"
4612
- };
4613
- }
4614
- }
4615
- async function createMcpServerConfig(request, reply) {
4616
- const tenantId = getTenantId11(request);
4617
- const body = request.body;
4618
- try {
4619
- const storeLattice = getStoreLattice10("default", "mcp");
4620
- const store = storeLattice.store;
4621
- const existing = await store.getConfigByKey(tenantId, body.key);
4622
- if (existing) {
4623
- reply.code(409);
4624
- return {
4625
- success: false,
4626
- message: "MCP server configuration with this key already exists"
4627
- };
4628
- }
4629
- const id = body.id || randomUUID6();
4630
- const config = await store.createConfig(tenantId, id, body);
4631
- try {
4632
- await connectAndRegisterTools(config);
4633
- await store.updateConfig(tenantId, id, { status: "connected" });
4634
- config.status = "connected";
4635
- } catch (error) {
4636
- console.warn("Failed to auto-connect MCP server:", error);
4637
- await store.updateConfig(tenantId, id, { status: "error" });
4638
- config.status = "error";
4639
- }
4640
- reply.code(201);
4641
- return {
4642
- success: true,
4643
- message: "MCP server configuration created successfully",
4644
- data: config
4645
- };
4646
- } catch (error) {
4647
- console.error("Failed to create MCP server config:", error);
4648
- return {
4649
- success: false,
4650
- message: "Failed to create MCP server configuration"
4651
- };
4652
- }
4653
- }
4654
- async function updateMcpServerConfig(request, reply) {
4655
- const tenantId = getTenantId11(request);
4656
- const { key } = request.params;
4657
- const updates = request.body;
4658
- try {
4659
- const storeLattice = getStoreLattice10("default", "mcp");
4660
- const store = storeLattice.store;
4661
- const existing = await store.getConfigByKey(tenantId, key);
4662
- if (!existing) {
4663
- reply.code(404);
4664
- return {
4665
- success: false,
4666
- message: "MCP server configuration not found"
4667
- };
4668
- }
4669
- const shouldReconnect = updates.config !== void 0;
4670
- const updated = await store.updateConfig(tenantId, existing.id, updates);
4671
- if (!updated) {
4672
- return {
4673
- success: false,
4674
- message: "Failed to update MCP server configuration"
4675
- };
4676
- }
4677
- if (shouldReconnect) {
4678
- try {
4679
- if (mcpManager.hasServer(key)) {
4680
- await mcpManager.removeServer(key);
4681
- }
4682
- await connectAndRegisterTools(updated);
4683
- await store.updateConfig(tenantId, existing.id, { status: "connected" });
4684
- updated.status = "connected";
4685
- } catch (error) {
4686
- console.warn("Failed to reconnect MCP server:", error);
4687
- await store.updateConfig(tenantId, existing.id, { status: "error" });
4688
- updated.status = "error";
4689
- }
4690
- }
4691
- return {
4692
- success: true,
4693
- message: "MCP server configuration updated successfully",
4694
- data: updated
4695
- };
4696
- } catch (error) {
4697
- console.error("Failed to update MCP server config:", error);
4698
- return {
4699
- success: false,
4700
- message: "Failed to update MCP server configuration"
4701
- };
4702
- }
4703
- }
4704
- async function deleteMcpServerConfig(request, reply) {
4705
- const tenantId = getTenantId11(request);
4706
- const { keyOrId } = request.params;
4707
- try {
4708
- const storeLattice = getStoreLattice10("default", "mcp");
4709
- const store = storeLattice.store;
4710
- let config = await store.getConfigByKey(tenantId, keyOrId);
4711
- let configKey = keyOrId;
4712
- if (!config) {
4713
- config = await store.getConfigById(tenantId, keyOrId);
4714
- if (config) {
4715
- configKey = config.key;
4716
- }
4717
- }
4718
- if (!config) {
4719
- reply.code(404);
4720
- return {
4721
- success: false,
4722
- message: "MCP server configuration not found"
4723
- };
4724
- }
4725
- try {
4726
- if (mcpManager.hasServer(configKey)) {
4727
- await mcpManager.removeServer(configKey);
4728
- }
4729
- } catch (error) {
4730
- console.warn("Failed to remove from MCP manager:", error);
4731
- }
4732
- const deleted = await store.deleteConfig(tenantId, config.id);
4733
- if (!deleted) {
4734
- return {
4735
- success: false,
4736
- message: "Failed to delete MCP server configuration"
4737
- };
4738
- }
4739
- return {
4740
- success: true,
4741
- message: "MCP server configuration deleted successfully"
4742
- };
4743
- } catch (error) {
4744
- console.error("Failed to delete MCP server config:", error);
4745
- return {
4746
- success: false,
4747
- message: "Failed to delete MCP server configuration"
4748
- };
4749
- }
4750
- }
4751
- async function testMcpServerConnection(request, reply) {
4752
- const tenantId = getTenantId11(request);
4753
- const { key } = request.params;
4754
- try {
4755
- const storeLattice = getStoreLattice10("default", "mcp");
4756
- const store = storeLattice.store;
4757
- const config = await store.getConfigByKey(tenantId, key);
4758
- if (!config) {
4759
- reply.code(404);
4760
- return {
4761
- success: false,
4762
- message: "MCP server configuration not found"
4763
- };
4764
- }
4765
- const startTime = Date.now();
4766
- try {
4767
- const testKey = `__test_${key}_${Date.now()}`;
4768
- const connection = convertToConnection(config.config);
4769
- mcpManager.addServer(testKey, connection);
4770
- await mcpManager.connect();
4771
- const tools = await mcpManager.getAllTools();
4772
- const latency = Date.now() - startTime;
4773
- await mcpManager.removeServer(testKey);
4774
- return {
4775
- success: true,
4776
- message: "Connection test successful",
4777
- data: {
4778
- connected: true,
4779
- latency
4780
- }
4781
- };
4782
- } catch (error) {
4783
- return {
4784
- success: true,
4785
- message: "Connection test failed",
4786
- data: {
4787
- connected: false,
4788
- error: error instanceof Error ? error.message : "Unknown error"
4789
- }
4790
- };
4791
- }
4792
- } catch (error) {
4793
- console.error("Failed to test MCP server connection:", error);
4794
- return {
4795
- success: false,
4796
- message: "Failed to test MCP server connection",
4797
- data: {
4798
- connected: false,
4799
- error: error instanceof Error ? error.message : "Unknown error"
4800
- }
4801
- };
4802
- }
4803
- }
4804
- async function listMcpServerTools(request, reply) {
4805
- const tenantId = getTenantId11(request);
4806
- const { key } = request.params;
4807
- try {
4808
- const storeLattice = getStoreLattice10("default", "mcp");
4809
- const store = storeLattice.store;
4810
- const config = await store.getConfigByKey(tenantId, key);
4811
- if (!config) {
4812
- reply.code(404);
4813
- return {
4814
- success: false,
4815
- message: "MCP server configuration not found"
4816
- };
4817
- }
4818
- if (!mcpManager.hasServer(key)) {
4819
- await connectAndRegisterTools(config);
4820
- }
4821
- const tools = await mcpManager.getAllTools();
4822
- return {
4823
- success: true,
4824
- message: "Tools retrieved successfully",
4825
- data: {
4826
- tools
4827
- }
4828
- };
4829
- } catch (error) {
4830
- console.error("Failed to list MCP tools:", error);
4831
- return {
4832
- success: false,
4833
- message: "Failed to retrieve tools"
4834
- };
4835
- }
4836
- }
4837
- async function connectMcpServer(request, reply) {
4838
- const tenantId = getTenantId11(request);
4839
- const { key } = request.params;
4840
- try {
4841
- const storeLattice = getStoreLattice10("default", "mcp");
4842
- const store = storeLattice.store;
4843
- const config = await store.getConfigByKey(tenantId, key);
4844
- if (!config) {
4845
- reply.code(404);
4846
- return {
4847
- success: false,
4848
- message: "MCP server configuration not found"
4849
- };
4850
- }
4851
- await connectAndRegisterTools(config);
4852
- const updated = await store.updateConfig(tenantId, config.id, {
4853
- status: "connected"
4854
- });
4855
- return {
4856
- success: true,
4857
- message: "MCP server connected successfully",
4858
- data: updated || config
4859
- };
4860
- } catch (error) {
4861
- console.error("Failed to connect MCP server:", error);
4862
- const storeLattice = getStoreLattice10("default", "mcp");
4863
- const store = storeLattice.store;
4864
- const config = await store.getConfigByKey(tenantId, key);
4865
- if (config) {
4866
- await store.updateConfig(tenantId, config.id, { status: "error" });
4867
- }
4868
- return {
4869
- success: false,
4870
- message: `Failed to connect MCP server: ${error instanceof Error ? error.message : "Unknown error"}`
4871
- };
4872
- }
4873
- }
4874
- async function disconnectMcpServer(request, reply) {
4875
- const tenantId = getTenantId11(request);
4876
- const { key } = request.params;
4877
- try {
4878
- const storeLattice = getStoreLattice10("default", "mcp");
4879
- const store = storeLattice.store;
4880
- const config = await store.getConfigByKey(tenantId, key);
4881
- if (!config) {
4882
- reply.code(404);
4883
- return {
4884
- success: false,
4885
- message: "MCP server configuration not found"
4886
- };
4887
- }
4888
- if (mcpManager.hasServer(key)) {
4889
- await mcpManager.removeServer(key);
4890
- }
4891
- const updated = await store.updateConfig(tenantId, config.id, {
4892
- status: "disconnected"
4893
- });
4894
- return {
4895
- success: true,
4896
- message: "MCP server disconnected successfully",
4897
- data: updated || config
4898
- };
4899
- } catch (error) {
4900
- console.error("Failed to disconnect MCP server:", error);
4901
- return {
4902
- success: false,
4903
- message: "Failed to disconnect MCP server"
4904
- };
4905
- }
4906
- }
4907
- async function testMcpServerTools(request, reply) {
4908
- const body = request.body;
4909
- try {
4910
- if (!body.config) {
4911
- reply.code(400);
4912
- return {
4913
- success: false,
4914
- message: "config is required"
4915
- };
4916
- }
4917
- const testKey = `__test_${Date.now()}`;
4918
- const connection = convertToConnection(body.config);
4919
- mcpManager.addServer(testKey, connection);
4920
- await mcpManager.connect();
4921
- const tools = await mcpManager.getAllTools();
4922
- await mcpManager.removeServer(testKey);
4923
- return {
4924
- success: true,
4925
- message: "Tools retrieved successfully",
4926
- data: {
4927
- tools
4928
- }
4929
- };
4930
- } catch (error) {
4931
- console.error("Failed to test MCP server tools:", error);
4932
- return {
4933
- success: false,
4934
- message: `Failed to retrieve tools: ${error instanceof Error ? error.message : String(error)}`
4935
- };
4936
- }
4937
- }
4938
- function convertToConnection(config) {
4939
- const baseConfig = {
4940
- env: config.env
4941
- };
4942
- if (config.transport === "stdio") {
4943
- return {
4944
- ...baseConfig,
4945
- transport: "stdio",
4946
- command: config.command,
4947
- args: config.args || []
4948
- };
4949
- } else {
4950
- return {
4951
- ...baseConfig,
4952
- transport: config.transport === "streamable_http" ? "http" : config.transport,
4953
- url: config.url
4954
- };
4955
- }
4956
- }
4957
- async function connectAndRegisterTools(config) {
4958
- const connection = convertToConnection(config.config);
4959
- mcpManager.addServer(config.key, connection);
4960
- await mcpManager.connect();
4961
- const allTools = await mcpManager.getAllTools();
4962
- const selectedTools = allTools.filter(
4963
- (tool) => config.selectedTools.includes(tool.name)
4964
- );
4965
- for (const tool of selectedTools) {
4966
- toolLatticeManager2.registerExistingTool(tool.name, tool);
4967
- }
4968
- }
4969
- function registerMcpServerConfigRoutes(app2) {
4970
- app2.get("/api/mcp-servers", getMcpServerConfigList);
4971
- app2.get("/api/mcp-servers/:key", getMcpServerConfig);
4972
- app2.post("/api/mcp-servers", createMcpServerConfig);
4973
- app2.put("/api/mcp-servers/:key", updateMcpServerConfig);
4974
- app2.delete("/api/mcp-servers/:keyOrId", deleteMcpServerConfig);
4975
- app2.post("/api/mcp-servers/:key/test", testMcpServerConnection);
4976
- app2.get("/api/mcp-servers/:key/tools", listMcpServerTools);
4977
- app2.post("/api/mcp-servers/:key/connect", connectMcpServer);
4978
- app2.post("/api/mcp-servers/:key/disconnect", disconnectMcpServer);
4979
- app2.post("/api/mcp-servers/test-tools", testMcpServerTools);
4980
- }
4981
-
4982
5005
  // src/controllers/eval.ts
4983
- import { getStoreLattice as getStoreLattice12 } from "@axiom-lattice/core";
4984
- import { v4 as uuidv43 } from "uuid";
5006
+ import { getStoreLattice as getStoreLattice11 } from "@axiom-lattice/core";
5007
+ import { v4 as uuidv44 } from "uuid";
4985
5008
 
4986
5009
  // src/services/eval-runner.ts
4987
5010
  import { EventEmitter } from "events";
4988
- import { getStoreLattice as getStoreLattice11, modelLatticeManager as modelLatticeManager2 } from "@axiom-lattice/core";
5011
+ import { getStoreLattice as getStoreLattice10, modelLatticeManager as modelLatticeManager2 } from "@axiom-lattice/core";
4989
5012
  import { LatticeEvalProject } from "@axiom-lattice/agent-eval";
4990
- import { v4 as uuidv42 } from "uuid";
5013
+ import { v4 as uuidv43 } from "uuid";
4991
5014
  function mapLogs(logs) {
4992
5015
  return logs.map((l) => ({
4993
5016
  timestamp: l.ts,
@@ -5036,7 +5059,7 @@ var EvalRunner = class {
5036
5059
  }))
5037
5060
  });
5038
5061
  }
5039
- const runId = uuidv42();
5062
+ const runId = uuidv43();
5040
5063
  const concurrency = project.concurrency || 3;
5041
5064
  await store.createRun(tenantId, projectId, runId, { totalCases, concurrency });
5042
5065
  const judgeCfg = project.judgeModelConfig;
@@ -5078,7 +5101,7 @@ var EvalRunner = class {
5078
5101
  else stats.failed++;
5079
5102
  stats.totalScore += score;
5080
5103
  const completedCount = stats.passed + stats.failed;
5081
- await store.createRunResult(tenantId, runId, uuidv42(), {
5104
+ await store.createRunResult(tenantId, runId, uuidv43(), {
5082
5105
  suiteName,
5083
5106
  caseId: result.caseId,
5084
5107
  pass: passed,
@@ -5158,7 +5181,7 @@ var EvalRunner = class {
5158
5181
  return this.runs.has(runId);
5159
5182
  }
5160
5183
  getEvalStore() {
5161
- return getStoreLattice11("default", "eval").store;
5184
+ return getStoreLattice10("default", "eval").store;
5162
5185
  }
5163
5186
  };
5164
5187
  var evalRunner = new EvalRunner();
@@ -5172,13 +5195,13 @@ function getTenantId12(request) {
5172
5195
  return request.headers["x-tenant-id"] || "default";
5173
5196
  }
5174
5197
  function getEvalStore() {
5175
- return getStoreLattice12("default", "eval").store;
5198
+ return getStoreLattice11("default", "eval").store;
5176
5199
  }
5177
5200
  async function createProject(request, reply) {
5178
5201
  try {
5179
5202
  const tenantId = getTenantId12(request);
5180
5203
  const store = getEvalStore();
5181
- const id = uuidv43();
5204
+ const id = uuidv44();
5182
5205
  const data = request.body;
5183
5206
  const project = await store.createProject(tenantId, id, {
5184
5207
  name: data.name,
@@ -5212,7 +5235,7 @@ async function listProjects(request, reply) {
5212
5235
  const judgeModel = first ? { modelKey: first.key } : { provider: "openai", model: "gpt-4" };
5213
5236
  const host = request.hostname || "localhost";
5214
5237
  const baseUrl = `http://${host}:${process.env.PORT || 4001}`;
5215
- await store.createProject(tenantId, uuidv43(), {
5238
+ await store.createProject(tenantId, uuidv44(), {
5216
5239
  name: "Default",
5217
5240
  description: "Built-in project for testing eval against this server",
5218
5241
  judgeModelConfig: judgeModel,
@@ -5301,7 +5324,7 @@ async function createSuite(request, reply) {
5301
5324
  if (!project) {
5302
5325
  return reply.status(404).send({ success: false, message: "Project not found" });
5303
5326
  }
5304
- const id = uuidv43();
5327
+ const id = uuidv44();
5305
5328
  const data = request.body;
5306
5329
  const suite = await store.createSuite(tenantId, pid, id, { name: data.name });
5307
5330
  return reply.status(201).send({
@@ -5362,7 +5385,7 @@ async function createCase(request, reply) {
5362
5385
  if (!suite) {
5363
5386
  return reply.status(404).send({ success: false, message: "Suite not found" });
5364
5387
  }
5365
- const id = uuidv43();
5388
+ const id = uuidv44();
5366
5389
  const data = request.body;
5367
5390
  const created = await store.createCase(tenantId, sid, id, {
5368
5391
  inputMessage: data.inputMessage,
@@ -5558,11 +5581,11 @@ data: ${JSON.stringify(event.data)}
5558
5581
  }
5559
5582
 
5560
5583
  // src/controllers/users.ts
5561
- import { getStoreLattice as getStoreLattice13 } from "@axiom-lattice/core";
5562
- import { v4 as uuidv44 } from "uuid";
5584
+ import { getStoreLattice as getStoreLattice12 } from "@axiom-lattice/core";
5585
+ import { v4 as uuidv45 } from "uuid";
5563
5586
  var UsersController = class {
5564
5587
  constructor() {
5565
- this.userStore = getStoreLattice13("default", "user").store;
5588
+ this.userStore = getStoreLattice12("default", "user").store;
5566
5589
  }
5567
5590
  async listUsers(request, reply) {
5568
5591
  const { email } = request.query;
@@ -5575,7 +5598,7 @@ var UsersController = class {
5575
5598
  }
5576
5599
  async createUser(request, reply) {
5577
5600
  const data = request.body;
5578
- const id = uuidv44();
5601
+ const id = uuidv45();
5579
5602
  const existingUser = await this.userStore.getUserByEmail(data.email);
5580
5603
  if (existingUser) {
5581
5604
  return reply.status(409).send({
@@ -5640,11 +5663,11 @@ function registerUserRoutes(app2) {
5640
5663
  }
5641
5664
 
5642
5665
  // src/controllers/tenants.ts
5643
- import { getStoreLattice as getStoreLattice14 } from "@axiom-lattice/core";
5644
- import { v4 as uuidv45 } from "uuid";
5666
+ import { getStoreLattice as getStoreLattice13 } from "@axiom-lattice/core";
5667
+ import { v4 as uuidv46 } from "uuid";
5645
5668
  var TenantsController = class {
5646
5669
  constructor() {
5647
- this.tenantStore = getStoreLattice14("default", "tenant").store;
5670
+ this.tenantStore = getStoreLattice13("default", "tenant").store;
5648
5671
  }
5649
5672
  // ==================== Tenant CRUD ====================
5650
5673
  async listTenants(request, reply) {
@@ -5653,7 +5676,7 @@ var TenantsController = class {
5653
5676
  }
5654
5677
  async createTenant(request, reply) {
5655
5678
  const data = request.body;
5656
- const id = uuidv45();
5679
+ const id = uuidv46();
5657
5680
  const tenant = await this.tenantStore.createTenant(id, data);
5658
5681
  return reply.status(201).send({ success: true, data: tenant });
5659
5682
  }
@@ -5708,8 +5731,8 @@ function registerTenantRoutes(app2) {
5708
5731
  }
5709
5732
 
5710
5733
  // src/controllers/auth.ts
5711
- import { getStoreLattice as getStoreLattice15 } from "@axiom-lattice/core";
5712
- import { v4 as uuidv46 } from "uuid";
5734
+ import { getStoreLattice as getStoreLattice14 } from "@axiom-lattice/core";
5735
+ import { v4 as uuidv47 } from "uuid";
5713
5736
  var defaultAuthConfig = {
5714
5737
  autoApproveUsers: true,
5715
5738
  allowTenantRegistration: true,
@@ -5717,9 +5740,9 @@ var defaultAuthConfig = {
5717
5740
  };
5718
5741
  var AuthController = class {
5719
5742
  constructor(config = {}) {
5720
- this.userStore = getStoreLattice15("default", "user").store;
5721
- this.tenantStore = getStoreLattice15("default", "tenant").store;
5722
- this.userTenantLinkStore = getStoreLattice15("default", "userTenantLink").store;
5743
+ this.userStore = getStoreLattice14("default", "user").store;
5744
+ this.tenantStore = getStoreLattice14("default", "tenant").store;
5745
+ this.userTenantLinkStore = getStoreLattice14("default", "userTenantLink").store;
5723
5746
  this.config = { ...defaultAuthConfig, ...config };
5724
5747
  }
5725
5748
  async register(request, reply) {
@@ -5732,7 +5755,7 @@ var AuthController = class {
5732
5755
  error: "User with this email already exists"
5733
5756
  });
5734
5757
  }
5735
- const userId = uuidv46();
5758
+ const userId = uuidv47();
5736
5759
  const userStatus = this.config.autoApproveUsers ? "active" : "pending";
5737
5760
  const userData = {
5738
5761
  email,
@@ -5875,6 +5898,18 @@ var AuthController = class {
5875
5898
  const token = await this.generateToken(userId, tenantId);
5876
5899
  const link = await this.userTenantLinkStore.getLink(userId, tenantId);
5877
5900
  const linkMeta = link?.metadata || {};
5901
+ let personalAssistant = null;
5902
+ if (linkMeta.personalAssistantId) {
5903
+ const assistantStore = getStoreLattice14("default", "assistant").store;
5904
+ const exists = await assistantStore.hasAssistant(tenantId, linkMeta.personalAssistantId);
5905
+ if (exists) {
5906
+ personalAssistant = {
5907
+ assistantId: linkMeta.personalAssistantId,
5908
+ projectId: linkMeta.personalProjectId || "default",
5909
+ workspaceId: linkMeta.personalWorkspaceId || "default"
5910
+ };
5911
+ }
5912
+ }
5878
5913
  return {
5879
5914
  success: true,
5880
5915
  data: {
@@ -5884,11 +5919,7 @@ var AuthController = class {
5884
5919
  status: tenant.status
5885
5920
  },
5886
5921
  token,
5887
- personalAssistant: linkMeta.personalAssistantId ? {
5888
- assistantId: linkMeta.personalAssistantId,
5889
- projectId: linkMeta.personalProjectId || "default",
5890
- workspaceId: linkMeta.personalWorkspaceId || "default"
5891
- } : null
5922
+ personalAssistant
5892
5923
  }
5893
5924
  };
5894
5925
  } catch (error) {
@@ -6416,7 +6447,7 @@ function registerChannelRoutes(app2, dependencies) {
6416
6447
  }
6417
6448
 
6418
6449
  // src/controllers/channel-installations.ts
6419
- import { randomUUID as randomUUID7 } from "crypto";
6450
+ import { randomUUID as randomUUID6 } from "crypto";
6420
6451
  var _adapterRegistry;
6421
6452
  var _router;
6422
6453
  function setChannelControllerDeps(deps) {
@@ -6431,8 +6462,8 @@ function getTenantId13(request) {
6431
6462
  return request.headers["x-tenant-id"] || "default";
6432
6463
  }
6433
6464
  async function getInstallationStore() {
6434
- const { getStoreLattice: getStoreLattice18 } = await import("@axiom-lattice/core");
6435
- const store = getStoreLattice18("default", "channelInstallation").store;
6465
+ const { getStoreLattice: getStoreLattice17 } = await import("@axiom-lattice/core");
6466
+ const store = getStoreLattice17("default", "channelInstallation").store;
6436
6467
  if (store) return store;
6437
6468
  const { PostgreSQLChannelInstallationStore } = await import("@axiom-lattice/pg-stores");
6438
6469
  const databaseUrl = process.env.DATABASE_URL;
@@ -6538,7 +6569,7 @@ async function createChannelInstallation(request, reply) {
6538
6569
  }
6539
6570
  }
6540
6571
  const store = await getInstallationStore();
6541
- const installationId = body.id || randomUUID7();
6572
+ const installationId = body.id || randomUUID6();
6542
6573
  const installation = await store.createInstallation(
6543
6574
  tenantId,
6544
6575
  installationId,
@@ -7202,6 +7233,18 @@ var registerLatticeRoutes = (app2, channelDeps) => {
7202
7233
  "/api/skills/filter/license",
7203
7234
  filterSkillsByLicense
7204
7235
  );
7236
+ app2.get("/api/collections", getCollectionList);
7237
+ app2.get("/api/collections/:name", getCollection);
7238
+ app2.post("/api/collections", createCollection);
7239
+ app2.put("/api/collections/:name", updateCollection);
7240
+ app2.delete("/api/collections/:name", deleteCollection);
7241
+ app2.get("/api/embeddings", listEmbeddings);
7242
+ app2.get("/api/collections/:name/entries", listEntries);
7243
+ app2.post("/api/collections/:name/entries", createEntry);
7244
+ app2.get("/api/collections/:name/entries/:id", getEntry);
7245
+ app2.put("/api/collections/:name/entries/:id", updateEntry);
7246
+ app2.delete("/api/collections/:name/entries/:id", deleteEntry);
7247
+ app2.post("/api/collections/:name/search", searchEntries);
7205
7248
  registerSandboxProxyRoutes(app2);
7206
7249
  registerEvalRoutes(app2);
7207
7250
  registerWorkspaceRoutes(app2);
@@ -7317,10 +7360,10 @@ function registerResourceRoutes(app2, controller) {
7317
7360
 
7318
7361
  // src/router/MessageRouter.ts
7319
7362
  import {
7320
- getStoreLattice as getStoreLattice16,
7363
+ getStoreLattice as getStoreLattice15,
7321
7364
  agentInstanceManager as agentInstanceManager6
7322
7365
  } from "@axiom-lattice/core";
7323
- import { randomUUID as randomUUID8 } from "crypto";
7366
+ import { randomUUID as randomUUID7 } from "crypto";
7324
7367
  var BindingNotFoundError = class extends Error {
7325
7368
  constructor(message) {
7326
7369
  super(message);
@@ -7480,7 +7523,7 @@ var MessageRouter = class {
7480
7523
  channel: message.channel,
7481
7524
  adapterChannel: adapter.channel
7482
7525
  }, "Thread resolved by adapter strategy");
7483
- const threadStore = getStoreLattice16("default", "thread").store;
7526
+ const threadStore = getStoreLattice15("default", "thread").store;
7484
7527
  try {
7485
7528
  await threadStore.createThread(
7486
7529
  tenantId,
@@ -7517,8 +7560,8 @@ var MessageRouter = class {
7517
7560
  }
7518
7561
  }
7519
7562
  if (!threadId) {
7520
- const threadStore = getStoreLattice16("default", "thread").store;
7521
- const newThreadId = randomUUID8();
7563
+ const threadStore = getStoreLattice15("default", "thread").store;
7564
+ const newThreadId = randomUUID7();
7522
7565
  console.log({
7523
7566
  event: "dispatch:thread:create",
7524
7567
  agentId,
@@ -8123,10 +8166,11 @@ import {
8123
8166
  getLoggerLattice,
8124
8167
  loggerLatticeManager,
8125
8168
  sandboxLatticeManager as sandboxLatticeManager2,
8126
- getStoreLattice as getStoreLattice17,
8169
+ getStoreLattice as getStoreLattice16,
8127
8170
  agentInstanceManager as agentInstanceManager8,
8128
8171
  createSandboxProvider,
8129
- TokenCache
8172
+ TokenCache,
8173
+ mcpManager
8130
8174
  } from "@axiom-lattice/core";
8131
8175
  import {
8132
8176
  LoggerType
@@ -8187,7 +8231,7 @@ app.addHook("preHandler", async (request, reply) => {
8187
8231
  if (PUBLIC_ROUTES.some((r) => request.url === r)) return;
8188
8232
  if (request.url.startsWith("/s/")) return;
8189
8233
  const urlPath = request.url.split("?")[0];
8190
- if (urlPath.includes("/viewfile") || urlPath.includes("/downloadfile")) return;
8234
+ if (urlPath.includes("/viewfile") || urlPath.includes("/downloadfile") || urlPath.includes("/uploadfile")) return;
8191
8235
  return reply.status(401).send({
8192
8236
  success: false,
8193
8237
  error: "Unauthorized - Missing or invalid token"
@@ -8274,6 +8318,41 @@ function getConfiguredSandboxProvider() {
8274
8318
  daytonaVolumeName: process.env.DAYTONA_VOLUME_NAME
8275
8319
  });
8276
8320
  }
8321
+ async function restoreMcpConnections() {
8322
+ try {
8323
+ const storeLattice = getStoreLattice16("default", "mcp");
8324
+ const store = storeLattice.store;
8325
+ if (!store) {
8326
+ logger4.info("MCP store not configured, skipping connection restoration");
8327
+ return;
8328
+ }
8329
+ const configs = await store.getAllConfigs("default");
8330
+ const connectedConfigs = configs.filter((c) => c.status === "connected");
8331
+ if (connectedConfigs.length === 0) return;
8332
+ logger4.info(`Restoring ${connectedConfigs.length} MCP server connections...`);
8333
+ const { convertToConnection } = await import("./mcp-configs-SHRMQHIL.mjs");
8334
+ for (const config of connectedConfigs) {
8335
+ try {
8336
+ const connection = convertToConnection(config.config);
8337
+ mcpManager.addServer(config.key, connection);
8338
+ } catch (err) {
8339
+ logger4.warn(`Failed to prepare MCP server "${config.key}" for restoration`, { error: err });
8340
+ }
8341
+ }
8342
+ await mcpManager.connect();
8343
+ for (const config of connectedConfigs) {
8344
+ try {
8345
+ await mcpManager.registerToolsToToolLattice(config.key, config.selectedTools);
8346
+ logger4.info(`MCP server "${config.key}" restored with ${config.selectedTools.length} tools`);
8347
+ } catch (err) {
8348
+ logger4.warn(`Failed to register tools for MCP server "${config.key}"`, { error: err });
8349
+ }
8350
+ }
8351
+ logger4.info(`MCP connection restoration complete: ${connectedConfigs.length} servers`);
8352
+ } catch (err) {
8353
+ logger4.error("MCP connection restoration failed", { error: err });
8354
+ }
8355
+ }
8277
8356
  var start = async (config) => {
8278
8357
  try {
8279
8358
  if (config?.loggerConfig) {
@@ -8322,7 +8401,7 @@ var start = async (config) => {
8322
8401
  });
8323
8402
  }
8324
8403
  try {
8325
- const menuStore = getStoreLattice17("default", "menu").store;
8404
+ const menuStore = getStoreLattice16("default", "menu").store;
8326
8405
  setMenuRegistry(menuStore);
8327
8406
  logger4.info("Menu registry initialized");
8328
8407
  } catch {
@@ -8336,8 +8415,8 @@ var start = async (config) => {
8336
8415
  logger4.info("Registered sandbox manager from env configuration");
8337
8416
  }
8338
8417
  try {
8339
- const { ResourceController } = await import("./resources-HEVGN3JM.mjs");
8340
- const sharedResourceStore = getStoreLattice17("default", "sharedResource").store;
8418
+ const { ResourceController } = await import("./resources-P4XF764M.mjs");
8419
+ const sharedResourceStore = getStoreLattice16("default", "sharedResource").store;
8341
8420
  const cache = new TokenCache();
8342
8421
  const resourceController = new ResourceController({
8343
8422
  store: sharedResourceStore,
@@ -8386,6 +8465,9 @@ var start = async (config) => {
8386
8465
  }).catch((error) => {
8387
8466
  logger4.error("Agent recovery failed", { error });
8388
8467
  });
8468
+ restoreMcpConnections().catch((error) => {
8469
+ logger4.error("MCP connection restoration failed", { error });
8470
+ });
8389
8471
  } catch (err) {
8390
8472
  logger4.error("Server start failed", { error: err });
8391
8473
  process.exit(1);