@automattic/jetpack-ai-client 0.20.1 → 0.22.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.
Files changed (174) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/{hooks → ai-client/src/hooks}/use-image-generator/constants.d.ts +6 -20
  3. package/build/ai-client/src/hooks/use-image-generator/constants.js +21 -0
  4. package/build/{hooks → ai-client/src/hooks}/use-image-generator/index.d.ts +0 -1
  5. package/build/{hooks → ai-client/src/hooks}/use-image-generator/index.js +0 -10
  6. package/build/{logo-generator → ai-client/src/logo-generator}/components/generator-modal.js +27 -8
  7. package/build/{logo-generator → ai-client/src/logo-generator}/components/history-carousel.js +1 -1
  8. package/build/{logo-generator → ai-client/src/logo-generator}/components/logo-presenter.js +8 -2
  9. package/build/ai-client/src/logo-generator/components/prompt.d.ts +6 -0
  10. package/build/{logo-generator → ai-client/src/logo-generator}/components/prompt.js +47 -19
  11. package/build/{logo-generator → ai-client/src/logo-generator}/components/upgrade-screen.js +6 -2
  12. package/build/{logo-generator → ai-client/src/logo-generator}/constants.d.ts +1 -0
  13. package/build/{logo-generator → ai-client/src/logo-generator}/constants.js +1 -0
  14. package/build/{logo-generator → ai-client/src/logo-generator}/hooks/use-checkout.js +0 -3
  15. package/build/{logo-generator → ai-client/src/logo-generator}/hooks/use-fair-usage-notice-message.js +5 -1
  16. package/build/{logo-generator → ai-client/src/logo-generator}/hooks/use-logo-generator.d.ts +3 -2
  17. package/build/{logo-generator → ai-client/src/logo-generator}/hooks/use-logo-generator.js +57 -3
  18. package/build/{logo-generator → ai-client/src/logo-generator}/store/constants.d.ts +1 -1
  19. package/build/{logo-generator → ai-client/src/logo-generator}/store/constants.js +1 -1
  20. package/build/{logo-generator → ai-client/src/logo-generator}/store/initial-state.js +6 -0
  21. package/build/{logo-generator → ai-client/src/logo-generator}/store/types.d.ts +6 -4
  22. package/build/{logo-generator → ai-client/src/logo-generator}/types.d.ts +0 -1
  23. package/build/{types.d.ts → ai-client/src/types.d.ts} +6 -1
  24. package/build/{types.js → ai-client/src/types.js} +4 -0
  25. package/build/components/tools/jp-redirect/index.d.ts +20 -0
  26. package/build/components/tools/jp-redirect/index.js +50 -0
  27. package/build/components/tools/jp-redirect/types.d.ts +39 -0
  28. package/build/components/tools/jp-redirect/types.js +1 -0
  29. package/package.json +18 -18
  30. package/src/hooks/use-image-generator/constants.ts +27 -23
  31. package/src/hooks/use-image-generator/index.ts +0 -11
  32. package/src/logo-generator/components/generator-modal.tsx +29 -9
  33. package/src/logo-generator/components/history-carousel.tsx +1 -0
  34. package/src/logo-generator/components/logo-presenter.tsx +15 -1
  35. package/src/logo-generator/components/prompt.tsx +55 -24
  36. package/src/logo-generator/components/upgrade-screen.tsx +8 -2
  37. package/src/logo-generator/constants.ts +1 -0
  38. package/src/logo-generator/hooks/use-checkout.ts +0 -5
  39. package/src/logo-generator/hooks/use-fair-usage-notice-message.tsx +6 -7
  40. package/src/logo-generator/hooks/use-logo-generator.ts +100 -31
  41. package/src/logo-generator/store/constants.ts +1 -1
  42. package/src/logo-generator/store/initial-state.ts +6 -0
  43. package/src/logo-generator/store/types.ts +9 -4
  44. package/src/logo-generator/types.ts +0 -1
  45. package/src/types.ts +12 -1
  46. package/build/hooks/use-image-generator/constants.js +0 -40
  47. package/build/logo-generator/components/prompt.d.ts +0 -7
  48. /package/build/{api-fetch → ai-client/src/api-fetch}/index.d.ts +0 -0
  49. /package/build/{api-fetch → ai-client/src/api-fetch}/index.js +0 -0
  50. /package/build/{ask-question → ai-client/src/ask-question}/index.d.ts +0 -0
  51. /package/build/{ask-question → ai-client/src/ask-question}/index.js +0 -0
  52. /package/build/{ask-question → ai-client/src/ask-question}/sync.d.ts +0 -0
  53. /package/build/{ask-question → ai-client/src/ask-question}/sync.js +0 -0
  54. /package/build/{audio-transcription → ai-client/src/audio-transcription}/index.d.ts +0 -0
  55. /package/build/{audio-transcription → ai-client/src/audio-transcription}/index.js +0 -0
  56. /package/build/{components → ai-client/src/components}/ai-control/ai-control.d.ts +0 -0
  57. /package/build/{components → ai-client/src/components}/ai-control/ai-control.js +0 -0
  58. /package/build/{components → ai-client/src/components}/ai-control/block-ai-control.d.ts +0 -0
  59. /package/build/{components → ai-client/src/components}/ai-control/block-ai-control.js +0 -0
  60. /package/build/{components → ai-client/src/components}/ai-control/extension-ai-control.d.ts +0 -0
  61. /package/build/{components → ai-client/src/components}/ai-control/extension-ai-control.js +0 -0
  62. /package/build/{components → ai-client/src/components}/ai-control/index.d.ts +0 -0
  63. /package/build/{components → ai-client/src/components}/ai-control/index.js +0 -0
  64. /package/build/{components → ai-client/src/components}/ai-status-indicator/index.d.ts +0 -0
  65. /package/build/{components → ai-client/src/components}/ai-status-indicator/index.js +0 -0
  66. /package/build/{components → ai-client/src/components}/audio-duration-display/index.d.ts +0 -0
  67. /package/build/{components → ai-client/src/components}/audio-duration-display/index.js +0 -0
  68. /package/build/{components → ai-client/src/components}/audio-duration-display/lib/media.d.ts +0 -0
  69. /package/build/{components → ai-client/src/components}/audio-duration-display/lib/media.js +0 -0
  70. /package/build/{components → ai-client/src/components}/index.d.ts +0 -0
  71. /package/build/{components → ai-client/src/components}/index.js +0 -0
  72. /package/build/{components → ai-client/src/components}/message/index.d.ts +0 -0
  73. /package/build/{components → ai-client/src/components}/message/index.js +0 -0
  74. /package/build/{data-flow → ai-client/src/data-flow}/context.d.ts +0 -0
  75. /package/build/{data-flow → ai-client/src/data-flow}/context.js +0 -0
  76. /package/build/{data-flow → ai-client/src/data-flow}/index.d.ts +0 -0
  77. /package/build/{data-flow → ai-client/src/data-flow}/index.js +0 -0
  78. /package/build/{data-flow → ai-client/src/data-flow}/use-ai-context.d.ts +0 -0
  79. /package/build/{data-flow → ai-client/src/data-flow}/use-ai-context.js +0 -0
  80. /package/build/{data-flow → ai-client/src/data-flow}/with-ai-assistant-data.d.ts +0 -0
  81. /package/build/{data-flow → ai-client/src/data-flow}/with-ai-assistant-data.js +0 -0
  82. /package/build/{hooks → ai-client/src/hooks}/use-ai-suggestions/index.d.ts +0 -0
  83. /package/build/{hooks → ai-client/src/hooks}/use-ai-suggestions/index.js +0 -0
  84. /package/build/{hooks → ai-client/src/hooks}/use-audio-transcription/index.d.ts +0 -0
  85. /package/build/{hooks → ai-client/src/hooks}/use-audio-transcription/index.js +0 -0
  86. /package/build/{hooks → ai-client/src/hooks}/use-audio-validation/index.d.ts +0 -0
  87. /package/build/{hooks → ai-client/src/hooks}/use-audio-validation/index.js +0 -0
  88. /package/build/{hooks → ai-client/src/hooks}/use-media-recording/index.d.ts +0 -0
  89. /package/build/{hooks → ai-client/src/hooks}/use-media-recording/index.js +0 -0
  90. /package/build/{hooks → ai-client/src/hooks}/use-save-to-media-library/index.d.ts +0 -0
  91. /package/build/{hooks → ai-client/src/hooks}/use-save-to-media-library/index.js +0 -0
  92. /package/build/{hooks → ai-client/src/hooks}/use-transcription-post-processing/index.d.ts +0 -0
  93. /package/build/{hooks → ai-client/src/hooks}/use-transcription-post-processing/index.js +0 -0
  94. /package/build/{icons → ai-client/src/icons}/ai-assistant.d.ts +0 -0
  95. /package/build/{icons → ai-client/src/icons}/ai-assistant.js +0 -0
  96. /package/build/{icons → ai-client/src/icons}/error-exclamation.d.ts +0 -0
  97. /package/build/{icons → ai-client/src/icons}/error-exclamation.js +0 -0
  98. /package/build/{icons → ai-client/src/icons}/index.d.ts +0 -0
  99. /package/build/{icons → ai-client/src/icons}/index.js +0 -0
  100. /package/build/{icons → ai-client/src/icons}/mic.d.ts +0 -0
  101. /package/build/{icons → ai-client/src/icons}/mic.js +0 -0
  102. /package/build/{icons → ai-client/src/icons}/origami-plane.d.ts +0 -0
  103. /package/build/{icons → ai-client/src/icons}/origami-plane.js +0 -0
  104. /package/build/{icons → ai-client/src/icons}/player-pause.d.ts +0 -0
  105. /package/build/{icons → ai-client/src/icons}/player-pause.js +0 -0
  106. /package/build/{icons → ai-client/src/icons}/player-play.d.ts +0 -0
  107. /package/build/{icons → ai-client/src/icons}/player-play.js +0 -0
  108. /package/build/{icons → ai-client/src/icons}/player-stop.d.ts +0 -0
  109. /package/build/{icons → ai-client/src/icons}/player-stop.js +0 -0
  110. /package/build/{icons → ai-client/src/icons}/speak-tone.d.ts +0 -0
  111. /package/build/{icons → ai-client/src/icons}/speak-tone.js +0 -0
  112. /package/build/{index.d.ts → ai-client/src/index.d.ts} +0 -0
  113. /package/build/{index.js → ai-client/src/index.js} +0 -0
  114. /package/build/{jwt → ai-client/src/jwt}/index.d.ts +0 -0
  115. /package/build/{jwt → ai-client/src/jwt}/index.js +0 -0
  116. /package/build/{libs → ai-client/src/libs}/index.d.ts +0 -0
  117. /package/build/{libs → ai-client/src/libs}/index.js +0 -0
  118. /package/build/{libs → ai-client/src/libs}/markdown/html-to-markdown.d.ts +0 -0
  119. /package/build/{libs → ai-client/src/libs}/markdown/html-to-markdown.js +0 -0
  120. /package/build/{libs → ai-client/src/libs}/markdown/index.d.ts +0 -0
  121. /package/build/{libs → ai-client/src/libs}/markdown/index.js +0 -0
  122. /package/build/{libs → ai-client/src/libs}/markdown/markdown-to-html.d.ts +0 -0
  123. /package/build/{libs → ai-client/src/libs}/markdown/markdown-to-html.js +0 -0
  124. /package/build/{logo-generator → ai-client/src/logo-generator}/assets/icons/ai.d.ts +0 -0
  125. /package/build/{logo-generator → ai-client/src/logo-generator}/assets/icons/ai.js +0 -0
  126. /package/build/{logo-generator → ai-client/src/logo-generator}/assets/icons/check.d.ts +0 -0
  127. /package/build/{logo-generator → ai-client/src/logo-generator}/assets/icons/check.js +0 -0
  128. /package/build/{logo-generator → ai-client/src/logo-generator}/assets/icons/logo.d.ts +0 -0
  129. /package/build/{logo-generator → ai-client/src/logo-generator}/assets/icons/logo.js +0 -0
  130. /package/build/{logo-generator → ai-client/src/logo-generator}/assets/icons/media.d.ts +0 -0
  131. /package/build/{logo-generator → ai-client/src/logo-generator}/assets/icons/media.js +0 -0
  132. /package/build/{logo-generator → ai-client/src/logo-generator}/components/fair-usage-notice.d.ts +0 -0
  133. /package/build/{logo-generator → ai-client/src/logo-generator}/components/fair-usage-notice.js +0 -0
  134. /package/build/{logo-generator → ai-client/src/logo-generator}/components/feature-fetch-failure-screen.d.ts +0 -0
  135. /package/build/{logo-generator → ai-client/src/logo-generator}/components/feature-fetch-failure-screen.js +0 -0
  136. /package/build/{logo-generator → ai-client/src/logo-generator}/components/first-load-screen.d.ts +0 -0
  137. /package/build/{logo-generator → ai-client/src/logo-generator}/components/first-load-screen.js +0 -0
  138. /package/build/{logo-generator → ai-client/src/logo-generator}/components/generator-modal.d.ts +0 -0
  139. /package/build/{logo-generator → ai-client/src/logo-generator}/components/history-carousel.d.ts +0 -0
  140. /package/build/{logo-generator → ai-client/src/logo-generator}/components/image-loader.d.ts +0 -0
  141. /package/build/{logo-generator → ai-client/src/logo-generator}/components/image-loader.js +0 -0
  142. /package/build/{logo-generator → ai-client/src/logo-generator}/components/logo-presenter.d.ts +0 -0
  143. /package/build/{logo-generator → ai-client/src/logo-generator}/components/upgrade-nudge.d.ts +0 -0
  144. /package/build/{logo-generator → ai-client/src/logo-generator}/components/upgrade-nudge.js +0 -0
  145. /package/build/{logo-generator → ai-client/src/logo-generator}/components/upgrade-screen.d.ts +0 -0
  146. /package/build/{logo-generator → ai-client/src/logo-generator}/components/visit-site-banner.d.ts +0 -0
  147. /package/build/{logo-generator → ai-client/src/logo-generator}/components/visit-site-banner.js +0 -0
  148. /package/build/{logo-generator → ai-client/src/logo-generator}/hooks/use-checkout.d.ts +0 -0
  149. /package/build/{logo-generator → ai-client/src/logo-generator}/hooks/use-fair-usage-notice-message.d.ts +0 -0
  150. /package/build/{logo-generator → ai-client/src/logo-generator}/hooks/use-request-errors.d.ts +0 -0
  151. /package/build/{logo-generator → ai-client/src/logo-generator}/hooks/use-request-errors.js +0 -0
  152. /package/build/{logo-generator → ai-client/src/logo-generator}/index.d.ts +0 -0
  153. /package/build/{logo-generator → ai-client/src/logo-generator}/index.js +0 -0
  154. /package/build/{logo-generator → ai-client/src/logo-generator}/lib/logo-storage.d.ts +0 -0
  155. /package/build/{logo-generator → ai-client/src/logo-generator}/lib/logo-storage.js +0 -0
  156. /package/build/{logo-generator → ai-client/src/logo-generator}/lib/media-exists.d.ts +0 -0
  157. /package/build/{logo-generator → ai-client/src/logo-generator}/lib/media-exists.js +0 -0
  158. /package/build/{logo-generator → ai-client/src/logo-generator}/lib/set-site-logo.d.ts +0 -0
  159. /package/build/{logo-generator → ai-client/src/logo-generator}/lib/set-site-logo.js +0 -0
  160. /package/build/{logo-generator → ai-client/src/logo-generator}/lib/wpcom-limited-request.d.ts +0 -0
  161. /package/build/{logo-generator → ai-client/src/logo-generator}/lib/wpcom-limited-request.js +0 -0
  162. /package/build/{logo-generator → ai-client/src/logo-generator}/store/actions.d.ts +0 -0
  163. /package/build/{logo-generator → ai-client/src/logo-generator}/store/actions.js +0 -0
  164. /package/build/{logo-generator → ai-client/src/logo-generator}/store/index.d.ts +0 -0
  165. /package/build/{logo-generator → ai-client/src/logo-generator}/store/index.js +0 -0
  166. /package/build/{logo-generator → ai-client/src/logo-generator}/store/initial-state.d.ts +0 -0
  167. /package/build/{logo-generator → ai-client/src/logo-generator}/store/reducer.d.ts +0 -0
  168. /package/build/{logo-generator → ai-client/src/logo-generator}/store/reducer.js +0 -0
  169. /package/build/{logo-generator → ai-client/src/logo-generator}/store/selectors.d.ts +0 -0
  170. /package/build/{logo-generator → ai-client/src/logo-generator}/store/selectors.js +0 -0
  171. /package/build/{logo-generator → ai-client/src/logo-generator}/store/types.js +0 -0
  172. /package/build/{logo-generator → ai-client/src/logo-generator}/types.js +0 -0
  173. /package/build/{suggestions-event-source → ai-client/src/suggestions-event-source}/index.d.ts +0 -0
  174. /package/build/{suggestions-event-source → ai-client/src/suggestions-event-source}/index.js +0 -0
@@ -7,6 +7,7 @@ import { __ } from '@wordpress/i18n';
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
10
+ import getRedirectUrl from '../../../../components/tools/jp-redirect/index.js';
10
11
  import { EVENT_PLACEMENT_FREE_USER_SCREEN, EVENT_UPGRADE } from '../constants.js';
11
12
  import useLogoGenerator from '../hooks/use-logo-generator.js';
12
13
  /**
@@ -21,8 +22,9 @@ export const UpgradeScreen: React.FC< {
21
22
  } > = ( { onCancel, upgradeURL, reason } ) => {
22
23
  const { tracks } = useAnalytics();
23
24
  const { recordEvent: recordTracksEvent } = tracks;
25
+
24
26
  const upgradeMessageFeature = __(
25
- 'The logo generator requires a paid Jetpack AI plan. Upgrade your plan to access exclusive features, including logo generation. The upgrade will also increase the amount of requests you can use in all AI-powered features.',
27
+ 'Upgrade your Jetpack AI for access to logo generation. This upgrade will also increase the amount of monthly requests you can use in for all AI-powered features.',
26
28
  'jetpack-ai-client'
27
29
  );
28
30
 
@@ -31,6 +33,10 @@ export const UpgradeScreen: React.FC< {
31
33
  'jetpack-ai-client'
32
34
  );
33
35
 
36
+ const upgradeInfoUrl = getRedirectUrl( 'ai-logo-generator-fair-usage-policy', {
37
+ anchor: 'usage-limitations-and-upgrades',
38
+ } );
39
+
34
40
  const { context } = useLogoGenerator();
35
41
 
36
42
  const handleUpgradeClick = () => {
@@ -45,7 +51,7 @@ export const UpgradeScreen: React.FC< {
45
51
  { reason === 'feature' ? upgradeMessageFeature : upgradeMessageRequests }
46
52
  </span>
47
53
  &nbsp;
48
- <Button variant="link" href="https://jetpack.com/ai/" target="_blank">
54
+ <Button variant="link" href={ upgradeInfoUrl } target="_blank">
49
55
  { __( 'Learn more about Jetpack AI.', 'jetpack-ai-client' ) }
50
56
  </Button>
51
57
  </div>
@@ -11,6 +11,7 @@ export const EVENT_NAVIGATE = 'jetpack_ai_logo_generator_navigate';
11
11
  export const EVENT_FEEDBACK = 'jetpack_ai_logo_generator_feedback';
12
12
  export const EVENT_UPGRADE = 'jetpack_ai_upgrade_button';
13
13
  export const EVENT_SWITCH_STYLE = 'jetpack_ai_logo_generator_switch_style';
14
+ export const EVENT_GUESS_STYLE = 'jetpack_ai_logo_generator_guess_style';
14
15
 
15
16
  // Event placement constants
16
17
  export const EVENT_PLACEMENT_QUICK_LINKS = 'quick_links';
@@ -7,7 +7,6 @@ import {
7
7
  getSiteFragment,
8
8
  } from '@automattic/jetpack-shared-extension-utils';
9
9
  import { useSelect } from '@wordpress/data';
10
- import debugFactory from 'debug';
11
10
  /**
12
11
  * Internal dependencies
13
12
  */
@@ -17,8 +16,6 @@ import { STORE_NAME } from '../store/index.js';
17
16
  */
18
17
  import type { Selectors } from '../store/types.js';
19
18
 
20
- const debug = debugFactory( 'ai-client:logo-generator:use-checkout' );
21
-
22
19
  export const useCheckout = () => {
23
20
  const { nextTier, tierPlansEnabled } = useSelect( select => {
24
21
  const selectors: Selectors = select( STORE_NAME );
@@ -60,8 +57,6 @@ export const useCheckout = () => {
60
57
 
61
58
  const nextTierCheckoutURL = checkoutUrl.toString();
62
59
 
63
- debug( 'Next tier checkout URL: ', nextTierCheckoutURL );
64
-
65
60
  return {
66
61
  nextTierCheckoutURL,
67
62
  hasNextTier: !! nextTier,
@@ -1,6 +1,7 @@
1
1
  import { useSelect } from '@wordpress/data';
2
2
  import { createInterpolateElement } from '@wordpress/element';
3
3
  import { __, sprintf } from '@wordpress/i18n';
4
+ import getRedirectUrl from '../../../../components/tools/jp-redirect/index.js';
4
5
  /**
5
6
  * Internal dependencies
6
7
  */
@@ -52,14 +53,12 @@ const useFairUsageNoticeMessage = () => {
52
53
  // Get the proper template based on the presence of the next usage period start date.
53
54
  const fairUsageNoticeMessage = getFairUsageNoticeMessage( nextUsagePeriodStartDateString );
54
55
 
56
+ const upgradeInfoUrl = getRedirectUrl( 'ai-logo-generator-fair-usage-policy', {
57
+ anchor: 'jetpack-ai-usage-limit',
58
+ } );
59
+
55
60
  const fairUsageNoticeMessageElement = createInterpolateElement( fairUsageNoticeMessage, {
56
- link: (
57
- <a
58
- href="https://jetpack.com/redirect/?source=ai-logo-generator-fair-usage-policy"
59
- target="_blank"
60
- rel="noreferrer"
61
- />
62
- ),
61
+ link: <a href={ upgradeInfoUrl } target="_blank" rel="noreferrer" />,
63
62
  } );
64
63
 
65
64
  return fairUsageNoticeMessageElement;
@@ -7,6 +7,7 @@ import { useCallback } from 'react';
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
10
+ import askQuestionSync from '../../ask-question/sync.js';
10
11
  import useImageGenerator from '../../hooks/use-image-generator/index.js';
11
12
  import useSaveToMediaLibrary from '../../hooks/use-save-to-media-library/index.js';
12
13
  import requestJwt from '../../jwt/index.js';
@@ -17,8 +18,9 @@ import useRequestErrors from './use-request-errors.js';
17
18
  /**
18
19
  * Types
19
20
  */
20
- import type { ImageStyle } from '../../hooks/use-image-generator/constants.js';
21
- import type { Logo, Selectors, SaveLogo } from '../store/types.js';
21
+ import type { ImageStyle, ImageStyleObject } from '../../hooks/use-image-generator/constants.js';
22
+ import type { RoleType } from '../../types.js';
23
+ import type { Logo, Selectors, SaveLogo, LogoGeneratorFeatureControl } from '../store/types.js';
22
24
 
23
25
  const debug = debugFactory( 'jetpack-ai-calypso:use-logo-generator' );
24
26
 
@@ -79,7 +81,7 @@ const useLogoGenerator = () => {
79
81
  setLogoUpdateError,
80
82
  } = useRequestErrors();
81
83
 
82
- const { generateImageWithParameters, getImageStyles } = useImageGenerator();
84
+ const { generateImageWithParameters } = useImageGenerator();
83
85
  const { saveToMediaLibrary } = useSaveToMediaLibrary();
84
86
 
85
87
  const { ID = null, name = null, description = null } = siteDetails || {};
@@ -87,6 +89,10 @@ const useLogoGenerator = () => {
87
89
 
88
90
  const aiAssistantFeatureData = getAiAssistantFeature( siteId );
89
91
  const logoGenerationCost = aiAssistantFeatureData?.costs?.[ 'jetpack-ai-logo-generator' ]?.logo;
92
+ const logoGeneratorControl = aiAssistantFeatureData?.featuresControl?.[
93
+ 'logo-generator'
94
+ ] as LogoGeneratorFeatureControl;
95
+ const imageStyles: Array< ImageStyleObject > = logoGeneratorControl?.styles;
90
96
 
91
97
  const generateFirstPrompt = useCallback(
92
98
  async function (): Promise< string > {
@@ -192,25 +198,70 @@ For example: user's prompt: A logo for an ice cream shop. Returned prompt: A log
192
198
  }
193
199
  };
194
200
 
195
- const generateImage = useCallback( async function ( {
196
- prompt,
197
- style = null,
198
- }: {
199
- prompt: string;
200
- style?: ImageStyle | null;
201
- } ): Promise< { data: Array< { url: string } > } > {
202
- setLogoFetchError( null );
201
+ const guessStyle = useCallback(
202
+ async function ( prompt: string ): Promise< ImageStyle | null > {
203
+ setLogoFetchError( null );
204
+ if ( ! imageStyles || ! imageStyles.length ) {
205
+ return null;
206
+ }
203
207
 
204
- try {
205
- const tokenData = await requestJwt();
208
+ const messages = [
209
+ {
210
+ role: 'jetpack-ai' as RoleType,
211
+ context: {
212
+ type: 'ai-assistant-guess-logo-style',
213
+ request: prompt,
214
+ name,
215
+ description,
216
+ },
217
+ },
218
+ ];
206
219
 
207
- if ( ! tokenData || ! tokenData.token ) {
208
- throw new Error( 'No token provided' );
220
+ try {
221
+ const style = await askQuestionSync( messages, { feature: 'jetpack-ai-logo-generator' } );
222
+
223
+ if ( ! style ) {
224
+ return null;
225
+ }
226
+ const styleObject = imageStyles.find( ( { value } ) => value === style );
227
+
228
+ if ( ! styleObject ) {
229
+ return null;
230
+ }
231
+
232
+ return styleObject.value;
233
+ } catch ( error ) {
234
+ debug( 'Error guessing style', error );
235
+ Promise.reject( error );
209
236
  }
237
+ },
238
+ [ imageStyles, name, description ]
239
+ );
240
+
241
+ const generateImage = useCallback(
242
+ async function ( {
243
+ prompt,
244
+ style = null,
245
+ }: {
246
+ prompt: string;
247
+ style?: ImageStyle | null;
248
+ } ): Promise< { data: Array< { url: string } > } > {
249
+ setLogoFetchError( null );
210
250
 
211
- debug( 'Generating image with prompt', prompt );
251
+ try {
252
+ const tokenData = await requestJwt();
253
+
254
+ if ( ! tokenData || ! tokenData.token ) {
255
+ throw new Error( 'No token provided' );
256
+ }
212
257
 
213
- const imageGenerationPrompt = `I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:
258
+ if ( style === 'auto' ) {
259
+ throw new Error( 'Auto style is not supported' );
260
+ }
261
+
262
+ debug( 'Generating image with prompt', prompt );
263
+
264
+ const imageGenerationPrompt = `I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:
214
265
  Create a single text-free iconic vector logo that symbolically represents the user request, using abstract or symbolic imagery.
215
266
  The design should be modern, with either a vivid color scheme full of gradients or a color scheme that's monochromatic. Use any of those styles based on the user request mood.
216
267
  Ensure the logo is set against a clean solid background.
@@ -220,21 +271,38 @@ The image should contain a single icon, without variations, color palettes or di
220
271
 
221
272
  User request:${ prompt }`;
222
273
 
223
- const body = {
224
- prompt: imageGenerationPrompt,
225
- feature: 'jetpack-ai-logo-generator',
226
- response_format: 'b64_json',
227
- style: style || '', // backend expects an empty string if no style is provided
228
- };
274
+ const body = {
275
+ prompt: imageGenerationPrompt,
276
+ // if style is set prompt is reworked at backend with messages
277
+ messages: style
278
+ ? [
279
+ {
280
+ role: 'jetpack-ai',
281
+ context: {
282
+ type: 'ai-assistant-generate-logo',
283
+ request: prompt,
284
+ name,
285
+ description,
286
+ style,
287
+ },
288
+ },
289
+ ]
290
+ : [],
291
+ feature: 'jetpack-ai-logo-generator',
292
+ response_format: 'b64_json',
293
+ style: style || '', // backend expects an empty string if no style is provided
294
+ };
229
295
 
230
- const data = await generateImageWithParameters( body );
296
+ const data = await generateImageWithParameters( body );
231
297
 
232
- return data as { data: { url: string }[] };
233
- } catch ( error ) {
234
- setLogoFetchError( error );
235
- throw error;
236
- }
237
- }, [] );
298
+ return data as { data: { url: string }[] };
299
+ } catch ( error ) {
300
+ setLogoFetchError( error );
301
+ throw error;
302
+ }
303
+ },
304
+ [ name, description ]
305
+ );
238
306
 
239
307
  const saveLogo = useCallback< SaveLogo >(
240
308
  async logo => {
@@ -401,7 +469,8 @@ User request:${ prompt }`;
401
469
  tierPlansEnabled,
402
470
  isLoadingHistory,
403
471
  setIsLoadingHistory,
404
- getImageStyles,
472
+ imageStyles,
473
+ guessStyle,
405
474
  };
406
475
  };
407
476
 
@@ -18,7 +18,7 @@ export const ENDPOINT_AI_ASSISTANT_FEATURE = '/wpcom/v2/jetpack-ai/ai-assistant-
18
18
  * New AI Assistant feature async request
19
19
  */
20
20
  export const FREE_PLAN_REQUESTS_LIMIT = 20;
21
- export const UNLIMITED_PLAN_REQUESTS_LIMIT = 999999999;
21
+ export const UNLIMITED_PLAN_REQUESTS_LIMIT = 3000;
22
22
  export const ASYNC_REQUEST_COUNTDOWN_INIT_VALUE = 3;
23
23
  export const NEW_ASYNC_REQUEST_TIMER_INTERVAL = 5000;
24
24
  export const ACTION_DECREASE_NEW_ASYNC_REQUEST_COUNTDOWN = 'DECREASE_NEW_ASYNC_REQUEST_COUNTDOWN';
@@ -34,6 +34,12 @@ const INITIAL_STATE: LogoGeneratorStateProp = {
34
34
  asyncRequestTimerId: 0,
35
35
  isRequestingImage: false,
36
36
  },
37
+ featuresControl: {
38
+ 'logo-generator': {
39
+ enabled: false,
40
+ styles: [],
41
+ },
42
+ },
37
43
  },
38
44
  },
39
45
  history: [],
@@ -1,3 +1,4 @@
1
+ import type { ImageStyleObject } from '../../hooks/use-image-generator/constants.js';
1
2
  import type { SiteDetails } from '../types.js';
2
3
 
3
4
  /**
@@ -13,7 +14,7 @@ export type UpgradeTypeProp = 'vip' | 'default';
13
14
 
14
15
  export type TierUnlimitedProps = {
15
16
  slug: 'ai-assistant-tier-unlimited';
16
- limit: 999999999;
17
+ limit: 999999999 | 3000;
17
18
  value: 1;
18
19
  readableLimit: string;
19
20
  };
@@ -88,13 +89,17 @@ export type TierValueProp =
88
89
  | Tier750Props[ 'value' ]
89
90
  | Tier1000Props[ 'value' ];
90
91
 
92
+ export type LogoGeneratorFeatureControl = FeatureControl & {
93
+ styles: Array< ImageStyleObject > | [];
94
+ };
95
+
91
96
  export type FeatureControl = {
92
97
  enabled: boolean;
93
- 'min-jetpack-version': string;
94
- [ key: string ]: FeatureControl | boolean | string;
95
98
  };
96
99
 
97
- export type FeaturesControl = { [ key: string ]: FeatureControl };
100
+ export type FeaturesControl = {
101
+ [ key: string ]: FeatureControl | LogoGeneratorFeatureControl;
102
+ };
98
103
 
99
104
  export type AiFeatureProps = {
100
105
  hasFeature: boolean;
@@ -19,7 +19,6 @@ export interface GeneratorModalProps {
19
19
  onReload: () => void;
20
20
  context: string;
21
21
  placement: string;
22
- showStyleSelector?: boolean;
23
22
  }
24
23
 
25
24
  export interface LogoPresenterProps {
package/src/types.ts CHANGED
@@ -17,11 +17,22 @@ export type SuggestionErrorCode =
17
17
  | typeof ERROR_UNCLEAR_PROMPT
18
18
  | typeof ERROR_RESPONSE;
19
19
 
20
+ export const ROLE_SYSTEM = 'system' as const;
21
+ export const ROLE_USER = 'user' as const;
22
+ export const ROLE_ASSISTANT = 'assistant' as const;
23
+ export const ROLE_JETPACK_AI = 'jetpack-ai' as const;
24
+
25
+ export type RoleType =
26
+ | typeof ROLE_SYSTEM
27
+ | typeof ROLE_USER
28
+ | typeof ROLE_ASSISTANT
29
+ | typeof ROLE_JETPACK_AI;
30
+
20
31
  /*
21
32
  * Prompt types
22
33
  */
23
34
  export type PromptItemProps = {
24
- role: 'system' | 'user' | 'assistant' | 'jetpack-ai';
35
+ role: RoleType;
25
36
  content?: string;
26
37
  context?: object;
27
38
  };
@@ -1,40 +0,0 @@
1
- import { __ } from '@wordpress/i18n';
2
- // Styles
3
- export const IMAGE_STYLE_ENHANCE = 'enhance';
4
- export const IMAGE_STYLE_ANIME = 'anime';
5
- export const IMAGE_STYLE_PHOTOGRAPHIC = 'photographic';
6
- export const IMAGE_STYLE_DIGITAL_ART = 'digital-art';
7
- export const IMAGE_STYLE_COMICBOOK = 'comicbook';
8
- export const IMAGE_STYLE_FANTASY_ART = 'fantasy-art';
9
- export const IMAGE_STYLE_ANALOG_FILM = 'analog-film';
10
- export const IMAGE_STYLE_NEONPUNK = 'neonpunk';
11
- export const IMAGE_STYLE_ISOMETRIC = 'isometric';
12
- export const IMAGE_STYLE_LOWPOLY = 'lowpoly';
13
- export const IMAGE_STYLE_ORIGAMI = 'origami';
14
- export const IMAGE_STYLE_LINE_ART = 'line-art';
15
- export const IMAGE_STYLE_CRAFT_CLAY = 'craft-clay';
16
- export const IMAGE_STYLE_CINEMATIC = 'cinematic';
17
- export const IMAGE_STYLE_3D_MODEL = '3d-model';
18
- export const IMAGE_STYLE_PIXEL_ART = 'pixel-art';
19
- export const IMAGE_STYLE_TEXTURE = 'texture';
20
- export const IMAGE_STYLE_MONTY_PYTHON = 'monty-python';
21
- export const IMAGE_STYLE_LABELS = {
22
- [IMAGE_STYLE_ENHANCE]: __('Enhance', 'jetpack-ai-client'),
23
- [IMAGE_STYLE_ANIME]: __('Anime', 'jetpack-ai-client'),
24
- [IMAGE_STYLE_PHOTOGRAPHIC]: __('Photographic', 'jetpack-ai-client'),
25
- [IMAGE_STYLE_DIGITAL_ART]: __('Digital Art', 'jetpack-ai-client'),
26
- [IMAGE_STYLE_COMICBOOK]: __('Comicbook', 'jetpack-ai-client'),
27
- [IMAGE_STYLE_FANTASY_ART]: __('Fantasy Art', 'jetpack-ai-client'),
28
- [IMAGE_STYLE_ANALOG_FILM]: __('Analog Film', 'jetpack-ai-client'),
29
- [IMAGE_STYLE_NEONPUNK]: __('Neon Punk', 'jetpack-ai-client'),
30
- [IMAGE_STYLE_ISOMETRIC]: __('Isometric', 'jetpack-ai-client'),
31
- [IMAGE_STYLE_LOWPOLY]: __('Low Poly', 'jetpack-ai-client'),
32
- [IMAGE_STYLE_ORIGAMI]: __('Origami', 'jetpack-ai-client'),
33
- [IMAGE_STYLE_LINE_ART]: __('Line Art', 'jetpack-ai-client'),
34
- [IMAGE_STYLE_CRAFT_CLAY]: __('Craft Clay', 'jetpack-ai-client'),
35
- [IMAGE_STYLE_CINEMATIC]: __('Cinematic', 'jetpack-ai-client'),
36
- [IMAGE_STYLE_3D_MODEL]: __('3D Model', 'jetpack-ai-client'),
37
- [IMAGE_STYLE_PIXEL_ART]: __('Pixel Art', 'jetpack-ai-client'),
38
- [IMAGE_STYLE_TEXTURE]: __('Texture', 'jetpack-ai-client'),
39
- [IMAGE_STYLE_MONTY_PYTHON]: __('Monty Python', 'jetpack-ai-client'),
40
- };
@@ -1,7 +0,0 @@
1
- import './prompt.scss';
2
- type PromptProps = {
3
- initialPrompt?: string;
4
- showStyleSelector?: boolean;
5
- };
6
- export declare const Prompt: ({ initialPrompt, showStyleSelector }: PromptProps) => import("react/jsx-runtime").JSX.Element;
7
- 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