feat: add config load to agent gateway

This commit is contained in:
Acbox
2026-01-29 14:49:25 +08:00
parent a8441a7fde
commit 041f1afde0
3 changed files with 22 additions and 2 deletions
+1 -1
View File
@@ -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",
+14
View File
@@ -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
}
+7 -1
View File
@@ -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}`