Files
twenty/packages/twenty-server/src/engine/metadata-modules/agent/agent-chat.controller.ts
T
Abdul Rahman 51d02c13bf Feat - Agent chat tab (#13061)
Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
Co-authored-by: Marie <51697796+ijreilly@users.noreply.github.com>
Co-authored-by: Antoine Moreaux <moreaux.antoine@gmail.com>
Co-authored-by: Raphaël Bosi <71827178+bosiraphael@users.noreply.github.com>
2025-07-07 22:47:41 +02:00

73 lines
1.9 KiB
TypeScript

import {
Body,
Controller,
Get,
Param,
Post,
Res,
UseFilters,
UseGuards,
} from '@nestjs/common';
import { Response } from 'express';
import { RestApiExceptionFilter } from 'src/engine/api/rest/rest-api-exception.filter';
import { AuthUserWorkspaceId } from 'src/engine/decorators/auth/auth-user-workspace-id.decorator';
import { JwtAuthGuard } from 'src/engine/guards/jwt-auth.guard';
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
import { AgentChatService } from './agent-chat.service';
import { AgentStreamingService } from './agent-streaming.service';
@Controller('rest/agent-chat')
@UseGuards(JwtAuthGuard, WorkspaceAuthGuard)
@UseFilters(RestApiExceptionFilter)
export class AgentChatController {
constructor(
private readonly agentChatService: AgentChatService,
private readonly agentStreamingService: AgentStreamingService,
) {}
@Get('threads/:agentId')
async getThreadsForAgent(
@Param('agentId') agentId: string,
@AuthUserWorkspaceId() userWorkspaceId: string,
) {
return this.agentChatService.getThreadsForAgent(agentId, userWorkspaceId);
}
@Get('threads/:threadId/messages')
async getMessagesForThread(
@Param('threadId') threadId: string,
@AuthUserWorkspaceId() userWorkspaceId: string,
) {
return this.agentChatService.getMessagesForThread(
threadId,
userWorkspaceId,
);
}
@Post('threads')
async createThread(
@Body() body: { agentId: string },
@AuthUserWorkspaceId() userWorkspaceId: string,
) {
return this.agentChatService.createThread(body.agentId, userWorkspaceId);
}
@Post('stream')
async streamAgentChat(
@Body()
body: { threadId: string; userMessage: string },
@AuthUserWorkspaceId() userWorkspaceId: string,
@Res() res: Response,
) {
await this.agentStreamingService.streamAgentChat({
threadId: body.threadId,
userMessage: body.userMessage,
userWorkspaceId,
res,
});
}
}