@axiom-lattice/gateway 2.1.62 → 2.1.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1371,6 +1371,9 @@ async function createSkill(request, reply) {
1371
1371
  if (error.message?.includes("already exists")) {
1372
1372
  return reply.status(409).send({ success: false, message: error.message });
1373
1373
  }
1374
+ if (error.message?.includes("built-in skill")) {
1375
+ return reply.status(403).send({ success: false, message: error.message });
1376
+ }
1374
1377
  if (error.message?.includes("must equal name") || error.message?.includes("Invalid skill name")) {
1375
1378
  return reply.status(400).send({ success: false, message: error.message });
1376
1379
  }
@@ -1387,6 +1390,9 @@ async function updateSkill(request, reply) {
1387
1390
  }
1388
1391
  return { success: true, message: "Successfully updated skill", data: serializeSkill(skill) };
1389
1392
  } catch (error) {
1393
+ if (error.message?.includes("built-in skill")) {
1394
+ return reply.status(403).send({ success: false, message: error.message });
1395
+ }
1390
1396
  if (error.message?.includes("Invalid skill name")) {
1391
1397
  return reply.status(400).send({ success: false, message: error.message });
1392
1398
  }
@@ -1402,6 +1408,9 @@ async function deleteSkill(request, reply) {
1402
1408
  }
1403
1409
  return { success: true, message: "Successfully deleted skill" };
1404
1410
  } catch (error) {
1411
+ if (error.message?.includes("built-in skill")) {
1412
+ return reply.status(403).send({ success: false, message: error.message });
1413
+ }
1405
1414
  return reply.status(500).send({ success: false, message: `Failed to delete skill: ${error.message}` });
1406
1415
  }
1407
1416
  }
@@ -1700,6 +1709,296 @@ async function executeSqlQuery(client, body, reply) {
1700
1709
  };
1701
1710
  }
1702
1711
 
1712
+ // src/controllers/workflow-tracking.ts
1713
+ import { getStoreLattice as getStoreLattice4, agentInstanceManager as agentInstanceManager4 } from "@axiom-lattice/core";
1714
+ function getTenantId6(request) {
1715
+ const userTenantId = request.user?.tenantId;
1716
+ if (userTenantId) return userTenantId;
1717
+ return request.headers["x-tenant-id"] || "default";
1718
+ }
1719
+ function getTrackingStore() {
1720
+ try {
1721
+ const storeLattice = getStoreLattice4("default", "workflowTracking");
1722
+ return storeLattice.store;
1723
+ } catch {
1724
+ return null;
1725
+ }
1726
+ }
1727
+ async function getDefinitionsFromAssistants(tenantId) {
1728
+ try {
1729
+ const storeLattice = getStoreLattice4("default", "assistant");
1730
+ const assistantStore = storeLattice.store;
1731
+ const assistants = await assistantStore.getAllAssistants(tenantId);
1732
+ const results = [];
1733
+ for (const a of assistants) {
1734
+ const def = a.graphDefinition;
1735
+ if (!def || def.type !== "processing") continue;
1736
+ if (!def.middleware) continue;
1737
+ for (const mw of def.middleware) {
1738
+ if (mw.type === "topology" && mw.enabled && mw.config?.edges?.length > 0) {
1739
+ results.push({
1740
+ assistantId: a.id,
1741
+ assistantName: a.name,
1742
+ topologyEdges: mw.config.edges,
1743
+ totalEdges: mw.config.edges.length
1744
+ });
1745
+ }
1746
+ }
1747
+ }
1748
+ return results;
1749
+ } catch {
1750
+ return [];
1751
+ }
1752
+ }
1753
+ async function getAllWorkflowDefinitions(request, reply) {
1754
+ const tenantId = getTenantId6(request);
1755
+ try {
1756
+ const configDefs = await getDefinitionsFromAssistants(tenantId);
1757
+ if (configDefs.length === 0) {
1758
+ return {
1759
+ success: true,
1760
+ message: "No workflow definitions found",
1761
+ data: { records: [] }
1762
+ };
1763
+ }
1764
+ const runMap = /* @__PURE__ */ new Map();
1765
+ try {
1766
+ const store = getTrackingStore();
1767
+ if (store) {
1768
+ const runs = await store.getWorkflowRunsByTenantId(tenantId);
1769
+ for (const r of runs) {
1770
+ const entry = runMap.get(r.assistantId) || { runCount: 0 };
1771
+ entry.runCount++;
1772
+ if (!entry.lastRunAt || new Date(r.startedAt) > new Date(entry.lastRunAt)) {
1773
+ entry.lastRunAt = r.startedAt instanceof Date ? r.startedAt.toISOString() : String(r.startedAt);
1774
+ }
1775
+ runMap.set(r.assistantId, entry);
1776
+ }
1777
+ }
1778
+ } catch {
1779
+ }
1780
+ const definitions = configDefs.map((d) => {
1781
+ const runInfo = runMap.get(d.assistantId);
1782
+ return {
1783
+ ...d,
1784
+ lastRunAt: runInfo?.lastRunAt || null,
1785
+ runCount: runInfo?.runCount || 0
1786
+ };
1787
+ });
1788
+ return {
1789
+ success: true,
1790
+ message: "Successfully retrieved workflow definitions",
1791
+ data: { records: definitions }
1792
+ };
1793
+ } catch (error) {
1794
+ request.log.error(error, "Failed to get workflow definitions");
1795
+ return reply.status(500).send({ success: false, message: "Failed to retrieve workflow definitions" });
1796
+ }
1797
+ }
1798
+ async function getAllWorkflowRuns(request, reply) {
1799
+ const tenantId = getTenantId6(request);
1800
+ const { assistantId, status } = request.query;
1801
+ try {
1802
+ const store = getTrackingStore();
1803
+ if (!store) {
1804
+ return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
1805
+ }
1806
+ let runs;
1807
+ if (assistantId) {
1808
+ runs = await store.getWorkflowRunsByAssistantId(tenantId, assistantId);
1809
+ } else {
1810
+ runs = await store.getWorkflowRunsByTenantId(tenantId);
1811
+ }
1812
+ if (status) {
1813
+ runs = runs.filter((r) => r.status === status);
1814
+ }
1815
+ return {
1816
+ success: true,
1817
+ message: "Successfully retrieved workflow runs",
1818
+ data: { records: runs, total: runs.length }
1819
+ };
1820
+ } catch (error) {
1821
+ request.log.error(error, "Failed to get workflow runs");
1822
+ return reply.status(500).send({ success: false, message: "Failed to retrieve workflow runs" });
1823
+ }
1824
+ }
1825
+ async function getInboxItems(request, reply) {
1826
+ const tenantId = getTenantId6(request);
1827
+ try {
1828
+ const store = getTrackingStore();
1829
+ if (!store) {
1830
+ return { success: true, message: "No tracking store configured", data: { records: [] } };
1831
+ }
1832
+ const nameMap = {};
1833
+ try {
1834
+ const asStoreLattice = getStoreLattice4("default", "assistant");
1835
+ const assistantStore = asStoreLattice.store;
1836
+ const assistants = await assistantStore.getAllAssistants(tenantId);
1837
+ for (const a of assistants) {
1838
+ nameMap[a.id] = a.name;
1839
+ }
1840
+ } catch {
1841
+ }
1842
+ const runs = await store.getWorkflowRunsByTenantId(tenantId);
1843
+ const runningRuns = runs.filter((r) => r.status === "running");
1844
+ if (runningRuns.length === 0) {
1845
+ return { success: true, message: "No running workflows", data: { records: [] } };
1846
+ }
1847
+ const inboxItems = [];
1848
+ for (const r of runningRuns) {
1849
+ try {
1850
+ const agent = agentInstanceManager4.getAgent({
1851
+ assistant_id: r.assistantId,
1852
+ thread_id: r.threadId,
1853
+ tenant_id: r.tenantId
1854
+ });
1855
+ const runStatus = await agent.getRunStatus();
1856
+ if (runStatus !== "interrupted") continue;
1857
+ const state = await agent.getCurrentState();
1858
+ const interrupts = state.tasks?.flatMap((t) => t.interrupts || []) || [];
1859
+ for (const i of interrupts) {
1860
+ inboxItems.push({
1861
+ runId: r.id,
1862
+ assistantId: r.assistantId,
1863
+ assistantName: nameMap[r.assistantId] || r.assistantId,
1864
+ threadId: r.threadId,
1865
+ tenantId: r.tenantId,
1866
+ interruptId: i.id,
1867
+ interruptValue: i.value,
1868
+ startedAt: r.startedAt,
1869
+ totalEdges: r.totalEdges,
1870
+ completedEdges: r.completedEdges
1871
+ });
1872
+ }
1873
+ } catch {
1874
+ }
1875
+ }
1876
+ inboxItems.sort(
1877
+ (a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
1878
+ );
1879
+ return {
1880
+ success: true,
1881
+ message: "Successfully retrieved inbox items",
1882
+ data: { records: inboxItems }
1883
+ };
1884
+ } catch (error) {
1885
+ request.log.error(error, "Failed to get inbox items");
1886
+ return reply.status(500).send({ success: false, message: "Failed to retrieve inbox items" });
1887
+ }
1888
+ }
1889
+ async function getWorkflowDefinitions(request, reply) {
1890
+ const { assistantId } = request.params;
1891
+ const tenantId = getTenantId6(request);
1892
+ try {
1893
+ const store = getTrackingStore();
1894
+ if (!store) {
1895
+ return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
1896
+ }
1897
+ const runs = await store.getWorkflowRunsByAssistantId(tenantId, assistantId);
1898
+ const seen = /* @__PURE__ */ new Set();
1899
+ const definitions = runs.filter((r) => {
1900
+ const key = JSON.stringify(r.topologyEdges);
1901
+ if (seen.has(key)) return false;
1902
+ seen.add(key);
1903
+ return true;
1904
+ }).map((r) => ({
1905
+ assistantId: r.assistantId,
1906
+ topologyEdges: r.topologyEdges,
1907
+ totalEdges: r.totalEdges,
1908
+ lastRunAt: r.startedAt
1909
+ }));
1910
+ return {
1911
+ success: true,
1912
+ message: "Successfully retrieved workflow definitions",
1913
+ data: { records: definitions }
1914
+ };
1915
+ } catch (error) {
1916
+ request.log.error(error, "Failed to get workflow definitions");
1917
+ return reply.status(500).send({ success: false, message: "Failed to retrieve workflow definitions" });
1918
+ }
1919
+ }
1920
+ async function getWorkflowRuns(request, reply) {
1921
+ const { threadId } = request.params;
1922
+ const tenantId = getTenantId6(request);
1923
+ try {
1924
+ const store = getTrackingStore();
1925
+ if (!store) {
1926
+ return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
1927
+ }
1928
+ const runs = await store.getWorkflowRunsByThreadId(tenantId, threadId);
1929
+ return {
1930
+ success: true,
1931
+ message: "Successfully retrieved workflow runs",
1932
+ data: { records: runs, total: runs.length }
1933
+ };
1934
+ } catch (error) {
1935
+ request.log.error(error, "Failed to get workflow runs");
1936
+ return reply.status(500).send({ success: false, message: "Failed to retrieve workflow runs" });
1937
+ }
1938
+ }
1939
+ async function getWorkflowRun(request, reply) {
1940
+ const { runId } = request.params;
1941
+ try {
1942
+ const store = getTrackingStore();
1943
+ if (!store) {
1944
+ return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
1945
+ }
1946
+ const run = await store.getWorkflowRun(runId);
1947
+ if (!run) {
1948
+ return reply.status(404).send({ success: false, message: "Workflow run not found" });
1949
+ }
1950
+ return { success: true, message: "Successfully retrieved workflow run", data: run };
1951
+ } catch (error) {
1952
+ request.log.error(error, "Failed to get workflow run");
1953
+ return reply.status(500).send({ success: false, message: "Failed to retrieve workflow run" });
1954
+ }
1955
+ }
1956
+ async function getRunSteps(request, reply) {
1957
+ const { runId } = request.params;
1958
+ const { step_type, status: stepStatus } = request.query;
1959
+ try {
1960
+ const store = getTrackingStore();
1961
+ if (!store) {
1962
+ return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
1963
+ }
1964
+ let steps;
1965
+ if (step_type) {
1966
+ steps = await store.getRunStepsByType(runId, step_type);
1967
+ } else {
1968
+ steps = await store.getRunSteps(runId);
1969
+ }
1970
+ if (stepStatus) {
1971
+ steps = steps.filter((s) => s.status === stepStatus);
1972
+ }
1973
+ return {
1974
+ success: true,
1975
+ message: "Successfully retrieved run steps",
1976
+ data: { records: steps, total: steps.length }
1977
+ };
1978
+ } catch (error) {
1979
+ request.log.error(error, "Failed to get run steps");
1980
+ return reply.status(500).send({ success: false, message: "Failed to retrieve run steps" });
1981
+ }
1982
+ }
1983
+ async function getRunTasks(request, reply) {
1984
+ const { runId } = request.params;
1985
+ try {
1986
+ const store = getTrackingStore();
1987
+ if (!store) {
1988
+ return reply.status(404).send({ success: false, message: "No workflow tracking store configured" });
1989
+ }
1990
+ const steps = await store.getInterruptedSteps(runId);
1991
+ return {
1992
+ success: true,
1993
+ message: "Successfully retrieved user tasks",
1994
+ data: { records: steps, total: steps.length }
1995
+ };
1996
+ } catch (error) {
1997
+ request.log.error(error, "Failed to get run tasks");
1998
+ return reply.status(500).send({ success: false, message: "Failed to retrieve user tasks" });
1999
+ }
2000
+ }
2001
+
1703
2002
  // src/schemas/data-query.ts
1704
2003
  var dataQuerySchema = {
1705
2004
  description: "Execute data query (semantic or SQL)",
@@ -2041,7 +2340,7 @@ var getHealthSchema = {
2041
2340
  };
2042
2341
 
2043
2342
  // src/controllers/thread_status.ts
2044
- import { agentInstanceManager as agentInstanceManager4 } from "@axiom-lattice/core";
2343
+ import { agentInstanceManager as agentInstanceManager5 } from "@axiom-lattice/core";
2045
2344
  async function removePendingMessageHandler(request, reply) {
2046
2345
  try {
2047
2346
  const { assistant_id, thread_id, message_id } = request.params;
@@ -2054,7 +2353,7 @@ async function removePendingMessageHandler(request, reply) {
2054
2353
  if (!assistant_id) {
2055
2354
  return reply.code(400).send({ error: "Missing assistant_id parameter" });
2056
2355
  }
2057
- const agent = agentInstanceManager4.getAgent({
2356
+ const agent = agentInstanceManager5.getAgent({
2058
2357
  assistant_id,
2059
2358
  thread_id,
2060
2359
  tenant_id,
@@ -2384,14 +2683,14 @@ function registerSandboxProxyRoutes(app2) {
2384
2683
  // src/controllers/workspace.ts
2385
2684
  import * as fs from "fs/promises";
2386
2685
  import * as path from "path";
2387
- import { getStoreLattice as getStoreLattice4 } from "@axiom-lattice/core";
2686
+ import { getStoreLattice as getStoreLattice5 } from "@axiom-lattice/core";
2388
2687
  import { SandboxFilesystem, FilesystemBackend } from "@axiom-lattice/core";
2389
2688
  import { getSandBoxManager as getSandBoxManager3 } from "@axiom-lattice/core";
2390
2689
  import { v4 as uuidv4 } from "uuid";
2391
2690
  var WorkspaceController = class {
2392
2691
  constructor() {
2393
- this.workspaceStore = getStoreLattice4("default", "workspace").store;
2394
- this.projectStore = getStoreLattice4("default", "project").store;
2692
+ this.workspaceStore = getStoreLattice5("default", "workspace").store;
2693
+ this.projectStore = getStoreLattice5("default", "project").store;
2395
2694
  }
2396
2695
  getTenantId(request) {
2397
2696
  const userTenantId = request.user?.tenantId;
@@ -2916,11 +3215,11 @@ function registerWorkspaceRoutes(app2) {
2916
3215
 
2917
3216
  // src/controllers/database-configs.ts
2918
3217
  import {
2919
- getStoreLattice as getStoreLattice5,
3218
+ getStoreLattice as getStoreLattice6,
2920
3219
  sqlDatabaseManager
2921
3220
  } from "@axiom-lattice/core";
2922
3221
  import { randomUUID as randomUUID3 } from "crypto";
2923
- function getTenantId6(request) {
3222
+ function getTenantId7(request) {
2924
3223
  const userTenantId = request.user?.tenantId;
2925
3224
  if (userTenantId) {
2926
3225
  return userTenantId;
@@ -2928,9 +3227,9 @@ function getTenantId6(request) {
2928
3227
  return request.headers["x-tenant-id"] || "default";
2929
3228
  }
2930
3229
  async function getDatabaseConfigList(request, reply) {
2931
- const tenantId = getTenantId6(request);
3230
+ const tenantId = getTenantId7(request);
2932
3231
  try {
2933
- const storeLattice = getStoreLattice5("default", "database");
3232
+ const storeLattice = getStoreLattice6("default", "database");
2934
3233
  const store = storeLattice.store;
2935
3234
  const configs = await store.getAllConfigs(tenantId);
2936
3235
  console.log("Backend: getAllConfigs returned:", configs);
@@ -2958,10 +3257,10 @@ async function getDatabaseConfigList(request, reply) {
2958
3257
  }
2959
3258
  }
2960
3259
  async function getDatabaseConfig(request, reply) {
2961
- const tenantId = getTenantId6(request);
3260
+ const tenantId = getTenantId7(request);
2962
3261
  const { key } = request.params;
2963
3262
  try {
2964
- const storeLattice = getStoreLattice5("default", "database");
3263
+ const storeLattice = getStoreLattice6("default", "database");
2965
3264
  const store = storeLattice.store;
2966
3265
  const config = await store.getConfigByKey(tenantId, key);
2967
3266
  if (!config) {
@@ -2984,10 +3283,10 @@ async function getDatabaseConfig(request, reply) {
2984
3283
  }
2985
3284
  }
2986
3285
  async function createDatabaseConfig(request, reply) {
2987
- const tenantId = getTenantId6(request);
3286
+ const tenantId = getTenantId7(request);
2988
3287
  const body = request.body;
2989
3288
  try {
2990
- const storeLattice = getStoreLattice5("default", "database");
3289
+ const storeLattice = getStoreLattice6("default", "database");
2991
3290
  const store = storeLattice.store;
2992
3291
  const existing = await store.getConfigByKey(tenantId, body.key);
2993
3292
  if (existing) {
@@ -3019,11 +3318,11 @@ async function createDatabaseConfig(request, reply) {
3019
3318
  }
3020
3319
  }
3021
3320
  async function updateDatabaseConfig(request, reply) {
3022
- const tenantId = getTenantId6(request);
3321
+ const tenantId = getTenantId7(request);
3023
3322
  const { key } = request.params;
3024
3323
  const updates = request.body;
3025
3324
  try {
3026
- const storeLattice = getStoreLattice5("default", "database");
3325
+ const storeLattice = getStoreLattice6("default", "database");
3027
3326
  const store = storeLattice.store;
3028
3327
  const existing = await store.getConfigByKey(tenantId, key);
3029
3328
  if (!existing) {
@@ -3061,10 +3360,10 @@ async function updateDatabaseConfig(request, reply) {
3061
3360
  }
3062
3361
  }
3063
3362
  async function deleteDatabaseConfig(request, reply) {
3064
- const tenantId = getTenantId6(request);
3363
+ const tenantId = getTenantId7(request);
3065
3364
  const { keyOrId } = request.params;
3066
3365
  try {
3067
- const storeLattice = getStoreLattice5("default", "database");
3366
+ const storeLattice = getStoreLattice6("default", "database");
3068
3367
  const store = storeLattice.store;
3069
3368
  console.log("Delete request - keyOrId:", keyOrId);
3070
3369
  let config = await store.getConfigByKey(tenantId, keyOrId);
@@ -3110,10 +3409,10 @@ async function deleteDatabaseConfig(request, reply) {
3110
3409
  }
3111
3410
  }
3112
3411
  async function testDatabaseConnection(request, reply) {
3113
- const tenantId = getTenantId6(request);
3412
+ const tenantId = getTenantId7(request);
3114
3413
  const { key } = request.params;
3115
3414
  try {
3116
- const storeLattice = getStoreLattice5("default", "database");
3415
+ const storeLattice = getStoreLattice6("default", "database");
3117
3416
  const store = storeLattice.store;
3118
3417
  const config = await store.getConfigByKey(tenantId, key);
3119
3418
  if (!config) {
@@ -3198,12 +3497,12 @@ function registerDatabaseConfigRoutes(app2) {
3198
3497
 
3199
3498
  // src/controllers/metrics-configs.ts
3200
3499
  import {
3201
- getStoreLattice as getStoreLattice6,
3500
+ getStoreLattice as getStoreLattice7,
3202
3501
  metricsServerManager as metricsServerManager2,
3203
3502
  SemanticMetricsClient as SemanticMetricsClient2
3204
3503
  } from "@axiom-lattice/core";
3205
3504
  import { randomUUID as randomUUID4 } from "crypto";
3206
- function getTenantId7(request) {
3505
+ function getTenantId8(request) {
3207
3506
  const userTenantId = request.user?.tenantId;
3208
3507
  if (userTenantId) {
3209
3508
  return userTenantId;
@@ -3211,9 +3510,9 @@ function getTenantId7(request) {
3211
3510
  return request.headers["x-tenant-id"] || "default";
3212
3511
  }
3213
3512
  async function getMetricsServerConfigList(request, reply) {
3214
- const tenantId = getTenantId7(request);
3513
+ const tenantId = getTenantId8(request);
3215
3514
  try {
3216
- const storeLattice = getStoreLattice6("default", "metrics");
3515
+ const storeLattice = getStoreLattice7("default", "metrics");
3217
3516
  const store = storeLattice.store;
3218
3517
  const configs = await store.getAllConfigs(tenantId);
3219
3518
  return {
@@ -3237,10 +3536,10 @@ async function getMetricsServerConfigList(request, reply) {
3237
3536
  }
3238
3537
  }
3239
3538
  async function getMetricsServerConfig(request, reply) {
3240
- const tenantId = getTenantId7(request);
3539
+ const tenantId = getTenantId8(request);
3241
3540
  const { key } = request.params;
3242
3541
  try {
3243
- const storeLattice = getStoreLattice6("default", "metrics");
3542
+ const storeLattice = getStoreLattice7("default", "metrics");
3244
3543
  const store = storeLattice.store;
3245
3544
  const config = await store.getConfigByKey(tenantId, key);
3246
3545
  if (!config) {
@@ -3263,10 +3562,10 @@ async function getMetricsServerConfig(request, reply) {
3263
3562
  }
3264
3563
  }
3265
3564
  async function createMetricsServerConfig(request, reply) {
3266
- const tenantId = getTenantId7(request);
3565
+ const tenantId = getTenantId8(request);
3267
3566
  const body = request.body;
3268
3567
  try {
3269
- const storeLattice = getStoreLattice6("default", "metrics");
3568
+ const storeLattice = getStoreLattice7("default", "metrics");
3270
3569
  const store = storeLattice.store;
3271
3570
  const existing = await store.getConfigByKey(tenantId, body.key);
3272
3571
  if (existing) {
@@ -3314,11 +3613,11 @@ async function createMetricsServerConfig(request, reply) {
3314
3613
  }
3315
3614
  }
3316
3615
  async function updateMetricsServerConfig(request, reply) {
3317
- const tenantId = getTenantId7(request);
3616
+ const tenantId = getTenantId8(request);
3318
3617
  const { key } = request.params;
3319
3618
  const updates = request.body;
3320
3619
  try {
3321
- const storeLattice = getStoreLattice6("default", "metrics");
3620
+ const storeLattice = getStoreLattice7("default", "metrics");
3322
3621
  const store = storeLattice.store;
3323
3622
  const existing = await store.getConfigByKey(tenantId, key);
3324
3623
  if (!existing) {
@@ -3365,10 +3664,10 @@ async function updateMetricsServerConfig(request, reply) {
3365
3664
  }
3366
3665
  }
3367
3666
  async function deleteMetricsServerConfig(request, reply) {
3368
- const tenantId = getTenantId7(request);
3667
+ const tenantId = getTenantId8(request);
3369
3668
  const { keyOrId } = request.params;
3370
3669
  try {
3371
- const storeLattice = getStoreLattice6("default", "metrics");
3670
+ const storeLattice = getStoreLattice7("default", "metrics");
3372
3671
  const store = storeLattice.store;
3373
3672
  let config = await store.getConfigByKey(tenantId, keyOrId);
3374
3673
  let configKey = keyOrId;
@@ -3412,10 +3711,10 @@ async function deleteMetricsServerConfig(request, reply) {
3412
3711
  }
3413
3712
  }
3414
3713
  async function testMetricsServerConnection(request, reply) {
3415
- const tenantId = getTenantId7(request);
3714
+ const tenantId = getTenantId8(request);
3416
3715
  const { key } = request.params;
3417
3716
  try {
3418
- const storeLattice = getStoreLattice6("default", "metrics");
3717
+ const storeLattice = getStoreLattice7("default", "metrics");
3419
3718
  const store = storeLattice.store;
3420
3719
  const config = await store.getConfigByKey(tenantId, key);
3421
3720
  if (!config) {
@@ -3463,10 +3762,10 @@ async function testMetricsServerConnection(request, reply) {
3463
3762
  }
3464
3763
  }
3465
3764
  async function listAvailableMetrics(request, reply) {
3466
- const tenantId = getTenantId7(request);
3765
+ const tenantId = getTenantId8(request);
3467
3766
  const { key } = request.params;
3468
3767
  try {
3469
- const storeLattice = getStoreLattice6("default", "metrics");
3768
+ const storeLattice = getStoreLattice7("default", "metrics");
3470
3769
  const store = storeLattice.store;
3471
3770
  const config = await store.getConfigByKey(tenantId, key);
3472
3771
  if (!config) {
@@ -3501,11 +3800,11 @@ async function listAvailableMetrics(request, reply) {
3501
3800
  }
3502
3801
  }
3503
3802
  async function queryMetricsData(request, reply) {
3504
- const tenantId = getTenantId7(request);
3803
+ const tenantId = getTenantId8(request);
3505
3804
  const { key } = request.params;
3506
3805
  const { metricName, startTime, endTime, step, labels } = request.body;
3507
3806
  try {
3508
- const storeLattice = getStoreLattice6("default", "metrics");
3807
+ const storeLattice = getStoreLattice7("default", "metrics");
3509
3808
  const store = storeLattice.store;
3510
3809
  const config = await store.getConfigByKey(tenantId, key);
3511
3810
  if (!config) {
@@ -3549,10 +3848,10 @@ async function queryMetricsData(request, reply) {
3549
3848
  }
3550
3849
  }
3551
3850
  async function getDataSources(request, reply) {
3552
- const tenantId = getTenantId7(request);
3851
+ const tenantId = getTenantId8(request);
3553
3852
  const { key } = request.params;
3554
3853
  try {
3555
- const storeLattice = getStoreLattice6("default", "metrics");
3854
+ const storeLattice = getStoreLattice7("default", "metrics");
3556
3855
  const store = storeLattice.store;
3557
3856
  const config = await store.getConfigByKey(tenantId, key);
3558
3857
  if (!config) {
@@ -3590,10 +3889,10 @@ async function getDataSources(request, reply) {
3590
3889
  }
3591
3890
  }
3592
3891
  async function getDatasourceMetrics(request, reply) {
3593
- const tenantId = getTenantId7(request);
3892
+ const tenantId = getTenantId8(request);
3594
3893
  const { key, datasourceId } = request.params;
3595
3894
  try {
3596
- const storeLattice = getStoreLattice6("default", "metrics");
3895
+ const storeLattice = getStoreLattice7("default", "metrics");
3597
3896
  const store = storeLattice.store;
3598
3897
  const config = await store.getConfigByKey(tenantId, key);
3599
3898
  if (!config) {
@@ -3627,11 +3926,11 @@ async function getDatasourceMetrics(request, reply) {
3627
3926
  }
3628
3927
  }
3629
3928
  async function querySemanticMetrics(request, reply) {
3630
- const tenantId = getTenantId7(request);
3929
+ const tenantId = getTenantId8(request);
3631
3930
  const { key } = request.params;
3632
3931
  const body = request.body;
3633
3932
  try {
3634
- const storeLattice = getStoreLattice6("default", "metrics");
3933
+ const storeLattice = getStoreLattice7("default", "metrics");
3635
3934
  const store = storeLattice.store;
3636
3935
  const config = await store.getConfigByKey(tenantId, key);
3637
3936
  if (!config) {
@@ -3785,12 +4084,12 @@ function registerMetricsServerConfigRoutes(app2) {
3785
4084
 
3786
4085
  // src/controllers/mcp-configs.ts
3787
4086
  import {
3788
- getStoreLattice as getStoreLattice7,
4087
+ getStoreLattice as getStoreLattice8,
3789
4088
  mcpManager,
3790
4089
  toolLatticeManager as toolLatticeManager2
3791
4090
  } from "@axiom-lattice/core";
3792
4091
  import { randomUUID as randomUUID5 } from "crypto";
3793
- function getTenantId8(request) {
4092
+ function getTenantId9(request) {
3794
4093
  const userTenantId = request.user?.tenantId;
3795
4094
  if (userTenantId) {
3796
4095
  return userTenantId;
@@ -3798,9 +4097,9 @@ function getTenantId8(request) {
3798
4097
  return request.headers["x-tenant-id"] || "default";
3799
4098
  }
3800
4099
  async function getMcpServerConfigList(request, reply) {
3801
- const tenantId = getTenantId8(request);
4100
+ const tenantId = getTenantId9(request);
3802
4101
  try {
3803
- const storeLattice = getStoreLattice7("default", "mcp");
4102
+ const storeLattice = getStoreLattice8("default", "mcp");
3804
4103
  const store = storeLattice.store;
3805
4104
  const configs = await store.getAllConfigs(tenantId);
3806
4105
  return {
@@ -3824,10 +4123,10 @@ async function getMcpServerConfigList(request, reply) {
3824
4123
  }
3825
4124
  }
3826
4125
  async function getMcpServerConfig(request, reply) {
3827
- const tenantId = getTenantId8(request);
4126
+ const tenantId = getTenantId9(request);
3828
4127
  const { key } = request.params;
3829
4128
  try {
3830
- const storeLattice = getStoreLattice7("default", "mcp");
4129
+ const storeLattice = getStoreLattice8("default", "mcp");
3831
4130
  const store = storeLattice.store;
3832
4131
  const config = await store.getConfigByKey(tenantId, key);
3833
4132
  if (!config) {
@@ -3850,10 +4149,10 @@ async function getMcpServerConfig(request, reply) {
3850
4149
  }
3851
4150
  }
3852
4151
  async function createMcpServerConfig(request, reply) {
3853
- const tenantId = getTenantId8(request);
4152
+ const tenantId = getTenantId9(request);
3854
4153
  const body = request.body;
3855
4154
  try {
3856
- const storeLattice = getStoreLattice7("default", "mcp");
4155
+ const storeLattice = getStoreLattice8("default", "mcp");
3857
4156
  const store = storeLattice.store;
3858
4157
  const existing = await store.getConfigByKey(tenantId, body.key);
3859
4158
  if (existing) {
@@ -3889,11 +4188,11 @@ async function createMcpServerConfig(request, reply) {
3889
4188
  }
3890
4189
  }
3891
4190
  async function updateMcpServerConfig(request, reply) {
3892
- const tenantId = getTenantId8(request);
4191
+ const tenantId = getTenantId9(request);
3893
4192
  const { key } = request.params;
3894
4193
  const updates = request.body;
3895
4194
  try {
3896
- const storeLattice = getStoreLattice7("default", "mcp");
4195
+ const storeLattice = getStoreLattice8("default", "mcp");
3897
4196
  const store = storeLattice.store;
3898
4197
  const existing = await store.getConfigByKey(tenantId, key);
3899
4198
  if (!existing) {
@@ -3939,10 +4238,10 @@ async function updateMcpServerConfig(request, reply) {
3939
4238
  }
3940
4239
  }
3941
4240
  async function deleteMcpServerConfig(request, reply) {
3942
- const tenantId = getTenantId8(request);
4241
+ const tenantId = getTenantId9(request);
3943
4242
  const { keyOrId } = request.params;
3944
4243
  try {
3945
- const storeLattice = getStoreLattice7("default", "mcp");
4244
+ const storeLattice = getStoreLattice8("default", "mcp");
3946
4245
  const store = storeLattice.store;
3947
4246
  let config = await store.getConfigByKey(tenantId, keyOrId);
3948
4247
  let configKey = keyOrId;
@@ -3986,10 +4285,10 @@ async function deleteMcpServerConfig(request, reply) {
3986
4285
  }
3987
4286
  }
3988
4287
  async function testMcpServerConnection(request, reply) {
3989
- const tenantId = getTenantId8(request);
4288
+ const tenantId = getTenantId9(request);
3990
4289
  const { key } = request.params;
3991
4290
  try {
3992
- const storeLattice = getStoreLattice7("default", "mcp");
4291
+ const storeLattice = getStoreLattice8("default", "mcp");
3993
4292
  const store = storeLattice.store;
3994
4293
  const config = await store.getConfigByKey(tenantId, key);
3995
4294
  if (!config) {
@@ -4039,10 +4338,10 @@ async function testMcpServerConnection(request, reply) {
4039
4338
  }
4040
4339
  }
4041
4340
  async function listMcpServerTools(request, reply) {
4042
- const tenantId = getTenantId8(request);
4341
+ const tenantId = getTenantId9(request);
4043
4342
  const { key } = request.params;
4044
4343
  try {
4045
- const storeLattice = getStoreLattice7("default", "mcp");
4344
+ const storeLattice = getStoreLattice8("default", "mcp");
4046
4345
  const store = storeLattice.store;
4047
4346
  const config = await store.getConfigByKey(tenantId, key);
4048
4347
  if (!config) {
@@ -4072,10 +4371,10 @@ async function listMcpServerTools(request, reply) {
4072
4371
  }
4073
4372
  }
4074
4373
  async function connectMcpServer(request, reply) {
4075
- const tenantId = getTenantId8(request);
4374
+ const tenantId = getTenantId9(request);
4076
4375
  const { key } = request.params;
4077
4376
  try {
4078
- const storeLattice = getStoreLattice7("default", "mcp");
4377
+ const storeLattice = getStoreLattice8("default", "mcp");
4079
4378
  const store = storeLattice.store;
4080
4379
  const config = await store.getConfigByKey(tenantId, key);
4081
4380
  if (!config) {
@@ -4096,7 +4395,7 @@ async function connectMcpServer(request, reply) {
4096
4395
  };
4097
4396
  } catch (error) {
4098
4397
  console.error("Failed to connect MCP server:", error);
4099
- const storeLattice = getStoreLattice7("default", "mcp");
4398
+ const storeLattice = getStoreLattice8("default", "mcp");
4100
4399
  const store = storeLattice.store;
4101
4400
  const config = await store.getConfigByKey(tenantId, key);
4102
4401
  if (config) {
@@ -4109,10 +4408,10 @@ async function connectMcpServer(request, reply) {
4109
4408
  }
4110
4409
  }
4111
4410
  async function disconnectMcpServer(request, reply) {
4112
- const tenantId = getTenantId8(request);
4411
+ const tenantId = getTenantId9(request);
4113
4412
  const { key } = request.params;
4114
4413
  try {
4115
- const storeLattice = getStoreLattice7("default", "mcp");
4414
+ const storeLattice = getStoreLattice8("default", "mcp");
4116
4415
  const store = storeLattice.store;
4117
4416
  const config = await store.getConfigByKey(tenantId, key);
4118
4417
  if (!config) {
@@ -4217,11 +4516,11 @@ function registerMcpServerConfigRoutes(app2) {
4217
4516
  }
4218
4517
 
4219
4518
  // src/controllers/users.ts
4220
- import { getStoreLattice as getStoreLattice8 } from "@axiom-lattice/core";
4519
+ import { getStoreLattice as getStoreLattice9 } from "@axiom-lattice/core";
4221
4520
  import { v4 as uuidv42 } from "uuid";
4222
4521
  var UsersController = class {
4223
4522
  constructor() {
4224
- this.userStore = getStoreLattice8("default", "user").store;
4523
+ this.userStore = getStoreLattice9("default", "user").store;
4225
4524
  }
4226
4525
  async listUsers(request, reply) {
4227
4526
  const { email } = request.query;
@@ -4299,11 +4598,11 @@ function registerUserRoutes(app2) {
4299
4598
  }
4300
4599
 
4301
4600
  // src/controllers/tenants.ts
4302
- import { getStoreLattice as getStoreLattice9 } from "@axiom-lattice/core";
4601
+ import { getStoreLattice as getStoreLattice10 } from "@axiom-lattice/core";
4303
4602
  import { v4 as uuidv43 } from "uuid";
4304
4603
  var TenantsController = class {
4305
4604
  constructor() {
4306
- this.tenantStore = getStoreLattice9("default", "tenant").store;
4605
+ this.tenantStore = getStoreLattice10("default", "tenant").store;
4307
4606
  }
4308
4607
  // ==================== Tenant CRUD ====================
4309
4608
  async listTenants(request, reply) {
@@ -4367,7 +4666,7 @@ function registerTenantRoutes(app2) {
4367
4666
  }
4368
4667
 
4369
4668
  // src/controllers/auth.ts
4370
- import { getStoreLattice as getStoreLattice10 } from "@axiom-lattice/core";
4669
+ import { getStoreLattice as getStoreLattice11 } from "@axiom-lattice/core";
4371
4670
  import { v4 as uuidv44 } from "uuid";
4372
4671
  var defaultAuthConfig = {
4373
4672
  autoApproveUsers: true,
@@ -4376,9 +4675,9 @@ var defaultAuthConfig = {
4376
4675
  };
4377
4676
  var AuthController = class {
4378
4677
  constructor(config = {}) {
4379
- this.userStore = getStoreLattice10("default", "user").store;
4380
- this.tenantStore = getStoreLattice10("default", "tenant").store;
4381
- this.userTenantLinkStore = getStoreLattice10("default", "userTenantLink").store;
4678
+ this.userStore = getStoreLattice11("default", "user").store;
4679
+ this.tenantStore = getStoreLattice11("default", "tenant").store;
4680
+ this.userTenantLinkStore = getStoreLattice11("default", "userTenantLink").store;
4382
4681
  this.config = { ...defaultAuthConfig, ...config };
4383
4682
  }
4384
4683
  async register(request, reply) {
@@ -4750,7 +5049,7 @@ function registerAuthRoutes(app2, config) {
4750
5049
  }
4751
5050
 
4752
5051
  // src/channels/lark/routes.ts
4753
- import { getStoreLattice as getStoreLattice11 } from "@axiom-lattice/core";
5052
+ import { getStoreLattice as getStoreLattice12 } from "@axiom-lattice/core";
4754
5053
  import {
4755
5054
  ChannelIdentityMappingStore,
4756
5055
  PostgreSQLChannelInstallationStore
@@ -5001,7 +5300,7 @@ function resolveSubjectType(mappingMode, chatType) {
5001
5300
  }
5002
5301
 
5003
5302
  // src/channels/lark/runner.ts
5004
- import { agentInstanceManager as agentInstanceManager5 } from "@axiom-lattice/core";
5303
+ import { agentInstanceManager as agentInstanceManager6 } from "@axiom-lattice/core";
5005
5304
  import { MessageChunkTypes as MessageChunkTypes3 } from "@axiom-lattice/protocols";
5006
5305
 
5007
5306
  // src/channels/lark/aggregator.ts
@@ -5014,7 +5313,7 @@ function aggregateLarkReply(messageId, chunks) {
5014
5313
 
5015
5314
  // src/channels/lark/runner.ts
5016
5315
  async function runAgentAndCollectLarkReply(input) {
5017
- const agent = agentInstanceManager5.getAgent({
5316
+ const agent = agentInstanceManager6.getAgent({
5018
5317
  tenant_id: input.tenantId,
5019
5318
  assistant_id: input.assistantId,
5020
5319
  thread_id: input.threadId,
@@ -5126,7 +5425,7 @@ function createDefaultLarkDependencies() {
5126
5425
  const installationStore = new PostgreSQLChannelInstallationStore({
5127
5426
  poolConfig: getDatabaseUrl()
5128
5427
  });
5129
- const threadStore = getStoreLattice11("default", "thread").store;
5428
+ const threadStore = getStoreLattice12("default", "thread").store;
5130
5429
  const mappingStore = new ChannelIdentityMappingStore({
5131
5430
  poolConfig: getDatabaseUrl()
5132
5431
  });
@@ -5207,7 +5506,7 @@ function registerChannelRoutes(app2, dependencies = {}) {
5207
5506
 
5208
5507
  // src/controllers/channel-installations.ts
5209
5508
  import { randomUUID as randomUUID7 } from "crypto";
5210
- function getTenantId9(request) {
5509
+ function getTenantId10(request) {
5211
5510
  const userTenantId = request.user?.tenantId;
5212
5511
  if (userTenantId) {
5213
5512
  return userTenantId;
@@ -5225,7 +5524,7 @@ async function getInstallationStore() {
5225
5524
  });
5226
5525
  }
5227
5526
  async function getChannelInstallationList(request, reply) {
5228
- const tenantId = getTenantId9(request);
5527
+ const tenantId = getTenantId10(request);
5229
5528
  const { channel } = request.query;
5230
5529
  try {
5231
5530
  const store = await getInstallationStore();
@@ -5251,7 +5550,7 @@ async function getChannelInstallationList(request, reply) {
5251
5550
  }
5252
5551
  }
5253
5552
  async function getChannelInstallation(request, reply) {
5254
- const tenantId = getTenantId9(request);
5553
+ const tenantId = getTenantId10(request);
5255
5554
  const { installationId } = request.params;
5256
5555
  try {
5257
5556
  const store = await getInstallationStore();
@@ -5284,7 +5583,7 @@ async function getChannelInstallation(request, reply) {
5284
5583
  }
5285
5584
  }
5286
5585
  async function createChannelInstallation(request, reply) {
5287
- const tenantId = getTenantId9(request);
5586
+ const tenantId = getTenantId10(request);
5288
5587
  const body = request.body;
5289
5588
  try {
5290
5589
  if (!body.channel) {
@@ -5347,7 +5646,7 @@ async function createChannelInstallation(request, reply) {
5347
5646
  }
5348
5647
  }
5349
5648
  async function updateChannelInstallation(request, reply) {
5350
- const tenantId = getTenantId9(request);
5649
+ const tenantId = getTenantId10(request);
5351
5650
  const { installationId } = request.params;
5352
5651
  const body = request.body;
5353
5652
  try {
@@ -5393,7 +5692,7 @@ async function updateChannelInstallation(request, reply) {
5393
5692
  }
5394
5693
  }
5395
5694
  async function deleteChannelInstallation(request, reply) {
5396
- const tenantId = getTenantId9(request);
5695
+ const tenantId = getTenantId10(request);
5397
5696
  const { installationId } = request.params;
5398
5697
  try {
5399
5698
  const store = await getInstallationStore();
@@ -5579,6 +5878,29 @@ var registerLatticeRoutes = (app2) => {
5579
5878
  });
5580
5879
  registerChannelRoutes(app2);
5581
5880
  registerChannelInstallationRoutes(app2);
5881
+ app2.get(
5882
+ "/api/workflows/definitions",
5883
+ getAllWorkflowDefinitions
5884
+ );
5885
+ app2.get(
5886
+ "/api/workflows/runs",
5887
+ getAllWorkflowRuns
5888
+ );
5889
+ app2.get(
5890
+ "/api/workflows/inbox",
5891
+ getInboxItems
5892
+ );
5893
+ app2.get(
5894
+ "/api/assistants/:assistantId/workflows/definitions",
5895
+ getWorkflowDefinitions
5896
+ );
5897
+ app2.get(
5898
+ "/api/assistants/:assistantId/threads/:threadId/workflows/runs",
5899
+ getWorkflowRuns
5900
+ );
5901
+ app2.get("/api/workflows/runs/:runId", getWorkflowRun);
5902
+ app2.get("/api/workflows/runs/:runId/steps", getRunSteps);
5903
+ app2.get("/api/workflows/runs/:runId/tasks", getRunTasks);
5582
5904
  app2.delete(
5583
5905
  "/api/assistants/:assistant_id/threads/:thread_id/pending-messages/:message_id",
5584
5906
  removePendingMessageHandler
@@ -5648,7 +5970,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
5648
5970
  };
5649
5971
 
5650
5972
  // src/services/agent_task_consumer.ts
5651
- import { eventBus as eventBus2, AGENT_TASK_EVENT, agentInstanceManager as agentInstanceManager6, QueueMode as QueueMode2 } from "@axiom-lattice/core";
5973
+ import { eventBus as eventBus2, AGENT_TASK_EVENT, agentInstanceManager as agentInstanceManager7, QueueMode as QueueMode2 } from "@axiom-lattice/core";
5652
5974
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
5653
5975
  const {
5654
5976
  assistant_id,
@@ -5657,13 +5979,16 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
5657
5979
  "x-tenant-id": tenant_id,
5658
5980
  command,
5659
5981
  callback_event,
5660
- runConfig
5982
+ runConfig,
5983
+ main_thread_id,
5984
+ main_tenant_id,
5985
+ main_assistant_id
5661
5986
  } = taskRequest;
5662
5987
  try {
5663
5988
  console.log(
5664
5989
  `\u5F00\u59CB\u5904\u7406\u4EFB\u52A1 [assistant_id: ${assistant_id}, thread_id: ${thread_id}]`
5665
5990
  );
5666
- const agent = agentInstanceManager6.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
5991
+ const agent = agentInstanceManager7.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig });
5667
5992
  await agent.addMessage({ input, command, custom_run_config: runConfig }, QueueMode2.STEER);
5668
5993
  if (callback_event) {
5669
5994
  agent.subscribeOnce("message:completed", (evt) => {
@@ -5672,6 +5997,34 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
5672
5997
  state: evt.state,
5673
5998
  config: { assistant_id, thread_id, tenant_id }
5674
5999
  });
6000
+ if (main_thread_id && main_tenant_id) {
6001
+ try {
6002
+ const mainAgent = agentInstanceManager7.getAgent({
6003
+ assistant_id: main_assistant_id ?? assistant_id,
6004
+ thread_id: main_thread_id,
6005
+ tenant_id: main_tenant_id
6006
+ });
6007
+ if (mainAgent) {
6008
+ const messages = evt.state?.values?.messages;
6009
+ const lastAIMessage = messages?.filter((m) => m.type === "ai" || m.getType?.() === "ai").pop();
6010
+ const summary = lastAIMessage?.content?.substring(0, 500) ?? "(no output)";
6011
+ mainAgent.addMessage(
6012
+ {
6013
+ input: {
6014
+ message: `[Async task completed]
6015
+ task_id: ${thread_id}
6016
+ ${summary}`
6017
+ }
6018
+ }
6019
+ ).catch((err) => {
6020
+ console.error("Failed to notify main thread:", err);
6021
+ });
6022
+ mainAgent.updateAsyncTaskStatus(thread_id, "completed");
6023
+ }
6024
+ } catch (err) {
6025
+ console.error("Failed to notify main thread:", err);
6026
+ }
6027
+ }
5675
6028
  });
5676
6029
  agent.subscribeOnce("message:interrupted", (evt) => {
5677
6030
  eventBus2.publish(callback_event, {
@@ -5881,8 +6234,9 @@ import {
5881
6234
  loggerLatticeManager,
5882
6235
  sandboxLatticeManager as sandboxLatticeManager2,
5883
6236
  sqlDatabaseManager as sqlDatabaseManager2,
5884
- getStoreLattice as getStoreLattice12,
5885
- agentInstanceManager as agentInstanceManager7,
6237
+ getStoreLattice as getStoreLattice13,
6238
+ storeLatticeManager,
6239
+ agentInstanceManager as agentInstanceManager8,
5886
6240
  createSandboxProvider
5887
6241
  } from "@axiom-lattice/core";
5888
6242
  import {
@@ -6030,7 +6384,7 @@ var start = async (config) => {
6030
6384
  app.decorate("loggerLattice", loggerLattice);
6031
6385
  registerLatticeRoutes(app);
6032
6386
  try {
6033
- const storeLattice = getStoreLattice12("default", "database");
6387
+ const storeLattice = getStoreLattice13("default", "database");
6034
6388
  const store = storeLattice.store;
6035
6389
  sqlDatabaseManager2.setConfigStore(store);
6036
6390
  logger.info("Database config store set for SqlDatabaseManager");
@@ -6041,6 +6395,21 @@ var start = async (config) => {
6041
6395
  sandboxLatticeManager2.registerLattice("default", getConfiguredSandboxProvider());
6042
6396
  logger.info("Registered sandbox manager from env configuration");
6043
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 (storeLatticeManager.hasLattice("default", "workflowTracking")) {
6405
+ storeLatticeManager.removeLattice("default", "workflowTracking");
6406
+ }
6407
+ 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
+ }
6044
6413
  const target_port = config?.port || Number(process.env.PORT) || 4001;
6045
6414
  await app.listen({ port: target_port, host: "0.0.0.0" });
6046
6415
  logger.info(`Lattice Gateway is running on port: ${target_port}`);
@@ -6059,7 +6428,7 @@ var start = async (config) => {
6059
6428
  }
6060
6429
  try {
6061
6430
  logger.info("Starting agent instance recovery...");
6062
- const restoreStats = await agentInstanceManager7.restore();
6431
+ const restoreStats = await agentInstanceManager8.restore();
6063
6432
  logger.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
6064
6433
  } catch (error) {
6065
6434
  logger.error("Agent recovery failed", { error });