mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
feat: add config load to agent gateway
This commit is contained in:
+1
-1
@@ -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",
|
||||
|
||||
@@ -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
@@ -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}`
|
||||
|
||||
Reference in New Issue
Block a user