Files
CASAN/packages/casan-control-panel/backend/src/chat/chat.controller.ts
T

54 lines
1.7 KiB
TypeScript

import { Body, Controller, Get, Headers, Inject, Post, Query, Res } from '@nestjs/common';
import type { Response } from 'express';
import { ok } from '../common/api-response.js';
import { actorFromHeaders } from '../common/auth-context.js';
import { ChatAskInput, ChatService } from './chat.service.js';
@Controller('api/v1/chat')
export class ChatController {
constructor(@Inject(ChatService) private readonly svc: ChatService) {}
@Post('ask')
ask(@Headers() headers: Record<string, string | string[] | undefined>, @Body() body: ChatAskInput) {
return ok(this.svc.ask(body, actorFromHeaders(headers)));
}
@Post('ask/stream')
askStream(
@Headers() headers: Record<string, string | string[] | undefined>,
@Body() body: ChatAskInput,
@Res() res: Response,
) {
this.svc.streamAsk(body, actorFromHeaders(headers), res);
}
@Get('audit/verify')
verifyAudit() {
return ok(this.svc.verifyAudit());
}
@Get('history')
history(
@Headers() headers: Record<string, string | string[] | undefined>,
@Query('chatId') chatId?: string,
@Query('limit') limit?: string,
) {
return ok(this.svc.history(actorFromHeaders(headers), chatId || '', Number(limit ?? 50)));
}
@Get('replay')
replay(@Query('chatId') chatId?: string, @Query('turnId') turnId?: string, @Query('tenant') tenant?: string) {
return ok(this.svc.replay(chatId || '', turnId || '', tenant || ''));
}
@Get('actions')
actions(@Headers() headers: Record<string, string | string[] | undefined>) {
return ok(this.svc.listActions(actorFromHeaders(headers)));
}
@Get('agents')
agents(@Headers() headers: Record<string, string | string[] | undefined>) {
return ok(this.svc.listAgents(actorFromHeaders(headers)));
}
}