47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { Body, Controller, Headers, Post } from '@nestjs/common';
|
|
import { CurrentUser } from '../../common/auth/current-user.decorator';
|
|
import type { CurrentUser as ResolvedCurrentUser } from '../../common/auth/auth-context.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,
|
|
) {}
|
|
|
|
@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,
|
|
@CurrentUser() user: ResolvedCurrentUser | null,
|
|
@Headers('x-ftb-user-id') headerUserId?: string,
|
|
@Headers('x-user-id') legacyHeaderUserId?: string,
|
|
): Promise<AnalysisResponse> {
|
|
return this.businessAnalysisService.analyze(dto, {
|
|
id: user?.id ?? headerUserId ?? legacyHeaderUserId ?? '',
|
|
permissions: dto.permissions ?? [],
|
|
});
|
|
}
|
|
}
|