feat(sessions): keep JWT in memory and wire IPC to the sessions API

Max Avatar can now call Max API's /sessions endpoints: session.ts keeps
the access token in memory after login (never persisted, cleared on
logout, same lifecycle as the existing email/keys state), a new
sessionsClient.ts wraps the 4 endpoints with the Bearer header, and
index.ts exposes them as sessions:create/get/send-objective-message/
confirm-objective IPC handlers (input-validated, requireLoggedIn()
gated) surfaced to the renderer as window.api.sessions.*.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-10-31 21:41:35 +01:00
co-authored by Claude Sonnet 5
parent ef4cd41ad4
commit 00619add9f
11 changed files with 1820 additions and 16 deletions
+51 -1
View File
@@ -8,9 +8,20 @@ import { setMainWindow } from './windowBridge'
import { stripWakeWord } from './wakeWord'
import { loginAndLoadKeys } from './auth/authClient'
import { openLoginWindow, closeLoginWindow } from './auth/loginWindow'
import { clearSession, getCurrentUserEmail, isLoggedIn } from './auth/session'
import { clearSession, getCurrentUserEmail, isLoggedIn, requireLoggedIn } from './auth/session'
import {
confirmObjective,
createSession,
getSession,
sendObjectiveMessage
} from './api/sessionsClient'
import type { VoiceTurnResult } from '../shared/voice'
import type { AuthStatus, LoginResult } from '../shared/auth'
import type {
ObjectiveMessageResponse,
SessionObjectiveResponse,
SessionResponse
} from '../shared/session'
import { logger } from './utils/logger'
import { SECURE_WEB_PREFERENCES, blockExternalNavigation } from './utils/windowSecurity'
import { startAutoUpdater } from './updater'
@@ -221,6 +232,45 @@ app
email: getCurrentUserEmail()
}))
ipcMain.handle('sessions:create', (): Promise<SessionResponse> => {
requireLoggedIn()
return createSession()
})
ipcMain.handle('sessions:get', (_event, id: unknown): Promise<SessionResponse> => {
requireLoggedIn()
if (typeof id !== 'number' || !Number.isInteger(id) || id <= 0) {
throw new Error('id de session invalide')
}
return getSession(id)
})
ipcMain.handle(
'sessions:send-objective-message',
(_event, id: unknown, message: unknown): Promise<ObjectiveMessageResponse> => {
requireLoggedIn()
if (typeof id !== 'number' || !Number.isInteger(id) || id <= 0) {
throw new Error('id de session invalide')
}
if (typeof message !== 'string' || message.trim().length === 0) {
throw new Error('message vide')
}
if (message.length > 2000) throw new Error('message trop long')
return sendObjectiveMessage(id, message)
}
)
ipcMain.handle(
'sessions:confirm-objective',
(_event, id: unknown): Promise<SessionObjectiveResponse> => {
requireLoggedIn()
if (typeof id !== 'number' || !Number.isInteger(id) || id <= 0) {
throw new Error('id de session invalide')
}
return confirmObjective(id)
}
)
createWindow()
if (!is.dev) startAutoUpdater()