PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / HelpCenter / lib / api.js

api.js in Extendify trunk, at src/HelpCenter/lib/api.js

41 lines 992 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { AI_HOST } from '@constants';
2 import { useAIConsentStore } from '@shared/state/ai-consent';
3
4 // Additional data to send with requests
5 const allowList = [
6 'siteId',
7 'partnerId',
8 'wpVersion',
9 'wpLanguage',
10 'devbuild',
11 'isBlockTheme',
12 'userId',
13 'siteProfile',
14 ];
15
16 const { showAIConsent, userGaveConsent } = useAIConsentStore.getState();
17
18 const extraBody = {
19 ...Object.fromEntries(
20 Object.entries(window.extSharedData).filter(([key]) =>
21 allowList.includes(key),
22 ),
23 ),
24 showAIConsent,
25 userGaveConsent,
26 };
27
28 export const getAnswer = ({ question, experienceLevel }) =>
29 fetch(`${AI_HOST}/api/chat/ask-question`, {
30 method: 'POST',
31 headers: { 'Content-Type': 'application/json' },
32 body: JSON.stringify({ question, experienceLevel, ...extraBody }),
33 });
34
35 export const rateAnswer = ({ answerId, rating }) =>
36 fetch(`${AI_HOST}/api/chat/rate-answer`, {
37 method: 'POST',
38 headers: { 'Content-Type': 'application/json' },
39 body: JSON.stringify({ answerId, rating }),
40 });
41