import { AI_HOST, INSIGHTS_HOST } from '@constants';
import { reqDataBasics } from '@shared/lib/data';
import { useImageGenerationStore } from '@shared/state/generate-images';
import apiFetch from '@wordpress/api-fetch';
import { __ } from '@wordpress/i18n';
export const generateImage = async (imageData, signal) => {
const response = await fetch(`${AI_HOST}/api/draft/image`, {
headers: { 'Content-Type': 'application/json' },
globalState: useImageGenerationStore.getState(),
const body = await response.json();
remaining: response.headers.get('x-ratelimit-remaining'),
total: response.headers.get('x-ratelimit-limit'),
refresh: response.headers.get('x-ratelimit-reset'),
if (body.status && body.status === 'content-policy-violation') {
'Your request was rejected as a result of our safety system. Your prompt may contain text that is not allowed by our safety system.',
message: __('Service temporarily unavailable', 'extendify-local'),
id: response.headers.get('x-request-id'),
export const recordPluginActivity = async ({ slug, source }) => {
const res = await fetch(`${INSIGHTS_HOST}/api/v1/plugin-install`, {
headers: { 'Content-Type': 'application/json', 'X-Extendify': 'true' },
siteCreatedAt: window.extSharedData?.siteCreatedAt,
// this should not break the app.
console.error('Bad response from server');
console.error('Error sending plugin installation notification:', error);
export const pingServer = async () =>
await apiFetch({ path: '/extendify/v1/shared/ping' });
export const getPartnerPlugins = async (key) => {
const plugins = await apiFetch({
path: '/extendify/v1/shared/partner-plugins',
if (!Object.keys(plugins?.data ?? {}).length) {
throw new Error('Could not get plugins');
if (key && plugins.data?.[key]) {
return plugins.data[key];