49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { Body, Controller, Post, Req } from '@nestjs/common';
|
|
import { AuthContextService, type AuthenticatedRequest } from '../../common/auth/auth-context.service';
|
|
import { PermissionService } from '../../common/auth/permission.service';
|
|
import { AiService } from './ai.service';
|
|
import { BusinessAnalysisService } from './analysis/business-analysis.service';
|
|
import { AnalysisDto } from './dto/analysis.dto';
|
|
import { DecomposeDto } from './dto/decompose.dto';
|
|
import { RiskInterpretDto } from './dto/risk-interpret.dto';
|
|
import type {
|
|
AgentDecomposeResponse,
|
|
AgentDecomposeError,
|
|
AgentRiskInterpretResponse,
|
|
AgentRiskInterpretError,
|
|
AnalysisResponse,
|
|
} from '@ftb/shared';
|
|
|
|
@Controller('ai')
|
|
export class AiController {
|
|
constructor(
|
|
private readonly aiService: AiService,
|
|
private readonly businessAnalysisService: BusinessAnalysisService,
|
|
private readonly authContext: AuthContextService,
|
|
private readonly permissionService: PermissionService,
|
|
) {}
|
|
|
|
@Post('decompose')
|
|
async decompose(@Body() dto: DecomposeDto): Promise<AgentDecomposeResponse | AgentDecomposeError> {
|
|
return this.aiService.decompose(dto);
|
|
}
|
|
|
|
@Post('risk-interpret')
|
|
async interpretRisk(@Body() dto: RiskInterpretDto): Promise<AgentRiskInterpretResponse | AgentRiskInterpretError> {
|
|
return this.aiService.interpretRisk(dto);
|
|
}
|
|
|
|
@Post('analysis')
|
|
async analyze(
|
|
@Body() dto: AnalysisDto,
|
|
@Req() request: AuthenticatedRequest,
|
|
): Promise<AnalysisResponse> {
|
|
const user = await this.authContext.resolveCurrentUser(request);
|
|
const permissions = await this.permissionService.resolveUserPermissions(user);
|
|
return this.businessAnalysisService.analyze(dto, {
|
|
id: user?.id ?? '',
|
|
permissions,
|
|
});
|
|
}
|
|
}
|