()
| 354 | } |
| 355 | |
| 356 | async function loadPublicAiConfig() { |
| 357 | const siteCfg = await loadPublicSiteConfig(); |
| 358 | if (!siteCfg || !siteCfg.pro || siteCfg.pro.active !== true) { |
| 359 | return { enabled: false }; |
| 360 | } |
| 361 | if (publicAiConfigPromise) return publicAiConfigPromise; |
| 362 | publicAiConfigPromise = fetch(withBasePath('/api/pro/ai/config/public.php'), { |
| 363 | method: 'GET', |
| 364 | credentials: 'same-origin', |
| 365 | headers: { |
| 366 | Accept: 'application/json' |
| 367 | } |
| 368 | }) |
| 369 | .then(async function (res) { |
| 370 | const raw = await res.text(); |
| 371 | let data = {}; |
| 372 | try { |
| 373 | data = JSON.parse(raw || '{}'); |
| 374 | } catch (e) { |
| 375 | data = {}; |
| 376 | } |
| 377 | const settings = data && data.settings && typeof data.settings === 'object' ? data.settings : {}; |
| 378 | const providers = Array.isArray(settings.providers) ? settings.providers : []; |
| 379 | return { |
| 380 | enabled: !!settings.chatEnabled && providers.length > 0 |
| 381 | }; |
| 382 | }) |
| 383 | .catch(function () { |
| 384 | return { enabled: false }; |
| 385 | }); |
| 386 | return publicAiConfigPromise; |
| 387 | } |
| 388 | |
| 389 | function createShareCopilotCard() { |
| 390 | const host = document.createElement('section'); |
no test coverage detected