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:
co-authored by
Claude Sonnet 5
parent
ce25d3f290
commit
7179743d4e
@@ -3,8 +3,14 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
const getAccessToken = vi.fn<() => string | null>(() => 'jwt-token')
|
||||
vi.mock('../../src/main/auth/session', () => ({ getAccessToken }))
|
||||
|
||||
const { createSession, getSession, sendObjectiveMessage, confirmObjective, MaxApiError } =
|
||||
await import('../../src/main/api/sessionsClient')
|
||||
const {
|
||||
createSession,
|
||||
getSession,
|
||||
sendObjectiveMessage,
|
||||
confirmObjective,
|
||||
routeMessage,
|
||||
MaxApiError
|
||||
} = await import('../../src/main/api/sessionsClient')
|
||||
|
||||
function jsonResponse(body: unknown, ok = true, status = ok ? 200 : 400): Response {
|
||||
return { ok, status, json: () => Promise.resolve(body) } as Response
|
||||
@@ -84,6 +90,20 @@ describe('sessionsClient', () => {
|
||||
expect(result.sessionId).toBe(1)
|
||||
})
|
||||
|
||||
it('should route a message to the unified entry point', async () => {
|
||||
global.fetch = vi.fn().mockResolvedValueOnce(jsonResponse({ type: 'chat', reply: 'Salut !' }))
|
||||
|
||||
const result = await routeMessage('Salut ça va ?')
|
||||
|
||||
expect(result).toEqual({ type: 'chat', reply: 'Salut !' })
|
||||
const calls = (global.fetch as unknown as { mock: { calls: [string, RequestInit][] } }).mock
|
||||
.calls
|
||||
const call = calls.at(0)
|
||||
expect(call?.[0]).toContain('/sessions/messages')
|
||||
const body = call?.[1]?.body as string
|
||||
expect(JSON.parse(body)).toEqual({ message: 'Salut ça va ?' })
|
||||
})
|
||||
|
||||
it('should throw MaxApiError with the server message on a non-ok response', async () => {
|
||||
global.fetch = vi.fn().mockResolvedValueOnce(jsonResponse({ message: 'Conflit' }, false, 409))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user