| 1 |
/** |
| 2 |
* Single-source check for "should the AI sparkle button render here?". |
| 3 |
* |
| 4 |
* Three independent gates must all be true: |
| 5 |
* 1. `isAiEligible` — license tier is Growth or Agency (set by Pro). |
| 6 |
* 2. `aiAssistantEnabled` — module toggle on (set by Pro). |
| 7 |
* 3. `aiAssistantConfigured` — at least one provider has an API key |
| 8 |
* (set by Pro's AiModule::boot → LocalizedData::register). |
| 9 |
* |
| 10 |
* Components import this so the rule lives in one place — flipping it |
| 11 |
* later (e.g. allowing per-user opt-in) is a single edit. |
| 12 |
*/ |
| 13 |
|
| 14 |
export interface AiAdminWindow { |
| 15 |
isAiEligible?: boolean; |
| 16 |
aiAssistantEnabled?: boolean; |
| 17 |
aiAssistantConfigured?: boolean; |
| 18 |
} |
| 19 |
|
| 20 |
function readAdmin(): AiAdminWindow { |
| 21 |
return ((window as any).yatraAdmin ?? {}) as AiAdminWindow; |
| 22 |
} |
| 23 |
|
| 24 |
/** Is the AI module fully ready (eligible + enabled + at least one key)? */ |
| 25 |
export function isAiReady(): boolean { |
| 26 |
const a = readAdmin(); |
| 27 |
return Boolean( |
| 28 |
a.isAiEligible && a.aiAssistantEnabled && a.aiAssistantConfigured, |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Looser check: the operator's license tier qualifies and the module is |
| 34 |
* enabled, but no key is configured yet. Used by the Settings page to |
| 35 |
* show the "add your API key to start" state. |
| 36 |
*/ |
| 37 |
export function isAiActiveButUnconfigured(): boolean { |
| 38 |
const a = readAdmin(); |
| 39 |
return Boolean( |
| 40 |
a.isAiEligible && a.aiAssistantEnabled && !a.aiAssistantConfigured, |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
/** Did the operator's license tier even unlock AI Assistant? */ |
| 45 |
export function isAiEligible(): boolean { |
| 46 |
return Boolean(readAdmin().isAiEligible); |
| 47 |
} |
| 48 |
|
| 49 |
/** Is the AI Assistant module toggle on? */ |
| 50 |
export function isAiModuleEnabled(): boolean { |
| 51 |
return Boolean(readAdmin().aiAssistantEnabled); |
| 52 |
} |
| 53 |
|