diff --git a/src/__tests__/config-schema.test.ts b/src/__tests__/config-schema.test.ts index 1208510..024189e 100644 --- a/src/__tests__/config-schema.test.ts +++ b/src/__tests__/config-schema.test.ts @@ -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') + }) +}) diff --git a/src/core/config.ts b/src/core/config.ts index a1d8fe6..254353f 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -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 @@ -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 } }