All files / src/platform/ai/controllers ai.controller.ts

0% Statements 0/17
0% Branches 0/4
0% Functions 0/5
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                                                                                                                       
import { Controller, Get, Post, Body, Param, Req } from '@nestjs/common';
import { AiService } from '../services/ai.service';
import {
  ApiTags,
  ApiBearerAuth,
  ApiOperation,
  ApiResponse,
} from '@nestjs/swagger';
 
@ApiTags('AI')
@ApiBearerAuth()
@Controller('api/v1/ai')
export class AiController {
  constructor(private readonly aiService: AiService) {}
 
  @Get('capabilities')
  @ApiOperation({ summary: 'List AI capabilities available for this tenant' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getCapabilities() {
    return {
      capabilities: [
        'text-generation',
        'structured-output',
        'summarization',
        'classification',
        'extraction',
        'embeddings',
      ],
    };
  }
 
  @Get('usage')
  @ApiOperation({ summary: 'Get AI usage statistics for the tenant' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getUsage(@Req() req: any) {
    return this.aiService.getUsage(req.user?.tenantId);
  }
 
  @Post('execute')
  @ApiOperation({ summary: 'Execute a registered AI prompt template' })
  @ApiResponse({ status: 201, description: 'Operation successful' })
  async execute(
    @Req() req: any,
    @Body()
    body: {
      promptKey: string;
      variables?: Record<string, string>;
      modelKey?: string;
    },
  ) {
    const tenantId = req.user?.tenantId;
    const result = await this.aiService.generateText(
      tenantId,
      body.promptKey,
      body.variables,
      body.modelKey,
    );
    return { result };
  }
 
  @Get('executions')
  @ApiOperation({ summary: 'Get AI execution history' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getExecutions(@Req() req: any) {
    return this.aiService.getUsage(req.user?.tenantId);
  }
}