PluginProbe
Extendify / 3.1.2
Extendify v3.1.2
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 0.7.0 All 126 releases
extendify / src / Draft / api / Data.js

Data.js in Extendify 3.1.2, at src/Draft/api/Data.js

55 lines 1.1 KB
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 import { useImageGenerationStore } from '@shared/state/generate-images.js';
4 import { __ } from '@wordpress/i18n';
5
6 // Additional data to send with requests
7 const allowList = [
8 'siteId',
9 'partnerId',
10 'wpVersion',
11 'wpLanguage',
12 'devbuild',
13 'isBlockTheme',
14 'userId',
15 'siteProfile',
16 ];
17
18 const { showAIConsent, userGaveConsent } = useAIConsentStore.getState();
19
20 const extraBody = {
21 ...Object.fromEntries(
22 Object.entries(window.extSharedData).filter(([key]) =>
23 allowList.includes(key),
24 ),
25 ),
26 showAIConsent,
27 userGaveConsent,
28 };
29
30 export const completion = async (
31 prompt,
32 promptType,
33 systemMessageKey,
34 details,
35 ) => {
36 const response = await fetch(`${AI_HOST}/api/draft/completion`, {
37 method: 'POST',
38 headers: { 'Content-Type': 'application/json' },
39 body: JSON.stringify({
40 prompt,
41 promptType,
42 systemMessageKey,
43 details,
44 globalState: useImageGenerationStore.getState(),
45 ...extraBody,
46 }),
47 });
48
49 if (!response.ok) {
50 throw new Error(__('Service temporarily unavailable', 'extendify-local'));
51 }
52
53 return response;
54 };
55