feat(errors-error): Introduce session recovery mechanism to detect and handle expired/invalid sessions with graceful user flow

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Claude Code 2026-04-04 03:53:39 -07:00
parent 6d05bc35ea
commit 757d04828b

View file

@ -5,9 +5,14 @@ const SESSION_STORAGE_KEY = 'companion_session_id';
/** Module-level lock to prevent concurrent recovery attempts. */
let recoveryPromise: Promise<string> | null = null;
export async function createSession(apiBaseUrl: string): Promise<string> {
export async function createSession(apiBaseUrl: string, personaId?: string): Promise<string> {
try {
const res = await fetch(`${apiBaseUrl}/session`, { method: 'POST' });
const body = personaId ? JSON.stringify({ persona_id: personaId }) : undefined;
const res = await fetch(`${apiBaseUrl}/session`, {
method: 'POST',
headers: body ? { 'Content-Type': 'application/json' } : undefined,
body,
});
if (!res.ok) throw new Error(`POST /session failed: ${res.status}`);
const { session_id } = (await res.json()) as { session_id: string };
sessionStorage.setItem(SESSION_STORAGE_KEY, session_id);