@axiom-lattice/gateway
v2.1.28
Published
API Gateway for LangGraph agent-based applications
Readme
Lattice Gateway
这是 Lattice 项目的 API 网关服务,提供了基于 Fastify 的 HTTP API 接口,用于与 Lattice Core 交互。
功能特点
- 基于 Fastify 的 HTTP API
- 代理调用服务
- 流式响应支持
- 事件总线
- 队列服务(基于 QueueLattice)
- 日志服务(基于 LoggerLattice,支持自定义配置)
安装
pnpm install启动服务
# 开发环境
pnpm dev
# 生产环境
pnpm build
pnpm startAPI 接口
Configuration API
The gateway supports dynamic configuration updates via JSON. You can update environment variables at runtime without restarting the server.
Get Configuration
GET /api/configReturns the current configuration (sensitive values are masked).
Update Configuration
PUT /api/config
Content-Type: application/json
{
"config": {
"port": 4001,
"queueServiceType": "redis",
"redisUrl": "redis://localhost:6379",
"redisPassword": "your-password",
"queueName": "tasks"
}
}Note: When updating queueServiceType, the queue service will be automatically reconfigured.
Example:
// Update configuration from frontend
const response = await fetch("http://localhost:4001/api/config", {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
config: {
queueServiceType: "redis",
redisUrl: "redis://localhost:6379",
redisPassword: "your-password",
},
}),
});
const result = await response.json();
console.log(result); // { success: true, message: "Configuration updated successfully", data: {...} }代理调用
POST /api/v1/run: 运行代理POST /api/v1/run/stream: 流式运行代理GET /api/v1/run/:thread_id: 获取运行状态GET /api/v1/run/:thread_id/messages: 获取消息历史
Logger 配置
Gateway 使用 Logger Lattice 进行日志管理,支持自定义日志配置。详细说明请参考 LOGGER_CONFIG.md。
快速开始
import { LatticeGateway } from "@axiom-lattice/gateway";
import { LoggerType } from "@axiom-lattice/protocols";
// 使用默认配置
LatticeGateway.startAsHttpEndpoint({
port: 4001,
});
// 自定义日志配置
LatticeGateway.startAsHttpEndpoint({
port: 4001,
loggerConfig: {
file: "./logs/my-app/gateway",
serviceName: "my-service",
},
});目录结构
src/config/: 配置文件src/controllers/: 控制器src/routes/: 路由定义src/services/: 服务实现src/types/: 类型定义LOGGER_CONFIG.md: Logger 配置详细文档
