@axiom-lattice/gateway 2.1.19 → 2.1.21

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.js CHANGED
@@ -1339,6 +1339,311 @@ async function getHealth(request, reply) {
1339
1339
  }
1340
1340
  }
1341
1341
 
1342
+ // src/controllers/skills.ts
1343
+ var import_core9 = require("@axiom-lattice/core");
1344
+ var import_core10 = require("@axiom-lattice/core");
1345
+ function serializeSkill(skill) {
1346
+ const serialized = {
1347
+ id: skill.id,
1348
+ name: skill.name,
1349
+ description: skill.description,
1350
+ license: skill.license,
1351
+ compatibility: skill.compatibility,
1352
+ metadata: skill.metadata || {},
1353
+ content: skill.content,
1354
+ subSkills: skill.subSkills,
1355
+ createdAt: skill.createdAt instanceof Date ? skill.createdAt.toISOString() : skill.createdAt ? new Date(skill.createdAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
1356
+ updatedAt: skill.updatedAt instanceof Date ? skill.updatedAt.toISOString() : skill.updatedAt ? new Date(skill.updatedAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString()
1357
+ };
1358
+ Object.keys(serialized).forEach((key) => {
1359
+ if (serialized[key] === void 0) {
1360
+ delete serialized[key];
1361
+ }
1362
+ });
1363
+ return serialized;
1364
+ }
1365
+ async function getSkillList(request, reply) {
1366
+ try {
1367
+ const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1368
+ const skillStore = storeLattice.store;
1369
+ const skills = await skillStore.getAllSkills();
1370
+ const serializedSkills = skills.map(serializeSkill);
1371
+ return {
1372
+ success: true,
1373
+ message: "Successfully retrieved skill list",
1374
+ data: {
1375
+ records: serializedSkills,
1376
+ total: serializedSkills.length
1377
+ }
1378
+ };
1379
+ } catch (error) {
1380
+ return reply.status(500).send({
1381
+ success: false,
1382
+ message: `Failed to retrieve skills: ${error.message}`,
1383
+ data: {
1384
+ records: [],
1385
+ total: 0
1386
+ }
1387
+ });
1388
+ }
1389
+ }
1390
+ async function getSkill(request, reply) {
1391
+ try {
1392
+ const { id } = request.params;
1393
+ const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1394
+ const skillStore = storeLattice.store;
1395
+ const skill = await skillStore.getSkillById(id);
1396
+ if (!skill) {
1397
+ return reply.status(404).send({
1398
+ success: false,
1399
+ message: "Skill not found"
1400
+ });
1401
+ }
1402
+ return {
1403
+ success: true,
1404
+ message: "Successfully retrieved skill",
1405
+ data: serializeSkill(skill)
1406
+ };
1407
+ } catch (error) {
1408
+ return reply.status(500).send({
1409
+ success: false,
1410
+ message: `Failed to retrieve skill: ${error.message}`
1411
+ });
1412
+ }
1413
+ }
1414
+ async function createSkill(request, reply) {
1415
+ try {
1416
+ const data = request.body;
1417
+ if (!data.name) {
1418
+ return reply.status(400).send({
1419
+ success: false,
1420
+ message: "name is required"
1421
+ });
1422
+ }
1423
+ if (!data.description) {
1424
+ return reply.status(400).send({
1425
+ success: false,
1426
+ message: "description is required"
1427
+ });
1428
+ }
1429
+ try {
1430
+ (0, import_core10.validateSkillName)(data.name);
1431
+ } catch (error) {
1432
+ return reply.status(400).send({
1433
+ success: false,
1434
+ message: error.message || "Invalid skill name format"
1435
+ });
1436
+ }
1437
+ const id = request.body.id || data.name;
1438
+ if (id !== data.name) {
1439
+ return reply.status(400).send({
1440
+ success: false,
1441
+ message: `id "${id}" must equal name "${data.name}" (name is used for path addressing)`
1442
+ });
1443
+ }
1444
+ const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1445
+ const skillStore = storeLattice.store;
1446
+ const exists = await skillStore.hasSkill(id);
1447
+ if (exists) {
1448
+ return reply.status(409).send({
1449
+ success: false,
1450
+ message: `Skill with id "${id}" already exists`
1451
+ });
1452
+ }
1453
+ const newSkill = await skillStore.createSkill(id, data);
1454
+ return reply.status(201).send({
1455
+ success: true,
1456
+ message: "Successfully created skill",
1457
+ data: serializeSkill(newSkill)
1458
+ });
1459
+ } catch (error) {
1460
+ return reply.status(500).send({
1461
+ success: false,
1462
+ message: `Failed to create skill: ${error.message}`
1463
+ });
1464
+ }
1465
+ }
1466
+ async function updateSkill(request, reply) {
1467
+ try {
1468
+ const { id } = request.params;
1469
+ const updates = request.body;
1470
+ if (updates.name !== void 0) {
1471
+ try {
1472
+ (0, import_core10.validateSkillName)(updates.name);
1473
+ } catch (error) {
1474
+ return reply.status(400).send({
1475
+ success: false,
1476
+ message: error.message || "Invalid skill name format"
1477
+ });
1478
+ }
1479
+ }
1480
+ const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1481
+ const skillStore = storeLattice.store;
1482
+ const exists = await skillStore.hasSkill(id);
1483
+ if (!exists) {
1484
+ return reply.status(404).send({
1485
+ success: false,
1486
+ message: "Skill not found"
1487
+ });
1488
+ }
1489
+ const updatedSkill = await skillStore.updateSkill(id, updates);
1490
+ if (!updatedSkill) {
1491
+ return reply.status(500).send({
1492
+ success: false,
1493
+ message: "Failed to update skill"
1494
+ });
1495
+ }
1496
+ return {
1497
+ success: true,
1498
+ message: "Successfully updated skill",
1499
+ data: serializeSkill(updatedSkill)
1500
+ };
1501
+ } catch (error) {
1502
+ return reply.status(500).send({
1503
+ success: false,
1504
+ message: `Failed to update skill: ${error.message}`
1505
+ });
1506
+ }
1507
+ }
1508
+ async function deleteSkill(request, reply) {
1509
+ try {
1510
+ const { id } = request.params;
1511
+ const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1512
+ const skillStore = storeLattice.store;
1513
+ const exists = await skillStore.hasSkill(id);
1514
+ if (!exists) {
1515
+ return reply.status(404).send({
1516
+ success: false,
1517
+ message: "Skill not found"
1518
+ });
1519
+ }
1520
+ const deleted = await skillStore.deleteSkill(id);
1521
+ if (!deleted) {
1522
+ return reply.status(500).send({
1523
+ success: false,
1524
+ message: "Failed to delete skill"
1525
+ });
1526
+ }
1527
+ return {
1528
+ success: true,
1529
+ message: "Successfully deleted skill"
1530
+ };
1531
+ } catch (error) {
1532
+ return reply.status(500).send({
1533
+ success: false,
1534
+ message: `Failed to delete skill: ${error.message}`
1535
+ });
1536
+ }
1537
+ }
1538
+ async function searchSkillsByMetadata(request, reply) {
1539
+ try {
1540
+ const { key, value } = request.query;
1541
+ if (!key || !value) {
1542
+ return reply.status(400).send({
1543
+ success: false,
1544
+ message: "key and value query parameters are required",
1545
+ data: {
1546
+ records: [],
1547
+ total: 0
1548
+ }
1549
+ });
1550
+ }
1551
+ const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1552
+ const skillStore = storeLattice.store;
1553
+ const skills = await skillStore.searchByMetadata(key, value);
1554
+ const serializedSkills = skills.map(serializeSkill);
1555
+ return {
1556
+ success: true,
1557
+ message: "Successfully searched skills",
1558
+ data: {
1559
+ records: serializedSkills,
1560
+ total: serializedSkills.length
1561
+ }
1562
+ };
1563
+ } catch (error) {
1564
+ return reply.status(500).send({
1565
+ success: false,
1566
+ message: `Failed to search skills: ${error.message}`,
1567
+ data: {
1568
+ records: [],
1569
+ total: 0
1570
+ }
1571
+ });
1572
+ }
1573
+ }
1574
+ async function filterSkillsByCompatibility(request, reply) {
1575
+ try {
1576
+ const { compatibility } = request.query;
1577
+ if (!compatibility) {
1578
+ return reply.status(400).send({
1579
+ success: false,
1580
+ message: "compatibility query parameter is required",
1581
+ data: {
1582
+ records: [],
1583
+ total: 0
1584
+ }
1585
+ });
1586
+ }
1587
+ const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1588
+ const skillStore = storeLattice.store;
1589
+ const skills = await skillStore.filterByCompatibility(compatibility);
1590
+ const serializedSkills = skills.map(serializeSkill);
1591
+ return {
1592
+ success: true,
1593
+ message: "Successfully filtered skills",
1594
+ data: {
1595
+ records: serializedSkills,
1596
+ total: serializedSkills.length
1597
+ }
1598
+ };
1599
+ } catch (error) {
1600
+ return reply.status(500).send({
1601
+ success: false,
1602
+ message: `Failed to filter skills: ${error.message}`,
1603
+ data: {
1604
+ records: [],
1605
+ total: 0
1606
+ }
1607
+ });
1608
+ }
1609
+ }
1610
+ async function filterSkillsByLicense(request, reply) {
1611
+ try {
1612
+ const { license } = request.query;
1613
+ if (!license) {
1614
+ return reply.status(400).send({
1615
+ success: false,
1616
+ message: "license query parameter is required",
1617
+ data: {
1618
+ records: [],
1619
+ total: 0
1620
+ }
1621
+ });
1622
+ }
1623
+ const storeLattice = (0, import_core9.getStoreLattice)("default", "skill");
1624
+ const skillStore = storeLattice.store;
1625
+ const skills = await skillStore.filterByLicense(license);
1626
+ const serializedSkills = skills.map(serializeSkill);
1627
+ return {
1628
+ success: true,
1629
+ message: "Successfully filtered skills",
1630
+ data: {
1631
+ records: serializedSkills,
1632
+ total: serializedSkills.length
1633
+ }
1634
+ };
1635
+ } catch (error) {
1636
+ return reply.status(500).send({
1637
+ success: false,
1638
+ message: `Failed to filter skills: ${error.message}`,
1639
+ data: {
1640
+ records: [],
1641
+ total: 0
1642
+ }
1643
+ });
1644
+ }
1645
+ }
1646
+
1342
1647
  // src/schemas/index.ts
1343
1648
  var getAllMemoryItemsSchema = {
1344
1649
  description: "Get all memory items for an assistant thread",
@@ -1698,144 +2003,35 @@ var registerLatticeRoutes = (app2) => {
1698
2003
  app2.post("/api/schedules/:taskId/cancel", cancelScheduledTask);
1699
2004
  app2.post("/api/schedules/:taskId/pause", pauseScheduledTask);
1700
2005
  app2.post("/api/schedules/:taskId/resume", resumeScheduledTask);
1701
- };
1702
-
1703
- // src/logger/Logger.ts
1704
- var import_pino = __toESM(require("pino"));
1705
- var import_pino_pretty = require("pino-pretty");
1706
- var import_pino_roll = require("pino-roll");
1707
- var PinoLoggerFactory = class _PinoLoggerFactory {
1708
- constructor() {
1709
- const isProd = process.env.NODE_ENV === "production";
1710
- const loggerConfig = {
1711
- // 自定义时间戳格式
1712
- timestamp: () => `,"@timestamp":"${(/* @__PURE__ */ new Date()).toISOString()}"`,
1713
- // 关闭默认的时间戳键
1714
- base: {
1715
- "@version": "1",
1716
- app_name: "lattice",
1717
- service_name: "lattice/graph-server",
1718
- thread_name: "main",
1719
- logger_name: "lattice-graph-logger"
1720
- },
1721
- formatters: {
1722
- level: (label, number) => {
1723
- return {
1724
- level: label.toUpperCase(),
1725
- level_value: number * 1e3
1726
- };
1727
- }
1728
- }
1729
- };
1730
- if (isProd) {
1731
- try {
1732
- this.pinoLogger = (0, import_pino.default)(
1733
- loggerConfig,
1734
- import_pino.default.transport({
1735
- target: "pino-roll",
1736
- options: {
1737
- file: "./logs/fin_ai_graph_server",
1738
- frequency: "daily",
1739
- mkdir: true
1740
- }
1741
- })
1742
- );
1743
- } catch (error) {
1744
- console.error(
1745
- "\u65E0\u6CD5\u521D\u59CB\u5316 pino-roll \u65E5\u5FD7\u8BB0\u5F55\u5668\uFF0C\u56DE\u9000\u5230\u63A7\u5236\u53F0\u65E5\u5FD7",
1746
- error
1747
- );
1748
- this.pinoLogger = (0, import_pino.default)({
1749
- ...loggerConfig,
1750
- transport: {
1751
- target: "pino-pretty",
1752
- options: {
1753
- colorize: true
1754
- }
1755
- }
1756
- });
1757
- }
1758
- } else {
1759
- this.pinoLogger = (0, import_pino.default)({
1760
- ...loggerConfig,
1761
- transport: {
1762
- target: "pino-pretty",
1763
- options: {
1764
- colorize: true
1765
- }
1766
- }
1767
- });
1768
- }
1769
- }
1770
- static getInstance() {
1771
- if (!_PinoLoggerFactory.instance) {
1772
- _PinoLoggerFactory.instance = new _PinoLoggerFactory();
1773
- }
1774
- return _PinoLoggerFactory.instance;
1775
- }
1776
- getPinoLogger() {
1777
- return this.pinoLogger;
1778
- }
1779
- };
1780
- var Logger = class _Logger {
1781
- constructor(options) {
1782
- this.context = options?.context || {};
1783
- this.name = options?.name || "lattice-graph-logger";
1784
- this.serviceName = options?.serviceName || "lattice/graph-server";
1785
- }
1786
- /**
1787
- * 获取合并了上下文的日志对象
1788
- * @param additionalContext 额外的上下文数据
1789
- * @returns 带有上下文的pino日志对象
1790
- */
1791
- getContextualLogger(additionalContext) {
1792
- const pinoLogger = PinoLoggerFactory.getInstance().getPinoLogger();
1793
- const contextObj = {
1794
- "x-user-id": this.context["x-user-id"] || "",
1795
- "x-tenant-id": this.context["x-tenant-id"] || "",
1796
- "x-request-id": this.context["x-request-id"] || "",
1797
- "x-task-id": this.context["x-task-id"] || "",
1798
- "x-thread-id": this.context["x-thread-id"] || "",
1799
- service_name: this.serviceName,
1800
- logger_name: this.name,
1801
- ...additionalContext
1802
- };
1803
- return pinoLogger.child(contextObj);
1804
- }
1805
- info(msg, obj) {
1806
- this.getContextualLogger(obj).info(msg);
1807
- }
1808
- error(msg, obj) {
1809
- this.getContextualLogger(obj).error(msg);
1810
- }
1811
- warn(msg, obj) {
1812
- this.getContextualLogger(obj).warn(msg);
1813
- }
1814
- debug(msg, obj) {
1815
- this.getContextualLogger(obj).debug(msg);
1816
- }
1817
- /**
1818
- * 更新Logger实例的上下文
1819
- */
1820
- updateContext(context) {
1821
- this.context = {
1822
- ...this.context,
1823
- ...context
1824
- };
1825
- }
1826
- /**
1827
- * 创建一个新的Logger实例,继承当前Logger的上下文
1828
- */
1829
- child(options) {
1830
- return new _Logger({
1831
- name: options.name || this.name,
1832
- serviceName: options.serviceName || this.serviceName,
1833
- context: {
1834
- ...this.context,
1835
- ...options.context
1836
- }
1837
- });
1838
- }
2006
+ app2.get("/api/skills", getSkillList);
2007
+ app2.get(
2008
+ "/api/skills/:id",
2009
+ getSkill
2010
+ );
2011
+ app2.post(
2012
+ "/api/skills",
2013
+ createSkill
2014
+ );
2015
+ app2.put(
2016
+ "/api/skills/:id",
2017
+ updateSkill
2018
+ );
2019
+ app2.delete(
2020
+ "/api/skills/:id",
2021
+ deleteSkill
2022
+ );
2023
+ app2.get(
2024
+ "/api/skills/search/metadata",
2025
+ searchSkillsByMetadata
2026
+ );
2027
+ app2.get(
2028
+ "/api/skills/filter/compatibility",
2029
+ filterSkillsByCompatibility
2030
+ );
2031
+ app2.get(
2032
+ "/api/skills/filter/license",
2033
+ filterSkillsByLicense
2034
+ );
1839
2035
  };
1840
2036
 
1841
2037
  // src/swagger.ts
@@ -1901,7 +2097,7 @@ var configureSwagger = async (app2, customSwaggerConfig, customSwaggerUiConfig)
1901
2097
  };
1902
2098
 
1903
2099
  // src/services/agent_task_consumer.ts
1904
- var import_core9 = require("@axiom-lattice/core");
2100
+ var import_core11 = require("@axiom-lattice/core");
1905
2101
  var handleAgentTask = async (taskRequest, retryCount = 0) => {
1906
2102
  const {
1907
2103
  assistant_id,
@@ -1965,7 +2161,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
1965
2161
  }
1966
2162
  if (callback_event) {
1967
2163
  const state = await agent_state({ assistant_id, thread_id });
1968
- import_core9.eventBus.publish(callback_event, {
2164
+ import_core11.eventBus.publish(callback_event, {
1969
2165
  success: true,
1970
2166
  state,
1971
2167
  config: { assistant_id, thread_id, tenant_id }
@@ -1979,7 +2175,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
1979
2175
  await response.text();
1980
2176
  if (callback_event) {
1981
2177
  const state = await agent_state({ assistant_id, thread_id });
1982
- import_core9.eventBus.publish(callback_event, {
2178
+ import_core11.eventBus.publish(callback_event, {
1983
2179
  success: true,
1984
2180
  state,
1985
2181
  config: { assistant_id, thread_id, tenant_id }
@@ -2006,7 +2202,7 @@ var handleAgentTask = async (taskRequest, retryCount = 0) => {
2006
2202
  return handleAgentTask(taskRequest, nextRetryCount);
2007
2203
  }
2008
2204
  if (callback_event) {
2009
- import_core9.eventBus.publish(callback_event, {
2205
+ import_core11.eventBus.publish(callback_event, {
2010
2206
  success: false,
2011
2207
  error: error instanceof Error ? error.message : String(error),
2012
2208
  config: { assistant_id, thread_id, tenant_id }
@@ -2044,7 +2240,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
2044
2240
  * 初始化事件监听和队列轮询
2045
2241
  */
2046
2242
  initialize() {
2047
- import_core9.eventBus.subscribe(import_core9.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
2243
+ import_core11.eventBus.subscribe(import_core11.AGENT_TASK_EVENT, this.trigger_agent_task.bind(this));
2048
2244
  this.startPollingQueue();
2049
2245
  console.log("Agent\u4EFB\u52A1\u6D88\u8D39\u8005\u5DF2\u542F\u52A8\u5E76\u76D1\u542C\u4EFB\u52A1\u4E8B\u4EF6\u548C\u961F\u5217");
2050
2246
  }
@@ -2163,7 +2359,7 @@ var _AgentTaskConsumer = class _AgentTaskConsumer {
2163
2359
  handleAgentTask(taskRequest).catch((error) => {
2164
2360
  console.error("\u5904\u7406Agent\u4EFB\u52A1\u65F6\u53D1\u751F\u672A\u6355\u83B7\u7684\u9519\u8BEF:", error);
2165
2361
  if (taskRequest.callback_event) {
2166
- import_core9.eventBus.publish(taskRequest.callback_event, {
2362
+ import_core11.eventBus.publish(taskRequest.callback_event, {
2167
2363
  success: false,
2168
2364
  error: error instanceof Error ? error.message : String(error),
2169
2365
  config: {
@@ -2183,13 +2379,27 @@ _AgentTaskConsumer.agent_run_endpoint = "http://localhost:4001/api/runs";
2183
2379
  var AgentTaskConsumer = _AgentTaskConsumer;
2184
2380
 
2185
2381
  // src/index.ts
2382
+ var import_core12 = require("@axiom-lattice/core");
2383
+ var import_protocols2 = require("@axiom-lattice/protocols");
2186
2384
  process.on("unhandledRejection", (reason, promise) => {
2187
2385
  console.error("\u672A\u5904\u7406\u7684Promise\u62D2\u7EDD:", reason);
2188
2386
  });
2189
- var logger = new Logger({
2190
- serviceName: "lattice-gateway",
2191
- name: "fastify-server"
2192
- });
2387
+ var DEFAULT_LOGGER_CONFIG = {
2388
+ name: "default",
2389
+ description: "Default logger for lattice-gateway service",
2390
+ type: import_protocols2.LoggerType.PINO,
2391
+ serviceName: "lattice/gateway",
2392
+ loggerName: "lattice/gateway"
2393
+ };
2394
+ var loggerLattice = initializeLogger(DEFAULT_LOGGER_CONFIG);
2395
+ var logger = loggerLattice.client;
2396
+ function initializeLogger(config) {
2397
+ if (import_core12.loggerLatticeManager.hasLattice("default")) {
2398
+ import_core12.loggerLatticeManager.removeLattice("default");
2399
+ }
2400
+ (0, import_core12.registerLoggerLattice)("default", config);
2401
+ return (0, import_core12.getLoggerLattice)("default");
2402
+ }
2193
2403
  var app = (0, import_fastify.default)({
2194
2404
  logger: false,
2195
2405
  // 禁用内置日志记录器
@@ -2197,17 +2407,33 @@ var app = (0, import_fastify.default)({
2197
2407
  // Default 50MB, configurable via BODY_LIMIT env var
2198
2408
  });
2199
2409
  app.addHook("onRequest", (request, reply, done) => {
2410
+ const getHeaderValue = (header) => {
2411
+ if (Array.isArray(header)) {
2412
+ return header[0];
2413
+ }
2414
+ return header;
2415
+ };
2200
2416
  const context = {
2201
- "x-tenant-id": request.headers["x-tenant-id"],
2202
- "x-request-id": request.headers["x-request-id"]
2417
+ "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
2418
+ "x-request-id": getHeaderValue(request.headers["x-request-id"])
2203
2419
  };
2420
+ if (loggerLattice.updateContext) {
2421
+ loggerLattice.updateContext(context);
2422
+ }
2204
2423
  done();
2205
2424
  });
2206
2425
  app.addHook("onResponse", (request, reply, done) => {
2426
+ const getHeaderValue = (header) => {
2427
+ if (Array.isArray(header)) {
2428
+ return header[0];
2429
+ }
2430
+ return header;
2431
+ };
2207
2432
  const context = {
2208
- "x-tenant-id": request.headers["x-tenant-id"],
2209
- "x-request-id": request.headers["x-request-id"]
2433
+ "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
2434
+ "x-request-id": getHeaderValue(request.headers["x-request-id"])
2210
2435
  };
2436
+ loggerLattice.info(`${request.method} ${request.url} - ${reply.statusCode}`);
2211
2437
  done();
2212
2438
  });
2213
2439
  app.register(import_cors.default, {
@@ -2225,9 +2451,15 @@ app.register(import_cors.default, {
2225
2451
  });
2226
2452
  app.register(import_sensible.default);
2227
2453
  app.setErrorHandler((error, request, reply) => {
2454
+ const getHeaderValue = (header) => {
2455
+ if (Array.isArray(header)) {
2456
+ return header[0];
2457
+ }
2458
+ return header;
2459
+ };
2228
2460
  const context = {
2229
- "x-tenant-id": request.headers["x-tenant-id"],
2230
- "x-request-id": request.headers["x-request-id"]
2461
+ "x-tenant-id": getHeaderValue(request.headers["x-tenant-id"]),
2462
+ "x-request-id": getHeaderValue(request.headers["x-request-id"])
2231
2463
  };
2232
2464
  logger.error(
2233
2465
  `\u8BF7\u6C42\u9519\u8BEF: ${request.method} ${request.url} error:${error.message}`,
@@ -2243,9 +2475,19 @@ app.setErrorHandler((error, request, reply) => {
2243
2475
  error: error.message || "\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEF"
2244
2476
  });
2245
2477
  });
2246
- app.decorate("logger", logger);
2247
2478
  var start = async (config) => {
2248
2479
  try {
2480
+ if (config?.loggerConfig) {
2481
+ const loggerConfig = {
2482
+ ...DEFAULT_LOGGER_CONFIG,
2483
+ ...config.loggerConfig,
2484
+ // Merge file config if provided
2485
+ file: config.loggerConfig.file || DEFAULT_LOGGER_CONFIG.file
2486
+ };
2487
+ loggerLattice = initializeLogger(loggerConfig);
2488
+ logger = loggerLattice.client;
2489
+ }
2490
+ app.decorate("loggerLattice", loggerLattice);
2249
2491
  const target_port = config?.port || Number(process.env.PORT) || 4001;
2250
2492
  await app.listen({ port: target_port, host: "0.0.0.0" });
2251
2493
  logger.info(`Lattice Gateway is running on port: ${target_port}`);