From 041f1afde007076257dea8d3a35e2aec17849247 Mon Sep 17 00:00:00 2001 From: Acbox Date: Thu, 29 Jan 2026 14:49:25 +0800 Subject: [PATCH] feat: add config load to agent gateway --- agent/package.json | 2 +- agent/src/config.ts | 14 ++++++++++++++ agent/src/index.ts | 8 +++++++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 agent/src/config.ts diff --git a/agent/package.json b/agent/package.json index fde59f2f..da792335 100644 --- a/agent/package.json +++ b/agent/package.json @@ -4,7 +4,7 @@ "scripts": { "dev": "bun run --watch src/index.ts", "build": "bun build src/index.ts --outfile dist/index.js --target bun --minify", - "start": "bun run dist/index.js" + "start": "pnpm run build && bun run dist/index.js" }, "dependencies": { "@ai-sdk/anthropic": "^3.0.9", diff --git a/agent/src/config.ts b/agent/src/config.ts new file mode 100644 index 00000000..4e0202b0 --- /dev/null +++ b/agent/src/config.ts @@ -0,0 +1,14 @@ +import { readFileSync } from 'fs' +import { parse } from 'toml' + +type AgentGatewayConfig = { + 'agent_gateway': { + host?: string + port?: number + } +} + +export const loadConfig = (path: string = './config.toml'): AgentGatewayConfig => { + const config = parse(readFileSync(path, 'utf-8')) + return config satisfies AgentGatewayConfig +} \ No newline at end of file diff --git a/agent/src/index.ts b/agent/src/index.ts index 2c5cca2c..60742b2a 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -2,12 +2,18 @@ import { Elysia } from 'elysia' import { chatModule } from './modules/chat' import { corsMiddleware } from './middlewares/cors' import { errorMiddleware } from './middlewares/error' +import { loadConfig } from './config' + +const config = loadConfig('../config.toml') const app = new Elysia() .use(corsMiddleware) .use(errorMiddleware) .use(chatModule) - .listen(8081) + .listen({ + port: config.agent_gateway.port ?? 8081, + hostname: config.agent_gateway.host ?? '127.0.0.1', + }) console.log( `Agent Gateway is running at ${app.server?.hostname}:${app.server?.port}`