feat(config): add api section with port and host defaults
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 8d075f40d25a
This commit is contained in:
parent
917f2e2628
commit
eda322e115
@ -32,3 +32,23 @@ describe('ConfigSchema - runMode and autoStart', () => {
|
||||
expect(() => ConfigSchema.parse({ ...baseConfig, runMode: 'invalid' })).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('ConfigSchema - api', () => {
|
||||
const baseConfig = {
|
||||
channels: { telegram: { enabled: false } },
|
||||
agents: { claude: { command: 'claude-agent-acp', args: [], env: {} } },
|
||||
defaultAgent: 'claude',
|
||||
}
|
||||
|
||||
it('defaults api.port to 21420 and api.host to 127.0.0.1', () => {
|
||||
const result = ConfigSchema.parse(baseConfig)
|
||||
expect(result.api.port).toBe(21420)
|
||||
expect(result.api.host).toBe('127.0.0.1')
|
||||
})
|
||||
|
||||
it('accepts custom api port', () => {
|
||||
const result = ConfigSchema.parse({ ...baseConfig, api: { port: 9999 } })
|
||||
expect(result.api.port).toBe(9999)
|
||||
expect(result.api.host).toBe('127.0.0.1')
|
||||
})
|
||||
})
|
||||
|
||||
@ -44,6 +44,10 @@ export const ConfigSchema = z.object({
|
||||
logging: LoggingSchema,
|
||||
runMode: z.enum(['foreground', 'daemon']).default('foreground'),
|
||||
autoStart: z.boolean().default(false),
|
||||
api: z.object({
|
||||
port: z.number().default(21420),
|
||||
host: z.string().default('127.0.0.1'),
|
||||
}).default({}),
|
||||
})
|
||||
|
||||
export type Config = z.infer<typeof ConfigSchema>
|
||||
@ -167,6 +171,7 @@ export class ConfigManager {
|
||||
['OPENACP_TELEGRAM_CHAT_ID', ['channels', 'telegram', 'chatId']],
|
||||
['OPENACP_DEFAULT_AGENT', ['defaultAgent']],
|
||||
['OPENACP_RUN_MODE', ['runMode']],
|
||||
['OPENACP_API_PORT', ['api', 'port']],
|
||||
]
|
||||
for (const [envVar, configPath] of overrides) {
|
||||
const value = process.env[envVar]
|
||||
@ -177,8 +182,8 @@ export class ConfigManager {
|
||||
target = target[configPath[i]]
|
||||
}
|
||||
const key = configPath[configPath.length - 1]
|
||||
// Convert chatId to number
|
||||
target[key] = key === 'chatId' ? Number(value) : value
|
||||
// Convert numeric fields to number
|
||||
target[key] = (key === 'chatId' || key === 'port') ? Number(value) : value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user