const KEY = 'minstrel.client_id';

export function getOrCreateClientId(): string {
  try {
    const existing = sessionStorage.getItem(KEY);
    if (existing) return existing;
  } catch {
    // sessionStorage unavailable (non-browser env). Generate ephemerally.
  }
  const id = crypto.randomUUID();
  try { sessionStorage.setItem(KEY, id); } catch { /* ignore */ }
  return id;
}
