()
| 11 | } |
| 12 | |
| 13 | async function loadPublicAiConfig() { |
| 14 | if (window.__FR_IS_PRO !== true) { |
| 15 | return { enabled: false }; |
| 16 | } |
| 17 | if (publicAiConfigPromise) { |
| 18 | return publicAiConfigPromise; |
| 19 | } |
| 20 | publicAiConfigPromise = fetch(withBase('/api/pro/ai/config/public.php'), { |
| 21 | method: 'GET', |
| 22 | credentials: 'include', |
| 23 | headers: { |
| 24 | Accept: 'application/json' |
| 25 | } |
| 26 | }) |
| 27 | .then(async (res) => { |
| 28 | const raw = await res.text(); |
| 29 | let data = {}; |
| 30 | try { |
| 31 | data = JSON.parse(raw || '{}'); |
| 32 | } catch (e) { |
| 33 | data = {}; |
| 34 | } |
| 35 | const settings = (data && data.settings && typeof data.settings === 'object') ? data.settings : {}; |
| 36 | const providers = Array.isArray(settings.providers) ? settings.providers : []; |
| 37 | return { |
| 38 | enabled: !!settings.chatEnabled && providers.length > 0 |
| 39 | }; |
| 40 | }) |
| 41 | .catch(() => ({ enabled: false })); |
| 42 | return publicAiConfigPromise; |
| 43 | } |
| 44 | |
| 45 | async function copyTextToClipboard(text) { |
| 46 | if (navigator.clipboard && window.isSecureContext) { |
no test coverage detected