@axiom-lattice/gateway 1.0.20

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 ADDED
@@ -0,0 +1,718 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ LatticeGateway: () => LatticeGateway
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_fastify = __toESM(require("fastify"));
37
+ var import_cors = __toESM(require("@fastify/cors"));
38
+ var import_sensible = __toESM(require("@fastify/sensible"));
39
+
40
+ // src/config/index.ts
41
+ var import_dotenv = __toESM(require("dotenv"));
42
+ var import_path = __toESM(require("path"));
43
+ import_dotenv.default.config({ path: import_path.default.resolve(__dirname, "../../.env") });
44
+ var config = {
45
+ server: {
46
+ port: process.env.PORT || 4001,
47
+ env: process.env.NODE_ENV || "development"
48
+ },
49
+ supabase: {
50
+ url: process.env.SUPABASE_URL || "",
51
+ key: process.env.SUPABASE_KEY || ""
52
+ },
53
+ // langgraph: {
54
+ // apiKey: process.env.LANGGRAPH_API_KEY || "dummy_key",
55
+ // },
56
+ webhook: {
57
+ url: process.env.WEBHOOK_URL || ""
58
+ },
59
+ // java_api_url: process.env.JAVA_API_URL || "",
60
+ // common_api_url: process.env.COMMON_API_URL || "",
61
+ // azure_openai_api_key: process.env.AZURE_OPENAI_API_KEY || "",
62
+ database_url: process.env.DATABASE_URL || ""
63
+ };
64
+ var validateConfig = () => {
65
+ };
66
+
67
+ // src/services/agent_service.ts
68
+ var import_messages = require("@langchain/core/messages");
69
+ var import_langgraph = require("@langchain/langgraph");
70
+ var import_uuid = require("uuid");
71
+ var import_core = require("@axiom-lattice/core");
72
+ async function agent_invoke({
73
+ input,
74
+ thread_id,
75
+ assistant_id,
76
+ tenant_id,
77
+ command,
78
+ run_id
79
+ }) {
80
+ const runnable_agent = (0, import_core.getAgentLattice)(assistant_id)?.client;
81
+ const { files, message, ...rest } = input;
82
+ const humanMessage = new import_messages.HumanMessage(message || "");
83
+ humanMessage.additional_kwargs = { files };
84
+ const messages = [humanMessage];
85
+ if (!runnable_agent) {
86
+ throw new Error(`Agent ${assistant_id} not found`);
87
+ }
88
+ const result = await runnable_agent.invoke(
89
+ command ? new import_langgraph.Command(command) : { ...rest, messages, "x-tenant-id": tenant_id },
90
+ {
91
+ configurable: {
92
+ thread_id,
93
+ run_id: run_id || (0, import_uuid.v4)(),
94
+ recursionLimit: 200,
95
+ "x-tenant-id": tenant_id,
96
+ "x-request-id": run_id,
97
+ "x-thread-id": thread_id
98
+ }
99
+ }
100
+ );
101
+ return result;
102
+ }
103
+ async function agent_stream({
104
+ input,
105
+ thread_id,
106
+ command,
107
+ tenant_id,
108
+ assistant_id,
109
+ run_id
110
+ }) {
111
+ const runnable_agent = (0, import_core.getAgentClient)(assistant_id);
112
+ const { files, message, ...rest } = input;
113
+ let messages = [];
114
+ if (!command) {
115
+ const humanMessage = new import_messages.HumanMessage(message);
116
+ humanMessage.additional_kwargs = { files };
117
+ messages = [humanMessage];
118
+ }
119
+ try {
120
+ if (!runnable_agent) {
121
+ throw new Error(`Agent ${assistant_id} not found`);
122
+ }
123
+ const agentStream = await runnable_agent.stream(
124
+ command ? new import_langgraph.Command(command) : {
125
+ ...rest,
126
+ messages,
127
+ "x-tenant-id": tenant_id
128
+ },
129
+ {
130
+ configurable: {
131
+ thread_id,
132
+ run_id: run_id || (0, import_uuid.v4)(),
133
+ "x-tenant-id": tenant_id,
134
+ "x-request-id": run_id,
135
+ "x-thread-id": thread_id
136
+ },
137
+ streamMode: ["updates", "messages"],
138
+ subgraphs: false
139
+ }
140
+ );
141
+ return {
142
+ [Symbol.asyncIterator]: async function* () {
143
+ try {
144
+ for await (const chunk of agentStream) {
145
+ let data;
146
+ if (chunk[0] === "messages") {
147
+ const messages2 = chunk[1];
148
+ data = messages2?.[0]?.toDict();
149
+ }
150
+ if (chunk?.[1]?.__interrupt__) {
151
+ data = chunk?.[1]?.[0]?.toDict();
152
+ }
153
+ if (data) {
154
+ console.log(data);
155
+ yield data;
156
+ }
157
+ }
158
+ } catch (error) {
159
+ console.error("Stream error:", error);
160
+ throw error;
161
+ }
162
+ }
163
+ };
164
+ } catch (error) {
165
+ throw error;
166
+ }
167
+ }
168
+ async function agent_state({
169
+ thread_id,
170
+ assistant_id
171
+ }) {
172
+ const runnable_agent = (0, import_core.getAgentClient)(assistant_id);
173
+ if (!runnable_agent) {
174
+ throw new Error(`Agent ${assistant_id} not found`);
175
+ }
176
+ const state = await runnable_agent.getState({
177
+ configurable: { thread_id, subgraphs: false }
178
+ });
179
+ return state;
180
+ }
181
+ async function agent_messages({
182
+ thread_id,
183
+ tenant_id,
184
+ assistant_id
185
+ }) {
186
+ const runnable_agent = (0, import_core.getAgentClient)(assistant_id);
187
+ if (!runnable_agent) {
188
+ throw new Error(`Agent ${assistant_id} not found`);
189
+ }
190
+ const state = await runnable_agent.getState({
191
+ configurable: { thread_id, subgraphs: false }
192
+ });
193
+ const messages = state.values.messages || [];
194
+ const filteredMessages = (0, import_messages.filterMessages)(messages, {
195
+ includeTypes: ["ai", "human", "tool"]
196
+ //["human", "ai", "tool"],
197
+ });
198
+ let messagesArray = filteredMessages.map((message) => ({
199
+ id: message.id,
200
+ role: message.getType(),
201
+ content: message.content,
202
+ files: message.additional_kwargs.files,
203
+ ...message.lc_kwargs
204
+ }));
205
+ const action_messages = state.tasks.flatMap((task) => {
206
+ return task.interrupts.map((interrupt) => {
207
+ return {
208
+ role: "ai",
209
+ content: interrupt.value,
210
+ type: "action"
211
+ };
212
+ });
213
+ });
214
+ const new_messages = [...messagesArray, ...action_messages];
215
+ return new_messages;
216
+ }
217
+ async function draw_graph(assistant_id) {
218
+ const runnable_agent = (0, import_core.getAgentClient)(assistant_id);
219
+ if (!runnable_agent) {
220
+ throw new Error(`Agent ${assistant_id} not found`);
221
+ }
222
+ const drawableGraph = await runnable_agent.getGraphAsync();
223
+ const image = await drawableGraph.drawMermaid();
224
+ return image;
225
+ }
226
+
227
+ // src/controllers/run.ts
228
+ var import_uuid2 = require("uuid");
229
+ var createRun = async (request, reply) => {
230
+ try {
231
+ const {
232
+ assistant_id,
233
+ thread_id,
234
+ command,
235
+ streaming,
236
+ background,
237
+ ...input
238
+ } = request.body;
239
+ const tenant_id = request.headers["x-tenant-id"];
240
+ const x_request_id = request.headers["x-request-id"] || (0, import_uuid2.v4)();
241
+ if (!assistant_id) {
242
+ reply.status(400).send({
243
+ success: false,
244
+ error: "\u52A9\u624BID\u662F\u5FC5\u9700\u7684"
245
+ });
246
+ return;
247
+ }
248
+ if (streaming) {
249
+ const stream = await agent_stream({
250
+ assistant_id,
251
+ input,
252
+ thread_id,
253
+ command,
254
+ tenant_id,
255
+ run_id: x_request_id
256
+ });
257
+ reply.raw.writeHead(200, {
258
+ "Content-Type": "text/event-stream",
259
+ "Cache-Control": "no-cache",
260
+ Connection: "keep-alive",
261
+ "Access-Control-Allow-Origin": "*"
262
+ });
263
+ try {
264
+ for await (const chunk of stream) {
265
+ reply.raw.write(`data: ${JSON.stringify(chunk)}
266
+
267
+ `);
268
+ }
269
+ } catch (error) {
270
+ } finally {
271
+ reply.raw.end();
272
+ return reply.hijack();
273
+ }
274
+ } else {
275
+ const result = await agent_invoke({
276
+ assistant_id,
277
+ input,
278
+ command,
279
+ thread_id,
280
+ tenant_id,
281
+ run_id: x_request_id
282
+ });
283
+ reply.status(200).send(result);
284
+ }
285
+ } catch (error) {
286
+ reply.status(500).send({
287
+ success: false,
288
+ error: `\u521B\u5EFA\u8FD0\u884C\u65F6\u53D1\u751F\u9519\u8BEF: ${error.message}`
289
+ });
290
+ }
291
+ };
292
+
293
+ // src/controllers/memory.ts
294
+ var setMemoryItem = async (request, reply) => {
295
+ try {
296
+ const { assistantId, key } = request.params;
297
+ const value = request.body;
298
+ if (!assistantId || !key) {
299
+ reply.status(400).send({
300
+ success: false,
301
+ error: "\u52A9\u624BID\u548C\u952E\u662F\u5FC5\u9700\u7684"
302
+ });
303
+ return;
304
+ }
305
+ if (value === void 0) {
306
+ reply.status(400).send({
307
+ success: false,
308
+ error: "\u503C\u662F\u5FC5\u9700\u7684"
309
+ });
310
+ return;
311
+ }
312
+ reply.status(500).send();
313
+ return;
314
+ } catch (error) {
315
+ reply.status(500).send({
316
+ success: false,
317
+ error: `\u8BBE\u7F6E\u5185\u5B58\u9879\u65F6\u53D1\u751F\u9519\u8BEF: ${error.message}`
318
+ });
319
+ }
320
+ };
321
+ var getMemoryItem = async (request, reply) => {
322
+ try {
323
+ const { assistantId, key } = request.params;
324
+ if (!assistantId || !key) {
325
+ reply.status(400).send({
326
+ success: false,
327
+ error: "\u52A9\u624BID\u548C\u952E\u662F\u5FC5\u9700\u7684"
328
+ });
329
+ return;
330
+ }
331
+ reply.status(404).send();
332
+ return;
333
+ } catch (error) {
334
+ reply.status(500).send({
335
+ success: false,
336
+ error: `\u83B7\u53D6\u5185\u5B58\u9879\u65F6\u53D1\u751F\u9519\u8BEF: ${error.message}`
337
+ });
338
+ }
339
+ };
340
+ var getAllMemoryItems = async (request, reply) => {
341
+ try {
342
+ const { assistantId, thread_id } = request.params;
343
+ const tenant_id = request.headers["x-tenant-id"];
344
+ if (!thread_id) {
345
+ reply.status(400).send({
346
+ success: false,
347
+ error: "\u7EBF\u7A0BID\u662F\u5FC5\u9700\u7684"
348
+ });
349
+ return;
350
+ }
351
+ if (!assistantId) {
352
+ reply.status(400).send({
353
+ success: false,
354
+ error: "\u52A9\u624BID\u662F\u5FC5\u9700\u7684"
355
+ });
356
+ return;
357
+ }
358
+ const result = await agent_messages({
359
+ assistant_id: assistantId,
360
+ thread_id,
361
+ tenant_id
362
+ });
363
+ if (!result) {
364
+ reply.status(500).send(result);
365
+ return;
366
+ }
367
+ reply.send(result);
368
+ } catch (error) {
369
+ reply.status(500).send({
370
+ success: false,
371
+ error: `\u83B7\u53D6\u6240\u6709\u5185\u5B58\u9879\u65F6\u53D1\u751F\u9519\u8BEF: ${error.message}`
372
+ });
373
+ }
374
+ };
375
+ var getAgentState = async (request, reply) => {
376
+ try {
377
+ const { assistantId, thread_id } = request.params;
378
+ if (!thread_id) {
379
+ reply.status(400).send({
380
+ success: false,
381
+ error: "\u7EBF\u7A0BID\u662F\u5FC5\u9700\u7684"
382
+ });
383
+ return;
384
+ }
385
+ if (!assistantId) {
386
+ reply.status(400).send({
387
+ success: false,
388
+ error: "\u52A9\u624BID\u662F\u5FC5\u9700\u7684"
389
+ });
390
+ return;
391
+ }
392
+ const result = await agent_state({
393
+ assistant_id: assistantId,
394
+ thread_id
395
+ });
396
+ if (!result) {
397
+ reply.status(500).send(result);
398
+ return;
399
+ }
400
+ reply.send(result);
401
+ } catch (error) {
402
+ reply.status(500).send({
403
+ success: false,
404
+ error: `\u83B7\u53D6\u52A9\u624B\u72B6\u6001\u65F6\u53D1\u751F\u9519\u8BEF: ${error.message}`
405
+ });
406
+ }
407
+ };
408
+ var deleteMemoryItem = async (request, reply) => {
409
+ try {
410
+ const { assistantId, key } = request.params;
411
+ if (!assistantId || !key) {
412
+ reply.status(400).send({
413
+ success: false,
414
+ error: "\u52A9\u624BID\u548C\u952E\u662F\u5FC5\u9700\u7684"
415
+ });
416
+ return;
417
+ }
418
+ reply.status(500).send();
419
+ return;
420
+ reply.status(204).send();
421
+ } catch (error) {
422
+ reply.status(500).send({
423
+ success: false,
424
+ error: `\u5220\u9664\u5185\u5B58\u9879\u65F6\u53D1\u751F\u9519\u8BEF: ${error.message}`
425
+ });
426
+ }
427
+ };
428
+ var clearMemory = async (request, reply) => {
429
+ try {
430
+ const { assistantId } = request.params;
431
+ if (!assistantId) {
432
+ reply.status(400).send({
433
+ success: false,
434
+ error: "\u52A9\u624BID\u662F\u5FC5\u9700\u7684"
435
+ });
436
+ return;
437
+ }
438
+ let result;
439
+ if (!result.success) {
440
+ reply.status(500).send(result);
441
+ return;
442
+ }
443
+ reply.status(204).send();
444
+ } catch (error) {
445
+ reply.status(500).send({
446
+ success: false,
447
+ error: `\u6E05\u9664\u5185\u5B58\u65F6\u53D1\u751F\u9519\u8BEF: ${error.message}`
448
+ });
449
+ }
450
+ };
451
+
452
+ // src/controllers/assistant.ts
453
+ var getAgentGraph = async (request, reply) => {
454
+ try {
455
+ const { assistantId } = request.params;
456
+ const imageData = await draw_graph(assistantId);
457
+ reply.header("Content-Type", "application/json").send({
458
+ image: imageData
459
+ });
460
+ } catch (error) {
461
+ reply.status(500).send({
462
+ success: false,
463
+ error: error.message || "\u83B7\u53D6\u4EE3\u7406\u56FE\u8868\u5931\u8D25"
464
+ });
465
+ }
466
+ };
467
+
468
+ // src/routes/index.ts
469
+ var registerRoutes = (app2) => {
470
+ app2.post("/api/runs", createRun);
471
+ app2.get(
472
+ "/api/assistants/:assistantId/:thread_id/memory",
473
+ getAllMemoryItems
474
+ );
475
+ app2.get(
476
+ "/api/assistants/:assistantId/:thread_id/state",
477
+ getAgentState
478
+ );
479
+ app2.get(
480
+ "/api/assistants/:assistantId/memory/:key",
481
+ getMemoryItem
482
+ );
483
+ app2.put(
484
+ "/api/assistants/:assistantId/memory/:key",
485
+ setMemoryItem
486
+ );
487
+ app2.delete(
488
+ "/api/assistants/:assistantId/memory/:key",
489
+ deleteMemoryItem
490
+ );
491
+ app2.delete("/api/assistants/:assistantId/memory", clearMemory);
492
+ app2.get("/api/assistants/:assistantId/graph", getAgentGraph);
493
+ };
494
+
495
+ // src/logger/Logger.ts
496
+ var import_pino = __toESM(require("pino"));
497
+ var import_pino_pretty = require("pino-pretty");
498
+ var import_pino_roll = require("pino-roll");
499
+ var PinoLoggerFactory = class _PinoLoggerFactory {
500
+ constructor() {
501
+ const isProd = process.env.NODE_ENV === "production";
502
+ const loggerConfig = {
503
+ // 自定义时间戳格式
504
+ timestamp: () => `,"@timestamp":"${(/* @__PURE__ */ new Date()).toISOString()}"`,
505
+ // 关闭默认的时间戳键
506
+ base: {
507
+ "@version": "1",
508
+ app_name: "lattice",
509
+ service_name: "lattice/graph-server",
510
+ thread_name: "main",
511
+ logger_name: "lattice-graph-logger"
512
+ },
513
+ formatters: {
514
+ level: (label, number) => {
515
+ return {
516
+ level: label.toUpperCase(),
517
+ level_value: number * 1e3
518
+ };
519
+ }
520
+ }
521
+ };
522
+ if (isProd) {
523
+ try {
524
+ this.pinoLogger = (0, import_pino.default)(
525
+ loggerConfig,
526
+ import_pino.default.transport({
527
+ target: "pino-roll",
528
+ options: {
529
+ file: "./logs/fin_ai_graph_server",
530
+ frequency: "daily",
531
+ mkdir: true
532
+ }
533
+ })
534
+ );
535
+ } catch (error) {
536
+ console.error(
537
+ "\u65E0\u6CD5\u521D\u59CB\u5316 pino-roll \u65E5\u5FD7\u8BB0\u5F55\u5668\uFF0C\u56DE\u9000\u5230\u63A7\u5236\u53F0\u65E5\u5FD7",
538
+ error
539
+ );
540
+ this.pinoLogger = (0, import_pino.default)({
541
+ ...loggerConfig,
542
+ transport: {
543
+ target: "pino-pretty",
544
+ options: {
545
+ colorize: true
546
+ }
547
+ }
548
+ });
549
+ }
550
+ } else {
551
+ this.pinoLogger = (0, import_pino.default)({
552
+ ...loggerConfig,
553
+ transport: {
554
+ target: "pino-pretty",
555
+ options: {
556
+ colorize: true
557
+ }
558
+ }
559
+ });
560
+ }
561
+ }
562
+ static getInstance() {
563
+ if (!_PinoLoggerFactory.instance) {
564
+ _PinoLoggerFactory.instance = new _PinoLoggerFactory();
565
+ }
566
+ return _PinoLoggerFactory.instance;
567
+ }
568
+ getPinoLogger() {
569
+ return this.pinoLogger;
570
+ }
571
+ };
572
+ var Logger = class _Logger {
573
+ constructor(options) {
574
+ this.context = options?.context || {};
575
+ this.name = options?.name || "lattice-graph-logger";
576
+ this.serviceName = options?.serviceName || "lattice/graph-server";
577
+ }
578
+ /**
579
+ * 获取合并了上下文的日志对象
580
+ * @param additionalContext 额外的上下文数据
581
+ * @returns 带有上下文的pino日志对象
582
+ */
583
+ getContextualLogger(additionalContext) {
584
+ const pinoLogger = PinoLoggerFactory.getInstance().getPinoLogger();
585
+ const contextObj = {
586
+ "x-user-id": this.context["x-user-id"] || "",
587
+ "x-tenant-id": this.context["x-tenant-id"] || "",
588
+ "x-request-id": this.context["x-request-id"] || "",
589
+ "x-task-id": this.context["x-task-id"] || "",
590
+ "x-thread-id": this.context["x-thread-id"] || "",
591
+ service_name: this.serviceName,
592
+ logger_name: this.name,
593
+ ...additionalContext
594
+ };
595
+ return pinoLogger.child(contextObj);
596
+ }
597
+ info(msg, obj) {
598
+ this.getContextualLogger(obj).info(msg);
599
+ }
600
+ error(msg, obj) {
601
+ this.getContextualLogger(obj).error(msg);
602
+ }
603
+ warn(msg, obj) {
604
+ this.getContextualLogger(obj).warn(msg);
605
+ }
606
+ debug(msg, obj) {
607
+ this.getContextualLogger(obj).debug(msg);
608
+ }
609
+ /**
610
+ * 更新Logger实例的上下文
611
+ */
612
+ updateContext(context) {
613
+ this.context = {
614
+ ...this.context,
615
+ ...context
616
+ };
617
+ }
618
+ /**
619
+ * 创建一个新的Logger实例,继承当前Logger的上下文
620
+ */
621
+ child(options) {
622
+ return new _Logger({
623
+ name: options.name || this.name,
624
+ serviceName: options.serviceName || this.serviceName,
625
+ context: {
626
+ ...this.context,
627
+ ...options.context
628
+ }
629
+ });
630
+ }
631
+ };
632
+
633
+ // src/index.ts
634
+ process.on("unhandledRejection", (reason, promise) => {
635
+ console.error("\u672A\u5904\u7406\u7684Promise\u62D2\u7EDD:", reason);
636
+ });
637
+ try {
638
+ validateConfig();
639
+ } catch (error) {
640
+ console.error("\u914D\u7F6E\u9519\u8BEF:", error.message);
641
+ process.exit(1);
642
+ }
643
+ var logger = new Logger({
644
+ serviceName: "lattice-gateway",
645
+ name: "fastify-server"
646
+ });
647
+ var app = (0, import_fastify.default)({
648
+ logger: false
649
+ // 禁用内置日志记录器
650
+ });
651
+ app.addHook("onRequest", (request, reply, done) => {
652
+ const context = {
653
+ "x-tenant-id": request.headers["x-tenant-id"],
654
+ "x-request-id": request.headers["x-request-id"]
655
+ };
656
+ done();
657
+ });
658
+ app.addHook("onResponse", (request, reply, done) => {
659
+ const context = {
660
+ "x-tenant-id": request.headers["x-tenant-id"],
661
+ "x-request-id": request.headers["x-request-id"]
662
+ };
663
+ done();
664
+ });
665
+ app.register(import_cors.default, {
666
+ origin: true,
667
+ methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
668
+ allowedHeaders: [
669
+ "Content-Type",
670
+ "Authorization",
671
+ "X-Requested-With",
672
+ "x-tenant-id",
673
+ "x-request-id"
674
+ ],
675
+ exposedHeaders: ["Content-Type"],
676
+ credentials: true
677
+ });
678
+ app.register(import_sensible.default);
679
+ app.setErrorHandler((error, request, reply) => {
680
+ const context = {
681
+ "x-tenant-id": request.headers["x-tenant-id"],
682
+ "x-request-id": request.headers["x-request-id"]
683
+ };
684
+ logger.error(
685
+ `\u8BF7\u6C42\u9519\u8BEF: ${request.method} ${request.url} error:${error.message}`,
686
+ {
687
+ ...context,
688
+ error: error.message,
689
+ stack: error.stack,
690
+ statusCode: error.statusCode || 500
691
+ }
692
+ );
693
+ reply.status(error.statusCode || 500).send({
694
+ success: false,
695
+ error: error.message || "\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEF"
696
+ });
697
+ });
698
+ app.decorate("logger", logger);
699
+ registerRoutes(app);
700
+ var start = async () => {
701
+ try {
702
+ const port = Number(config.server.port);
703
+ await app.listen({ port, host: "0.0.0.0" });
704
+ logger.info(`Lattice Gateway is running on port: ${port}`);
705
+ logger.info(`Environment: ${config.server.env}`);
706
+ } catch (err) {
707
+ logger.error("Server start failed", { error: err });
708
+ process.exit(1);
709
+ }
710
+ };
711
+ var LatticeGateway = {
712
+ startAsHttpEndpoint: start
713
+ };
714
+ // Annotate the CommonJS export names for ESM import in node:
715
+ 0 && (module.exports = {
716
+ LatticeGateway
717
+ });
718
+ //# sourceMappingURL=index.js.map