feat(sessions): route chat messages through the intent-aware backend entry point

Replace the chat window's unconditional create-session-then-send flow
with a single call to the new POST /sessions/messages endpoint: a
plain "salut ça va ?" no longer starts a fake training session, since
the backend's intent router decides that now.

Add sessions.routeMessage to the IPC/preload surface and the sessions
HTTP client. useSessionStore.sendMessage only sets sessionId/status
(fetched fresh via sessions:get) when the backend actually reports
type: "learn". The stepper-window-open + status-broadcast trigger in
main/index.ts moves from sessions:create's handler to
sessions:route-message's, since session creation now happens inside
the backend's routing logic rather than via an explicit prior call.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-11-01 09:02:39 +01:00
co-authored by Claude Sonnet 5
parent ce25d3f290
commit 7179743d4e
9 changed files with 160 additions and 44 deletions
@@ -3,16 +3,15 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import ChatPanel from '../../../src/renderer/src/components/ChatPanel'
import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore'
const create = vi.fn()
const get = vi.fn()
const sendObjectiveMessage = vi.fn()
const routeMessage = vi.fn()
const confirmObjective = vi.fn()
const notifySessionEnded = vi.fn()
beforeEach(() => {
vi.clearAllMocks()
;(window as unknown as { api: Record<string, unknown> }).api = {
sessions: { create, get, sendObjectiveMessage, confirmObjective },
sessions: { get, routeMessage, confirmObjective },
notifySessionEnded
}
useSessionStore.getState().restart()
@@ -26,8 +25,13 @@ describe('<ChatPanel />', () => {
})
it('should send the first message, creating a session, and render the conversation', async () => {
create.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
sendObjectiveMessage.mockResolvedValueOnce({ reply: 'Quel est ton sujet ?', ready: false })
routeMessage.mockResolvedValueOnce({
type: 'learn',
sessionId: 1,
reply: 'Quel est ton sujet ?',
ready: false
})
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
render(<ChatPanel />)
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'Je veux apprendre' } })
@@ -38,12 +42,14 @@ describe('<ChatPanel />', () => {
})
it('should show the ObjectiveValidationCard instead of the input bar once the agent is ready', async () => {
create.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
sendObjectiveMessage.mockResolvedValueOnce({
routeMessage.mockResolvedValueOnce({
type: 'learn',
sessionId: 1,
reply: 'Voici le recap',
ready: true,
draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' }
})
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
render(<ChatPanel />)
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } })
@@ -54,7 +60,7 @@ describe('<ChatPanel />', () => {
})
it('should show the store error message when a call fails', async () => {
create.mockRejectedValueOnce(new Error('Max API injoignable'))
routeMessage.mockRejectedValueOnce(new Error('Max API injoignable'))
render(<ChatPanel />)
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } })