feat(sessions): add unified /sessions/messages entry point

Add SessionsService#routeIncomingMessage: if the user has an active
non-completed session, route to its agent by status (only
objective_discovery is implemented so far - any other status rejects
with a clear 409 rather than failing silently); otherwise run the
intent router first and only create a session + start Agent 1 when it
detects a learning intent, replying as plain conversational Max
(PERSONALITY_PROMPT only, no session) otherwise.

Exposed as POST /sessions/messages (JWT-protected), the new single
entry point the chat window should call instead of unconditionally
creating a session on every message.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-11-01 08:57:29 +01:00
co-authored by Claude Sonnet 5
parent dc368a32f0
commit ce25d3f290
6 changed files with 237 additions and 2 deletions
@@ -19,6 +19,7 @@ import {
import type { AuthenticatedRequest } from '../auth/jwt-auth.guard';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { ObjectiveMessageResponseDto } from './dto/objective-message-response.dto';
import { RouteMessageResponseDto } from './dto/route-message-response.dto';
import { SendObjectiveMessageDto } from './dto/send-objective-message.dto';
import { SessionObjectiveResponseDto } from './dto/session-objective-response.dto';
import { SessionResponseDto } from './dto/session-response.dto';
@@ -38,6 +39,26 @@ export class SessionsController {
return this.sessionsService.create(request.user.sub);
}
@Post('messages')
@ApiOperation({
summary:
"Point d'entree unique du chat : route vers la session active ou demarre une formation selon l'intention detectee",
})
@ApiResponse({ status: HttpStatus.CREATED, type: RouteMessageResponseDto })
@ApiResponse({
status: HttpStatus.CONFLICT,
description: 'Etape du pipeline pas encore implementee',
})
routeMessage(
@Body() dto: SendObjectiveMessageDto,
@Req() request: AuthenticatedRequest,
): Promise<RouteMessageResponseDto> {
return this.sessionsService.routeIncomingMessage(
request.user.sub,
dto.message,
);
}
@Get(':id')
@ApiOperation({ summary: "Recuperer l'etat d'une session" })
@ApiResponse({ status: HttpStatus.OK, type: SessionResponseDto })