@automattic/jetpack-ai-client 0.25.6 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/build/components/ai-icon/index.d.ts +10 -0
- package/build/components/ai-icon/index.js +16 -0
- package/build/components/ai-image/components/ai-image-modal.d.ts +57 -0
- package/build/components/ai-image/components/ai-image-modal.js +92 -0
- package/build/components/ai-image/components/carrousel.d.ts +28 -0
- package/build/components/ai-image/components/carrousel.js +69 -0
- package/build/components/ai-image/components/usage-counter.d.ts +16 -0
- package/build/components/ai-image/components/usage-counter.js +29 -0
- package/build/components/ai-image/featured-image.d.ts +17 -0
- package/build/components/ai-image/featured-image.js +278 -0
- package/build/components/ai-image/general-purpose-image.d.ts +23 -0
- package/build/components/ai-image/general-purpose-image.js +184 -0
- package/build/components/ai-image/hooks/use-ai-image.d.ts +48 -0
- package/build/components/ai-image/hooks/use-ai-image.js +219 -0
- package/build/components/ai-image/hooks/use-site-type.d.ts +6 -0
- package/build/components/ai-image/hooks/use-site-type.js +23 -0
- package/build/components/ai-image/index.d.ts +4 -0
- package/build/components/ai-image/index.js +4 -0
- package/build/components/ai-image/types.d.ts +16 -0
- package/build/components/ai-image/types.js +6 -0
- package/build/{ai-client/src/components → components}/index.d.ts +4 -0
- package/build/{ai-client/src/components → components}/index.js +4 -0
- package/build/components/modal/index.d.ts +18 -0
- package/build/components/modal/index.js +23 -0
- package/build/components/quota-exceeded-message/index.d.ts +13 -0
- package/build/components/quota-exceeded-message/index.js +152 -0
- package/build/components/quota-exceeded-message/light-nudge.d.ts +11 -0
- package/build/components/quota-exceeded-message/light-nudge.js +8 -0
- package/build/{ai-client/src/constants.d.ts → constants.d.ts} +3 -0
- package/build/{ai-client/src/constants.js → constants.js} +4 -0
- package/build/hooks/use-ai-checkout/index.d.ts +13 -0
- package/build/hooks/use-ai-checkout/index.js +41 -0
- package/build/hooks/use-ai-feature/index.d.ts +33 -0
- package/build/hooks/use-ai-feature/index.js +37 -0
- package/build/hooks/use-post-content.d.ts +5 -0
- package/build/hooks/use-post-content.js +20 -0
- package/build/hooks/use-save-to-media-library.d.ts +12 -0
- package/build/hooks/use-save-to-media-library.js +74 -0
- package/build/{ai-client/src/index.d.ts → index.d.ts} +3 -0
- package/build/{ai-client/src/index.js → index.js} +3 -0
- package/build/{ai-client/src/logo-generator → logo-generator}/components/upgrade-screen.js +1 -1
- package/build/{ai-client/src/logo-generator → logo-generator}/hooks/use-fair-usage-notice-message.js +1 -1
- package/package.json +20 -14
- package/src/components/ai-icon/index.tsx +39 -0
- package/src/components/ai-image/components/ai-image-modal.scss +88 -0
- package/src/components/ai-image/components/ai-image-modal.tsx +240 -0
- package/src/components/ai-image/components/carrousel.scss +163 -0
- package/src/components/ai-image/components/carrousel.tsx +217 -0
- package/src/components/ai-image/components/usage-counter.scss +19 -0
- package/src/components/ai-image/components/usage-counter.tsx +54 -0
- package/src/components/ai-image/featured-image.tsx +439 -0
- package/src/components/ai-image/general-purpose-image.tsx +303 -0
- package/src/components/ai-image/hooks/use-ai-image.ts +339 -0
- package/src/components/ai-image/hooks/use-site-type.ts +26 -0
- package/src/components/ai-image/index.ts +10 -0
- package/src/components/ai-image/style.scss +95 -0
- package/src/components/ai-image/types.ts +19 -0
- package/src/components/index.ts +12 -0
- package/src/components/modal/index.tsx +70 -0
- package/src/components/modal/style.scss +45 -0
- package/src/components/quota-exceeded-message/index.tsx +319 -0
- package/src/components/quota-exceeded-message/light-nudge.tsx +38 -0
- package/src/components/quota-exceeded-message/style.scss +35 -0
- package/src/constants.ts +5 -0
- package/src/hooks/use-ai-checkout/index.ts +65 -0
- package/src/hooks/use-ai-feature/Readme.md +20 -0
- package/src/hooks/use-ai-feature/index.ts +62 -0
- package/src/hooks/use-post-content.ts +27 -0
- package/src/hooks/use-save-to-media-library.ts +100 -0
- package/src/index.ts +3 -0
- package/src/logo-generator/components/upgrade-screen.tsx +1 -1
- package/src/logo-generator/hooks/use-fair-usage-notice-message.tsx +1 -1
- package/build/components/tools/jp-redirect/index.d.ts +0 -20
- package/build/components/tools/jp-redirect/index.js +0 -50
- package/build/components/tools/jp-redirect/types.d.ts +0 -39
- package/build/components/tools/jp-redirect/types.js +0 -1
- /package/build/{ai-client/src/api-fetch → api-fetch}/index.d.ts +0 -0
- /package/build/{ai-client/src/api-fetch → api-fetch}/index.js +0 -0
- /package/build/{ai-client/src/ask-question → ask-question}/index.d.ts +0 -0
- /package/build/{ai-client/src/ask-question → ask-question}/index.js +0 -0
- /package/build/{ai-client/src/ask-question → ask-question}/sync.d.ts +0 -0
- /package/build/{ai-client/src/ask-question → ask-question}/sync.js +0 -0
- /package/build/{ai-client/src/audio-transcription → audio-transcription}/index.d.ts +0 -0
- /package/build/{ai-client/src/audio-transcription → audio-transcription}/index.js +0 -0
- /package/build/{ai-client/src/components → components}/ai-control/ai-control.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/ai-control/ai-control.js +0 -0
- /package/build/{ai-client/src/components → components}/ai-control/block-ai-control.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/ai-control/block-ai-control.js +0 -0
- /package/build/{ai-client/src/components → components}/ai-control/extension-ai-control.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/ai-control/extension-ai-control.js +0 -0
- /package/build/{ai-client/src/components → components}/ai-control/index.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/ai-control/index.js +0 -0
- /package/build/{ai-client/src/components → components}/ai-feedback/index.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/ai-feedback/index.js +0 -0
- /package/build/{ai-client/src/components → components}/ai-modal-footer/index.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/ai-modal-footer/index.js +0 -0
- /package/build/{ai-client/src/components → components}/ai-status-indicator/index.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/ai-status-indicator/index.js +0 -0
- /package/build/{ai-client/src/components → components}/audio-duration-display/index.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/audio-duration-display/index.js +0 -0
- /package/build/{ai-client/src/components → components}/audio-duration-display/lib/media.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/audio-duration-display/lib/media.js +0 -0
- /package/build/{ai-client/src/components → components}/message/index.d.ts +0 -0
- /package/build/{ai-client/src/components → components}/message/index.js +0 -0
- /package/build/{ai-client/src/data-flow → data-flow}/context.d.ts +0 -0
- /package/build/{ai-client/src/data-flow → data-flow}/context.js +0 -0
- /package/build/{ai-client/src/data-flow → data-flow}/index.d.ts +0 -0
- /package/build/{ai-client/src/data-flow → data-flow}/index.js +0 -0
- /package/build/{ai-client/src/data-flow → data-flow}/use-ai-context.d.ts +0 -0
- /package/build/{ai-client/src/data-flow → data-flow}/use-ai-context.js +0 -0
- /package/build/{ai-client/src/data-flow → data-flow}/with-ai-assistant-data.d.ts +0 -0
- /package/build/{ai-client/src/data-flow → data-flow}/with-ai-assistant-data.js +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-ai-suggestions/index.d.ts +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-ai-suggestions/index.js +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-audio-transcription/index.d.ts +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-audio-transcription/index.js +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-audio-validation/index.d.ts +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-audio-validation/index.js +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-image-generator/constants.d.ts +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-image-generator/constants.js +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-image-generator/index.d.ts +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-image-generator/index.js +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-media-recording/index.d.ts +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-media-recording/index.js +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-save-to-media-library/index.d.ts +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-save-to-media-library/index.js +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-transcription-post-processing/index.d.ts +0 -0
- /package/build/{ai-client/src/hooks → hooks}/use-transcription-post-processing/index.js +0 -0
- /package/build/{ai-client/src/icons → icons}/ai-assistant.d.ts +0 -0
- /package/build/{ai-client/src/icons → icons}/ai-assistant.js +0 -0
- /package/build/{ai-client/src/icons → icons}/error-exclamation.d.ts +0 -0
- /package/build/{ai-client/src/icons → icons}/error-exclamation.js +0 -0
- /package/build/{ai-client/src/icons → icons}/index.d.ts +0 -0
- /package/build/{ai-client/src/icons → icons}/index.js +0 -0
- /package/build/{ai-client/src/icons → icons}/mic.d.ts +0 -0
- /package/build/{ai-client/src/icons → icons}/mic.js +0 -0
- /package/build/{ai-client/src/icons → icons}/origami-plane.d.ts +0 -0
- /package/build/{ai-client/src/icons → icons}/origami-plane.js +0 -0
- /package/build/{ai-client/src/icons → icons}/player-pause.d.ts +0 -0
- /package/build/{ai-client/src/icons → icons}/player-pause.js +0 -0
- /package/build/{ai-client/src/icons → icons}/player-play.d.ts +0 -0
- /package/build/{ai-client/src/icons → icons}/player-play.js +0 -0
- /package/build/{ai-client/src/icons → icons}/player-stop.d.ts +0 -0
- /package/build/{ai-client/src/icons → icons}/player-stop.js +0 -0
- /package/build/{ai-client/src/icons → icons}/speak-tone.d.ts +0 -0
- /package/build/{ai-client/src/icons → icons}/speak-tone.js +0 -0
- /package/build/{ai-client/src/jwt → jwt}/index.d.ts +0 -0
- /package/build/{ai-client/src/jwt → jwt}/index.js +0 -0
- /package/build/{ai-client/src/libs → libs}/index.d.ts +0 -0
- /package/build/{ai-client/src/libs → libs}/index.js +0 -0
- /package/build/{ai-client/src/libs → libs}/map-action-to-human-text.d.ts +0 -0
- /package/build/{ai-client/src/libs → libs}/map-action-to-human-text.js +0 -0
- /package/build/{ai-client/src/libs → libs}/markdown/html-to-markdown.d.ts +0 -0
- /package/build/{ai-client/src/libs → libs}/markdown/html-to-markdown.js +0 -0
- /package/build/{ai-client/src/libs → libs}/markdown/index.d.ts +0 -0
- /package/build/{ai-client/src/libs → libs}/markdown/index.js +0 -0
- /package/build/{ai-client/src/libs → libs}/markdown/markdown-to-html.d.ts +0 -0
- /package/build/{ai-client/src/libs → libs}/markdown/markdown-to-html.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/assets/icons/ai.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/assets/icons/ai.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/assets/icons/check.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/assets/icons/check.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/assets/icons/logo.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/assets/icons/logo.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/assets/icons/media.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/assets/icons/media.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/fair-usage-notice.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/fair-usage-notice.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/feature-fetch-failure-screen.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/feature-fetch-failure-screen.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/first-load-screen.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/first-load-screen.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/generator-modal.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/generator-modal.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/history-carousel.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/history-carousel.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/image-loader.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/image-loader.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/logo-presenter.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/logo-presenter.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/prompt.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/prompt.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/upgrade-nudge.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/upgrade-nudge.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/upgrade-screen.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/visit-site-banner.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/components/visit-site-banner.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/constants.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/constants.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/hooks/use-checkout.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/hooks/use-checkout.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/hooks/use-fair-usage-notice-message.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/hooks/use-logo-generator.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/hooks/use-logo-generator.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/hooks/use-request-errors.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/hooks/use-request-errors.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/index.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/index.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/lib/logo-storage.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/lib/logo-storage.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/lib/media-exists.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/lib/media-exists.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/lib/set-site-logo.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/lib/set-site-logo.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/lib/wpcom-limited-request.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/lib/wpcom-limited-request.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/actions.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/actions.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/constants.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/constants.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/index.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/index.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/initial-state.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/initial-state.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/reducer.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/reducer.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/selectors.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/selectors.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/types.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/store/types.js +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/types.d.ts +0 -0
- /package/build/{ai-client/src/logo-generator → logo-generator}/types.js +0 -0
- /package/build/{ai-client/src/suggestions-event-source → suggestions-event-source}/index.d.ts +0 -0
- /package/build/{ai-client/src/suggestions-event-source → suggestions-event-source}/index.js +0 -0
- /package/build/{ai-client/src/types.d.ts → types.d.ts} +0 -0
- /package/build/{ai-client/src/types.js → types.js} +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import getRedirectUrl from '@automattic/jetpack-components/tools/jp-redirect';
|
|
5
|
+
import {
|
|
6
|
+
isAtomicSite,
|
|
7
|
+
isSimpleSite,
|
|
8
|
+
getSiteFragment,
|
|
9
|
+
useAutosaveAndRedirect,
|
|
10
|
+
} from '@automattic/jetpack-shared-extension-utils';
|
|
11
|
+
import useAiFeature from '../use-ai-feature/index.js';
|
|
12
|
+
/*
|
|
13
|
+
* Types
|
|
14
|
+
*/
|
|
15
|
+
import type { MouseEvent } from 'react';
|
|
16
|
+
|
|
17
|
+
const getWPComRedirectToURL = () => {
|
|
18
|
+
const searchParams = new URLSearchParams( window.location.search );
|
|
19
|
+
const site = getSiteFragment();
|
|
20
|
+
|
|
21
|
+
if ( isSimpleSite() && searchParams.has( 'post' ) ) {
|
|
22
|
+
// When there is an explicit post, use it as the destination
|
|
23
|
+
return `https://wordpress.com/post/${ site }/${ searchParams.get( 'post' ) }`;
|
|
24
|
+
}
|
|
25
|
+
// When there is no explicit post, or the site is not Simple, use the home page as the destination
|
|
26
|
+
return `https://wordpress.com/home/${ site }`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type UseAICheckoutReturn = {
|
|
30
|
+
checkoutUrl: string;
|
|
31
|
+
autosaveAndRedirect: ( event: MouseEvent< HTMLButtonElement > ) => void;
|
|
32
|
+
isRedirecting: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The hook to get properties for AICheckout
|
|
37
|
+
*
|
|
38
|
+
* @return {UseAICheckoutReturn} - Object containing properties for AICheckout.
|
|
39
|
+
*/
|
|
40
|
+
export default function useAICheckout(): UseAICheckoutReturn {
|
|
41
|
+
const { nextTier, tierPlansEnabled } = useAiFeature();
|
|
42
|
+
|
|
43
|
+
const wpcomRedirectToURL = getWPComRedirectToURL();
|
|
44
|
+
|
|
45
|
+
const wpcomCheckoutUrl = getRedirectUrl( 'jetpack-ai-yearly-tier-upgrade-nudge', {
|
|
46
|
+
site: getSiteFragment() as string,
|
|
47
|
+
path: tierPlansEnabled ? `jetpack_ai_yearly:-q-${ nextTier?.limit }` : 'jetpack_ai_yearly',
|
|
48
|
+
query: `redirect_to=${ encodeURIComponent( wpcomRedirectToURL ) }`,
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
const jetpackCheckoutUrl = getRedirectUrl( 'jetpack-ai-upgrade-url-for-jetpack-sites', {
|
|
52
|
+
site: getSiteFragment() as string,
|
|
53
|
+
path: 'jetpack_ai_yearly',
|
|
54
|
+
} );
|
|
55
|
+
|
|
56
|
+
const checkoutUrl = isAtomicSite() || isSimpleSite() ? wpcomCheckoutUrl : jetpackCheckoutUrl;
|
|
57
|
+
|
|
58
|
+
const { autosaveAndRedirect, isRedirecting } = useAutosaveAndRedirect( checkoutUrl );
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
checkoutUrl,
|
|
62
|
+
autosaveAndRedirect,
|
|
63
|
+
isRedirecting,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# useAiFeature()
|
|
2
|
+
|
|
3
|
+
React custom hook that provides valuable data about AI requests for the site.
|
|
4
|
+
|
|
5
|
+
```es6
|
|
6
|
+
function UpgradePlan() {
|
|
7
|
+
const { hasFeature, count, refresh } = useAiFeature();
|
|
8
|
+
if ( ! hasFeature ) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
{ `You have made ${ count } requests so far.` }
|
|
15
|
+
<Button>Upgrade</Button>
|
|
16
|
+
<Button onClick={ refresh}>Refresh Data!</Button>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
PLAN_TYPE_FREE,
|
|
6
|
+
usePlanType as getPlanType,
|
|
7
|
+
} from '@automattic/jetpack-shared-extension-utils';
|
|
8
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
9
|
+
import type { WordPressPlansSelectors } from '@automattic/jetpack-shared-extension-utils/store/wordpress-com';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hook to get properties for AiFeature
|
|
13
|
+
* @return {object} - Object containing properties for AiFeature.
|
|
14
|
+
*/
|
|
15
|
+
export default function useAiFeature() {
|
|
16
|
+
const { data, loading, requestsLimit, requestsCount } = useSelect( select => {
|
|
17
|
+
const { getAiAssistantFeature, getIsRequestingAiAssistantFeature } = select(
|
|
18
|
+
'wordpress-com/plans'
|
|
19
|
+
) as WordPressPlansSelectors;
|
|
20
|
+
|
|
21
|
+
const featureData = getAiAssistantFeature();
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
currentTier,
|
|
25
|
+
usagePeriod,
|
|
26
|
+
requestsCount: allTimeRequestsCount,
|
|
27
|
+
requestsLimit: freeRequestsLimit,
|
|
28
|
+
} = featureData;
|
|
29
|
+
|
|
30
|
+
const planType = getPlanType( currentTier );
|
|
31
|
+
|
|
32
|
+
const currentTierLimit = currentTier?.limit || freeRequestsLimit;
|
|
33
|
+
|
|
34
|
+
const actualRequestsCount =
|
|
35
|
+
planType === PLAN_TYPE_FREE ? allTimeRequestsCount : usagePeriod?.requestsCount;
|
|
36
|
+
const actualRequestsLimit = planType === PLAN_TYPE_FREE ? freeRequestsLimit : currentTierLimit;
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
data: featureData,
|
|
40
|
+
loading: getIsRequestingAiAssistantFeature(),
|
|
41
|
+
requestsCount: actualRequestsCount,
|
|
42
|
+
requestsLimit: actualRequestsLimit,
|
|
43
|
+
};
|
|
44
|
+
}, [] );
|
|
45
|
+
|
|
46
|
+
const {
|
|
47
|
+
fetchAiAssistantFeature: loadFeatures,
|
|
48
|
+
increaseAiAssistantRequestsCount: increaseRequestsCount,
|
|
49
|
+
dequeueAiAssistantFeatureAsyncRequest: dequeueAsyncRequest,
|
|
50
|
+
} = useDispatch( 'wordpress-com/plans' );
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
...data,
|
|
54
|
+
requestsCount,
|
|
55
|
+
requestsLimit,
|
|
56
|
+
loading,
|
|
57
|
+
error: null, // @todo: handle error at store level
|
|
58
|
+
refresh: loadFeatures,
|
|
59
|
+
increaseRequestsCount,
|
|
60
|
+
dequeueAsyncRequest,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { serialize } from '@wordpress/blocks';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
/**
|
|
7
|
+
* Types
|
|
8
|
+
*/
|
|
9
|
+
import { renderMarkdownFromHTML } from '../libs/markdown/index.js';
|
|
10
|
+
import type * as BlockEditorSelectors from '@wordpress/block-editor/store/selectors.js';
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* Simple helper to get the post content as markdown
|
|
17
|
+
*/
|
|
18
|
+
const usePostContent = () => {
|
|
19
|
+
const blocks = useSelect(
|
|
20
|
+
select => ( select( 'core/block-editor' ) as typeof BlockEditorSelectors ).getBlocks(),
|
|
21
|
+
[]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return blocks?.length ? renderMarkdownFromHTML( { content: serialize( blocks ) } ) : '';
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default usePostContent;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { isBlobURL } from '@wordpress/blob';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
import { useState } from '@wordpress/element';
|
|
7
|
+
import debugFactory from 'debug';
|
|
8
|
+
/**
|
|
9
|
+
* Types
|
|
10
|
+
*/
|
|
11
|
+
import type { BlockEditorStore } from '../types.js';
|
|
12
|
+
|
|
13
|
+
const debug = debugFactory( 'jetpack-ai-client:save-to-media-library' );
|
|
14
|
+
|
|
15
|
+
type UseSaveToMediaLibraryReturn = {
|
|
16
|
+
isLoading: boolean;
|
|
17
|
+
saveToMediaLibrary: ( url: string, name: string ) => Promise< { id: string; url: string } >;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Hook to save data to media library
|
|
22
|
+
*
|
|
23
|
+
* @return {UseSaveToMediaLibraryReturn} - Object containing properties to save data to media library.
|
|
24
|
+
*/
|
|
25
|
+
export default function useSaveToMediaLibrary() {
|
|
26
|
+
const [ isLoading, setIsLoading ] = useState( false );
|
|
27
|
+
const { getSettings } = useSelect(
|
|
28
|
+
select => select( 'core/block-editor' ),
|
|
29
|
+
[]
|
|
30
|
+
) as BlockEditorStore[ 'selectors' ];
|
|
31
|
+
|
|
32
|
+
const saveToMediaLibrary = (
|
|
33
|
+
url: string,
|
|
34
|
+
name: string = null
|
|
35
|
+
): Promise< { id: string; url: string } > => {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
const settings = getSettings() as any;
|
|
38
|
+
|
|
39
|
+
return new Promise( ( resolve, reject ) => {
|
|
40
|
+
setIsLoading( true );
|
|
41
|
+
|
|
42
|
+
debug( 'Fetching image from URL' );
|
|
43
|
+
|
|
44
|
+
fetch( url )
|
|
45
|
+
.then( response => {
|
|
46
|
+
debug( 'Transforming response to blob' );
|
|
47
|
+
|
|
48
|
+
response
|
|
49
|
+
.blob()
|
|
50
|
+
.then( ( blob: Blob ) => {
|
|
51
|
+
debug( 'Uploading blob to media library' );
|
|
52
|
+
const filesList = [];
|
|
53
|
+
|
|
54
|
+
if ( name ) {
|
|
55
|
+
filesList.push( new File( [ blob ], name ) );
|
|
56
|
+
} else {
|
|
57
|
+
filesList.push( blob );
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
settings.mediaUpload( {
|
|
61
|
+
allowedTypes: [ 'image' ],
|
|
62
|
+
filesList,
|
|
63
|
+
onFileChange( [ image ] ) {
|
|
64
|
+
if ( isBlobURL( image?.url ) ) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ( image ) {
|
|
69
|
+
debug( 'Image uploaded to media library', image );
|
|
70
|
+
resolve( image );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setIsLoading( false );
|
|
74
|
+
},
|
|
75
|
+
onError( message ) {
|
|
76
|
+
debug( 'Error uploading image to media library:', message );
|
|
77
|
+
reject( message );
|
|
78
|
+
setIsLoading( false );
|
|
79
|
+
},
|
|
80
|
+
} );
|
|
81
|
+
} )
|
|
82
|
+
.catch( e => {
|
|
83
|
+
debug( 'Error transforming response to blob:', e?.message );
|
|
84
|
+
reject( e?.message );
|
|
85
|
+
setIsLoading( false );
|
|
86
|
+
} );
|
|
87
|
+
} )
|
|
88
|
+
.catch( e => {
|
|
89
|
+
debug( 'Error fetching image from URL:', e?.message );
|
|
90
|
+
reject( e?.message );
|
|
91
|
+
setIsLoading( false );
|
|
92
|
+
} );
|
|
93
|
+
} );
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
isLoading,
|
|
98
|
+
saveToMediaLibrary,
|
|
99
|
+
};
|
|
100
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,12 +10,15 @@ export { default as transcribeAudio } from './audio-transcription/index.js';
|
|
|
10
10
|
/*
|
|
11
11
|
* Hooks
|
|
12
12
|
*/
|
|
13
|
+
export { default as useAICheckout } from './hooks/use-ai-checkout/index.js';
|
|
14
|
+
export { default as useAiFeature } from './hooks/use-ai-feature/index.js';
|
|
13
15
|
export { default as useAiSuggestions, getErrorData } from './hooks/use-ai-suggestions/index.js';
|
|
14
16
|
export { default as useMediaRecording } from './hooks/use-media-recording/index.js';
|
|
15
17
|
export { default as useAudioTranscription } from './hooks/use-audio-transcription/index.js';
|
|
16
18
|
export { default as useTranscriptionPostProcessing } from './hooks/use-transcription-post-processing/index.js';
|
|
17
19
|
export { default as useAudioValidation } from './hooks/use-audio-validation/index.js';
|
|
18
20
|
export { default as useImageGenerator } from './hooks/use-image-generator/index.js';
|
|
21
|
+
export { default as usePostContent } from './hooks/use-post-content.js';
|
|
19
22
|
export * from './hooks/use-image-generator/constants.js';
|
|
20
23
|
|
|
21
24
|
/*
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
+
import getRedirectUrl from '@automattic/jetpack-components/tools/jp-redirect';
|
|
4
5
|
import { useAnalytics } from '@automattic/jetpack-shared-extension-utils';
|
|
5
6
|
import { Button } from '@wordpress/components';
|
|
6
7
|
import { __ } from '@wordpress/i18n';
|
|
7
8
|
/**
|
|
8
9
|
* Internal dependencies
|
|
9
10
|
*/
|
|
10
|
-
import getRedirectUrl from '../../../../components/tools/jp-redirect/index.js';
|
|
11
11
|
import { EVENT_PLACEMENT_FREE_USER_SCREEN, EVENT_UPGRADE } from '../constants.js';
|
|
12
12
|
import useLogoGenerator from '../hooks/use-logo-generator.js';
|
|
13
13
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import getRedirectUrl from '@automattic/jetpack-components/tools/jp-redirect';
|
|
1
2
|
import { useSelect } from '@wordpress/data';
|
|
2
3
|
import { createInterpolateElement, type Element } from '@wordpress/element';
|
|
3
4
|
import { __, sprintf } from '@wordpress/i18n';
|
|
4
|
-
import getRedirectUrl from '../../../../components/tools/jp-redirect/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* Internal dependencies
|
|
7
7
|
*/
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { GetRedirectUrlArgs } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Builds an URL using the jetpack.com/redirect/ service
|
|
4
|
-
*
|
|
5
|
-
* If source is a simple slug, it will be sent using the source query parameter. e.g. jetpack.com/redirect/?source=slug
|
|
6
|
-
*
|
|
7
|
-
* If source is a full URL, starting with https://, it will be sent using the url query parameter. e.g. jetpack.com/redirect/?url=https://wordpress.com
|
|
8
|
-
*
|
|
9
|
-
* Note: if using full URL, query parameters and anchor must be passed in args. Any querystring of url fragment in the URL will be discarded.
|
|
10
|
-
*
|
|
11
|
-
* @since 0.2.0
|
|
12
|
-
* @param {string} source - The URL handler registered in the server or the full destination URL (starting with https://).
|
|
13
|
-
* @param {GetRedirectUrlArgs} args - Additional arguments to build the url.
|
|
14
|
-
* This is not a complete list as any argument passed here
|
|
15
|
-
* will be sent to as a query parameter to the Redirect server.
|
|
16
|
-
* These parameters will not necessarily be passed over to the final destination URL.
|
|
17
|
-
* If you want to add a parameter to the final destination URL, use the `query` argument.
|
|
18
|
-
* @return {string} The redirect URL
|
|
19
|
-
*/
|
|
20
|
-
export default function getRedirectUrl(source: string, args?: GetRedirectUrlArgs): string;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/* global jetpack_redirects */
|
|
2
|
-
/**
|
|
3
|
-
* Builds an URL using the jetpack.com/redirect/ service
|
|
4
|
-
*
|
|
5
|
-
* If source is a simple slug, it will be sent using the source query parameter. e.g. jetpack.com/redirect/?source=slug
|
|
6
|
-
*
|
|
7
|
-
* If source is a full URL, starting with https://, it will be sent using the url query parameter. e.g. jetpack.com/redirect/?url=https://wordpress.com
|
|
8
|
-
*
|
|
9
|
-
* Note: if using full URL, query parameters and anchor must be passed in args. Any querystring of url fragment in the URL will be discarded.
|
|
10
|
-
*
|
|
11
|
-
* @since 0.2.0
|
|
12
|
-
* @param {string} source - The URL handler registered in the server or the full destination URL (starting with https://).
|
|
13
|
-
* @param {GetRedirectUrlArgs} args - Additional arguments to build the url.
|
|
14
|
-
* This is not a complete list as any argument passed here
|
|
15
|
-
* will be sent to as a query parameter to the Redirect server.
|
|
16
|
-
* These parameters will not necessarily be passed over to the final destination URL.
|
|
17
|
-
* If you want to add a parameter to the final destination URL, use the `query` argument.
|
|
18
|
-
* @return {string} The redirect URL
|
|
19
|
-
*/
|
|
20
|
-
export default function getRedirectUrl(source, args = {}) {
|
|
21
|
-
const queryVars = {};
|
|
22
|
-
let calypsoEnv;
|
|
23
|
-
if (typeof window !== 'undefined') {
|
|
24
|
-
calypsoEnv = window?.JP_CONNECTION_INITIAL_STATE?.calypsoEnv;
|
|
25
|
-
}
|
|
26
|
-
if (source.search('https://') === 0) {
|
|
27
|
-
const parsedUrl = new URL(source);
|
|
28
|
-
// discard any query and fragments.
|
|
29
|
-
source = `https://${parsedUrl.host}${parsedUrl.pathname}`;
|
|
30
|
-
queryVars.url = encodeURIComponent(source);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
queryVars.source = encodeURIComponent(source);
|
|
34
|
-
}
|
|
35
|
-
for (const argName in args) {
|
|
36
|
-
queryVars[argName] = encodeURIComponent(args[argName]);
|
|
37
|
-
}
|
|
38
|
-
if (!Object.keys(queryVars).includes('site') &&
|
|
39
|
-
typeof jetpack_redirects !== 'undefined' &&
|
|
40
|
-
Object.hasOwn(jetpack_redirects, 'currentSiteRawUrl')) {
|
|
41
|
-
queryVars.site = jetpack_redirects.currentBlogID ?? jetpack_redirects.currentSiteRawUrl;
|
|
42
|
-
}
|
|
43
|
-
if (calypsoEnv) {
|
|
44
|
-
queryVars.calypso_env = calypsoEnv;
|
|
45
|
-
}
|
|
46
|
-
const queryString = Object.keys(queryVars)
|
|
47
|
-
.map(key => key + '=' + queryVars[key])
|
|
48
|
-
.join('&');
|
|
49
|
-
return `https://jetpack.com/redirect/?` + queryString;
|
|
50
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export type GetRedirectUrlArgs = {
|
|
2
|
-
/**
|
|
3
|
-
* URL of the current site. Will default to the value of
|
|
4
|
-
* jetpack_redirects.currentSiteRawUrl, if available.
|
|
5
|
-
* Used to fill in the `[site]` placeholder in the target.
|
|
6
|
-
*/
|
|
7
|
-
site?: string;
|
|
8
|
-
/**
|
|
9
|
-
* Additional path to be appended to the URL.
|
|
10
|
-
* Used to fill in the `[path]` placeholder in the target.
|
|
11
|
-
*/
|
|
12
|
-
path?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Query parameters to be added to the final destination URL.
|
|
15
|
-
* Should be in query string format (e.g. 'key=value&foo=bar').
|
|
16
|
-
*/
|
|
17
|
-
query?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Anchor to be added to the URL. Must be a single string.
|
|
20
|
-
* Example: `section1`.
|
|
21
|
-
*/
|
|
22
|
-
anchor?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Any other custom arguments to be added to the final destination URL.
|
|
25
|
-
*/
|
|
26
|
-
[key: string]: string;
|
|
27
|
-
};
|
|
28
|
-
export type QueryVars = {
|
|
29
|
-
url?: string;
|
|
30
|
-
site?: string;
|
|
31
|
-
source?: string;
|
|
32
|
-
calypso_env?: string;
|
|
33
|
-
};
|
|
34
|
-
declare global {
|
|
35
|
-
const jetpack_redirects: {
|
|
36
|
-
currentSiteRawUrl?: string;
|
|
37
|
-
currentBlogID?: string;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/build/{ai-client/src/components → components}/audio-duration-display/lib/media.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|