it0/packages/services/agent-service/src/interfaces/rest/controllers/agent-config.controller.ts

76 lines
2.2 KiB
TypeScript

/**
* REST controller for per-tenant agent configuration (engine, prompt, turns, budget, tools).
*
* Endpoints (JWT validated by Kong gateway):
* GET /api/v1/agent-config → Get current tenant's config (returns defaults if none set)
* POST /api/v1/agent-config → Create new config
* PUT /api/v1/agent-config/:id → Update existing config
*/
import { Controller, Get, Post, Put, Body, Param } from '@nestjs/common';
import { TenantId } from '@it0/common';
import { AgentConfigService, UpdateAgentConfigDto } from '../../../infrastructure/services/agent-config.service';
@Controller('api/v1/agent-config')
export class AgentConfigController {
constructor(private readonly configService: AgentConfigService) {}
@Get()
async getConfig(@TenantId() tenantId: string) {
const config = await this.configService.findByTenantId(tenantId);
if (!config) {
return {
engine: 'claude-cli',
system_prompt: '',
max_turns: 10,
max_budget: 5.0,
allowed_tools: ['Bash', 'Read', 'Write', 'Glob', 'Grep'],
};
}
return {
id: config.id,
engine: config.engine,
system_prompt: config.systemPrompt,
max_turns: config.maxTurns,
max_budget: config.maxBudget,
allowed_tools: config.allowedTools,
};
}
@Post()
async createConfig(
@TenantId() tenantId: string,
@Body() dto: UpdateAgentConfigDto,
) {
const config = await this.configService.create(tenantId, dto);
return {
id: config.id,
engine: config.engine,
system_prompt: config.systemPrompt,
max_turns: config.maxTurns,
max_budget: config.maxBudget,
allowed_tools: config.allowedTools,
};
}
@Put(':id')
async updateConfig(
@TenantId() tenantId: string,
@Param('id') id: string,
@Body() dto: UpdateAgentConfigDto,
) {
const config = await this.configService.update(id, tenantId, dto);
if (!config) {
return { error: 'Config not found' };
}
return {
id: config.id,
engine: config.engine,
system_prompt: config.systemPrompt,
max_turns: config.maxTurns,
max_budget: config.maxBudget,
allowed_tools: config.allowedTools,
};
}
}