|
| 1 | +/** Set when ?aibuddy=1 is present on initial page load (cleared on full reload). */ |
| 2 | +let aiBuddyMenuEnabled = false; |
| 3 | + |
| 4 | +/** |
| 5 | + * Demo / release backdoor for AI Buddy. Call once before the app renders. |
| 6 | + * |
| 7 | + * URL param on page load: |
| 8 | + * ?aibuddy=1 — show AI Buddy in the More menu until the tab is reloaded |
| 9 | + * ?aibuddy=0 — hide AI Buddy (useful to reset after testing ?aibuddy=1) |
| 10 | + * |
| 11 | + * Build flag: VITE_ENABLE_AI_BUDDY=true always shows the menu item. |
| 12 | + */ |
| 13 | +export function initAiBuddyAccess(): void { |
| 14 | + // Remove legacy session flag from earlier builds |
| 15 | + sessionStorage.removeItem('xrp-ai-buddy-enabled'); |
| 16 | + |
| 17 | + const params = new URLSearchParams(window.location.search); |
| 18 | + const value = params.get('aibuddy')?.toLowerCase(); |
| 19 | + |
| 20 | + if (value === '1' || value === 'true') { |
| 21 | + aiBuddyMenuEnabled = true; |
| 22 | + } else if (value === '0' || value === 'false') { |
| 23 | + aiBuddyMenuEnabled = false; |
| 24 | + } |
| 25 | + |
| 26 | + if (value) { |
| 27 | + params.delete('aibuddy'); |
| 28 | + const query = params.toString(); |
| 29 | + const cleanUrl = query |
| 30 | + ? `${window.location.pathname}?${query}${window.location.hash}` |
| 31 | + : `${window.location.pathname}${window.location.hash}`; |
| 32 | + window.history.replaceState({}, '', cleanUrl); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +export function isAiBuddyMenuEnabled(): boolean { |
| 37 | + if (import.meta.env.VITE_ENABLE_AI_BUDDY === 'true') { |
| 38 | + return true; |
| 39 | + } |
| 40 | + return aiBuddyMenuEnabled; |
| 41 | +} |
0 commit comments