Skip to content

Commit f5fc806

Browse files
committed
AI Buddy visiblity
AI Buddy can now be turned on by a VITE config parameter or by adding ?aibuddy=1 to the URL line in a release.
1 parent 522f973 commit f5fc806

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

src/components/navbar.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import UploadFileDlg from '@/components/dialogs/uploadfiledlg';
5959
import EditorMgr, { EditorSession, EdSearchParams } from '@/managers/editormgr';
6060
import { useLocalStorage } from 'usehooks-ts';
6161
import { StorageKeys } from '@/utils/localstorage';
62+
import { isAiBuddyMenuEnabled } from '@/utils/aiBuddyAccess';
6263
import FileSaver from 'file-saver';
6364
import PowerSwitchAlert from '@/components/dialogs/power-switchdlg';
6465
import ViewPythonDlg from '@/components/dialogs/view-pythondlg';
@@ -1368,11 +1369,13 @@ function NavBar({ layoutref }: NavBarProps) {
13681369
];
13691370

13701371
const moreMenu: MenuDataItem[] = [
1371-
{
1372-
label: t('ai-chat'),
1373-
iconImage: chatbot,
1374-
clicked: onAiClicked,
1375-
},
1372+
...(isAiBuddyMenuEnabled()
1373+
? [{
1374+
label: t('ai-chat'),
1375+
iconImage: chatbot,
1376+
clicked: onAiClicked,
1377+
}]
1378+
: []),
13761379
{
13771380
label: t('dashboard'),
13781381
iconImage: dashboard,

src/main.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { createRoot } from 'react-dom/client';
33
import '@/index.css';
44
import '@/utils/i18n';
55
import '@/utils/blockly-global'; // Expose Blockly globally for external plugins
6+
import { initAiBuddyAccess } from '@/utils/aiBuddyAccess';
67
import App from '@/App.tsx';
78
import { GoogleOAuthProvider } from '@react-oauth/google';
89
import { ThemeInit } from '../.flowbite-react/init';
910

11+
initAiBuddyAccess();
12+
1013
function Root() {
1114
const [googleClientId, setGoogleClientId] = useState<string | null>(null);
1215
const googleAuthBackendUrl = import.meta.env.GOOGLE_AUTH_URL;

src/utils/aiBuddyAccess.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)