33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Copyright (C) 2026 ZiroEDA and contributors.
|
|
// Modified by VibeMake to make the AI assistant opt-in at build time.
|
|
/**
|
|
* The AI assistant is available only in builds that explicitly enable it. In
|
|
* those builds, add `?ai=1` to turn it on for the tab's session; `?ai=0` turns
|
|
* it off. Production VibeMake builds keep the feature disabled.
|
|
*
|
|
* The pane talks to a separately configured AI agent server at AI_AGENT_URL.
|
|
*/
|
|
|
|
const KEY = 'ziroeda.ai';
|
|
const BUILD_ENABLED =
|
|
(import.meta as { env?: Record<string, string | undefined> }).env?.VITE_ENABLE_AI === 'true';
|
|
|
|
/** Whether the AI assistant is enabled for this build and shown in this tab. */
|
|
export function aiEnabled(): boolean {
|
|
if (!BUILD_ENABLED || typeof window === 'undefined') return false;
|
|
const flag = new URLSearchParams(window.location.search).get('ai');
|
|
try {
|
|
if (flag === '1') window.sessionStorage.setItem(KEY, '1');
|
|
else if (flag === '0') window.sessionStorage.removeItem(KEY);
|
|
return window.sessionStorage.getItem(KEY) === '1';
|
|
} catch {
|
|
return flag === '1';
|
|
}
|
|
}
|
|
|
|
/** Where the agent server listens; VITE_AI_AGENT_URL overrides the local default. */
|
|
export const AI_AGENT_URL: string =
|
|
(import.meta as { env?: Record<string, string | undefined> }).env?.VITE_AI_AGENT_URL ??
|
|
'http://127.0.0.1:8787';
|