@automattic/jetpack-ai-client 0.18.1 → 0.19.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 CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.19.0] - 2024-09-23
9
+ ### Changed
10
+ - AI Client: Don't send a default style to jetpack-ai-image endpoint, default is handled in backend and we need to not send it until we're ready for it to be a user option. [#39494]
11
+ - Jetpack AI: Point upgrade links and buttons to checkout instead of product interstitial. [#39469]
12
+ - Logo generator: Get selection from the prompt's document rather than the global `window`. [#39364]
13
+
8
14
  ## [0.18.1] - 2024-09-10
9
15
  ### Changed
10
16
  - Updated package dependencies. [#39302]
@@ -409,6 +415,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
409
415
  - Updated package dependencies. [#31659]
410
416
  - Updated package dependencies. [#31785]
411
417
 
418
+ [0.19.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.18.1...v0.19.0
412
419
  [0.18.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.18.0...v0.18.1
413
420
  [0.18.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.17.0...v0.18.0
414
421
  [0.17.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.16.4...v0.17.0
@@ -168,7 +168,6 @@ const useImageGenerator = () => {
168
168
  prompt,
169
169
  feature,
170
170
  model: 'stable-diffusion',
171
- style: 'photographic',
172
171
  };
173
172
  const data = await executeImageGeneration(parameters);
174
173
  return data;
@@ -74,7 +74,7 @@ export const Prompt = ({ initialPrompt = '' }) => {
74
74
  };
75
75
  const onPromptPaste = (event) => {
76
76
  event.preventDefault();
77
- const selection = window.getSelection();
77
+ const selection = event.currentTarget.ownerDocument.getSelection();
78
78
  if (!selection || !selection.rangeCount) {
79
79
  return;
80
80
  }
@@ -17,18 +17,27 @@ export const useCheckout = () => {
17
17
  tierPlansEnabled: selectors.getAiAssistantFeature().tierPlansEnabled,
18
18
  };
19
19
  }, []);
20
+ const isJetpackSite = !isAtomicSite() && !isSimpleSite();
21
+ const redirectSource = isJetpackSite
22
+ ? 'jetpack-ai-upgrade-url-for-jetpack-sites'
23
+ : 'jetpack-ai-yearly-tier-upgrade-nudge';
20
24
  /**
21
- * Use the Jetpack redirect URL to open the checkout page
25
+ * Determine the post-checkout URL for non-Jetpack sites
22
26
  */
23
- const wpcomCheckoutUrl = new URL(`https://jetpack.com/redirect/`);
24
- wpcomCheckoutUrl.searchParams.set('source', 'jetpack-ai-yearly-tier-upgrade-nudge');
25
- wpcomCheckoutUrl.searchParams.set('site', getSiteFragment());
26
- wpcomCheckoutUrl.searchParams.set('path', tierPlansEnabled ? `jetpack_ai_yearly:-q-${nextTier?.limit}` : 'jetpack_ai_yearly');
27
+ const siteFragment = getSiteFragment();
28
+ const wpcomRedirectToURL = `https://wordpress.com/home/${siteFragment}`;
27
29
  /**
28
- * Open the product interstitial page
30
+ * Use the Jetpack redirect URL to open the checkout page
29
31
  */
30
- const jetpackCheckoutUrl = `${window?.Jetpack_Editor_Initial_State?.adminUrl}admin.php?redirect_to_referrer=1&page=my-jetpack#/add-jetpack-ai`;
31
- const nextTierCheckoutURL = isAtomicSite() || isSimpleSite() ? wpcomCheckoutUrl.toString() : jetpackCheckoutUrl;
32
+ const checkoutUrl = new URL(`https://jetpack.com/redirect/`);
33
+ checkoutUrl.searchParams.set('source', redirectSource);
34
+ checkoutUrl.searchParams.set('site', siteFragment);
35
+ checkoutUrl.searchParams.set('path', tierPlansEnabled ? `jetpack_ai_yearly:-q-${nextTier?.limit}` : 'jetpack_ai_yearly');
36
+ // For Jetpack sites, the redirect_to parameter is handled by the Jetpack redirect source
37
+ if (!isJetpackSite) {
38
+ checkoutUrl.searchParams.set('query', `redirect_to=${encodeURIComponent(wpcomRedirectToURL)}`);
39
+ }
40
+ const nextTierCheckoutURL = checkoutUrl.toString();
32
41
  debug('Next tier checkout URL: ', nextTierCheckoutURL);
33
42
  return {
34
43
  nextTierCheckoutURL,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@automattic/jetpack-ai-client",
4
- "version": "0.18.1",
4
+ "version": "0.19.0",
5
5
  "description": "A JS client for consuming Jetpack AI services",
6
6
  "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/ai-client/#readme",
7
7
  "bugs": {
@@ -44,8 +44,8 @@
44
44
  "types": "./build/index.d.ts",
45
45
  "dependencies": {
46
46
  "@automattic/jetpack-base-styles": "^0.6.32",
47
- "@automattic/jetpack-connection": "^0.35.7",
48
- "@automattic/jetpack-shared-extension-utils": "^0.15.9",
47
+ "@automattic/jetpack-connection": "^0.35.8",
48
+ "@automattic/jetpack-shared-extension-utils": "^0.15.10",
49
49
  "@microsoft/fetch-event-source": "2.0.1",
50
50
  "@types/react": "18.3.3",
51
51
  "@types/wordpress__block-editor": "11.5.15",
@@ -214,7 +214,6 @@ const useImageGenerator = () => {
214
214
  prompt,
215
215
  feature,
216
216
  model: 'stable-diffusion',
217
- style: 'photographic',
218
217
  };
219
218
 
220
219
  const data: ImageGenerationResponse = await executeImageGeneration( parameters );
@@ -102,7 +102,7 @@ export const Prompt: React.FC< { initialPrompt?: string } > = ( { initialPrompt
102
102
  const onPromptPaste = ( event: React.ClipboardEvent< HTMLInputElement > ) => {
103
103
  event.preventDefault();
104
104
 
105
- const selection = window.getSelection();
105
+ const selection = event.currentTarget.ownerDocument.getSelection();
106
106
  if ( ! selection || ! selection.rangeCount ) {
107
107
  return;
108
108
  }
@@ -28,25 +28,37 @@ export const useCheckout = () => {
28
28
  };
29
29
  }, [] );
30
30
 
31
+ const isJetpackSite = ! isAtomicSite() && ! isSimpleSite();
32
+ const redirectSource = isJetpackSite
33
+ ? 'jetpack-ai-upgrade-url-for-jetpack-sites'
34
+ : 'jetpack-ai-yearly-tier-upgrade-nudge';
35
+
31
36
  /**
32
- * Use the Jetpack redirect URL to open the checkout page
37
+ * Determine the post-checkout URL for non-Jetpack sites
33
38
  */
34
- const wpcomCheckoutUrl = new URL( `https://jetpack.com/redirect/` );
35
- wpcomCheckoutUrl.searchParams.set( 'source', 'jetpack-ai-yearly-tier-upgrade-nudge' );
36
- wpcomCheckoutUrl.searchParams.set( 'site', getSiteFragment() as string );
39
+ const siteFragment = getSiteFragment() as string;
40
+ const wpcomRedirectToURL = `https://wordpress.com/home/${ siteFragment }`;
37
41
 
38
- wpcomCheckoutUrl.searchParams.set(
42
+ /**
43
+ * Use the Jetpack redirect URL to open the checkout page
44
+ */
45
+ const checkoutUrl = new URL( `https://jetpack.com/redirect/` );
46
+ checkoutUrl.searchParams.set( 'source', redirectSource );
47
+ checkoutUrl.searchParams.set( 'site', siteFragment );
48
+ checkoutUrl.searchParams.set(
39
49
  'path',
40
50
  tierPlansEnabled ? `jetpack_ai_yearly:-q-${ nextTier?.limit }` : 'jetpack_ai_yearly'
41
51
  );
42
52
 
43
- /**
44
- * Open the product interstitial page
45
- */
46
- const jetpackCheckoutUrl = `${ window?.Jetpack_Editor_Initial_State?.adminUrl }admin.php?redirect_to_referrer=1&page=my-jetpack#/add-jetpack-ai`;
53
+ // For Jetpack sites, the redirect_to parameter is handled by the Jetpack redirect source
54
+ if ( ! isJetpackSite ) {
55
+ checkoutUrl.searchParams.set(
56
+ 'query',
57
+ `redirect_to=${ encodeURIComponent( wpcomRedirectToURL ) }`
58
+ );
59
+ }
47
60
 
48
- const nextTierCheckoutURL =
49
- isAtomicSite() || isSimpleSite() ? wpcomCheckoutUrl.toString() : jetpackCheckoutUrl;
61
+ const nextTierCheckoutURL = checkoutUrl.toString();
50
62
 
51
63
  debug( 'Next tier checkout URL: ', nextTierCheckoutURL );
52
64