@automattic/jetpack-ai-client 0.25.2 โ†’ 0.25.4

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 (41) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/build/ai-client/src/components/ai-control/block-ai-control.d.ts +2 -1
  3. package/build/ai-client/src/components/ai-control/block-ai-control.js +10 -2
  4. package/build/ai-client/src/components/ai-control/extension-ai-control.d.ts +3 -1
  5. package/build/ai-client/src/components/ai-control/extension-ai-control.js +9 -3
  6. package/build/ai-client/src/components/ai-feedback/index.d.ts +27 -0
  7. package/build/ai-client/src/components/ai-feedback/index.js +71 -0
  8. package/build/ai-client/src/components/index.d.ts +1 -0
  9. package/build/ai-client/src/components/index.js +1 -0
  10. package/build/ai-client/src/components/message/index.d.ts +15 -4
  11. package/build/ai-client/src/components/message/index.js +22 -5
  12. package/build/ai-client/src/constants.d.ts +106 -0
  13. package/build/ai-client/src/constants.js +113 -0
  14. package/build/ai-client/src/index.d.ts +1 -0
  15. package/build/ai-client/src/index.js +4 -0
  16. package/build/ai-client/src/libs/index.d.ts +1 -0
  17. package/build/ai-client/src/libs/index.js +1 -0
  18. package/build/ai-client/src/libs/map-action-to-human-text.d.ts +13 -0
  19. package/build/ai-client/src/libs/map-action-to-human-text.js +40 -0
  20. package/build/ai-client/src/logo-generator/components/logo-presenter.js +25 -1
  21. package/build/ai-client/src/logo-generator/hooks/use-logo-generator.js +3 -0
  22. package/build/ai-client/src/logo-generator/lib/logo-storage.d.ts +9 -8
  23. package/build/ai-client/src/logo-generator/lib/logo-storage.js +12 -8
  24. package/build/ai-client/src/logo-generator/store/types.d.ts +2 -0
  25. package/build/ai-client/src/logo-generator/types.d.ts +1 -0
  26. package/package.json +2 -1
  27. package/src/components/ai-control/block-ai-control.tsx +15 -1
  28. package/src/components/ai-control/extension-ai-control.tsx +18 -2
  29. package/src/components/ai-feedback/index.tsx +135 -0
  30. package/src/components/ai-feedback/style.scss +16 -0
  31. package/src/components/index.ts +1 -0
  32. package/src/components/message/index.tsx +45 -12
  33. package/src/constants.ts +116 -0
  34. package/src/index.ts +5 -0
  35. package/src/libs/index.ts +2 -0
  36. package/src/libs/map-action-to-human-text.ts +77 -0
  37. package/src/logo-generator/components/logo-presenter.tsx +41 -0
  38. package/src/logo-generator/hooks/use-logo-generator.ts +4 -0
  39. package/src/logo-generator/lib/logo-storage.ts +18 -8
  40. package/src/logo-generator/store/types.ts +2 -0
  41. package/src/logo-generator/types.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@ 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.25.4] - 2024-12-30
9
+ ### Added
10
+ - AI Client: Add thumbs feedback on AI Assistant. [#40728]
11
+
12
+ ### Changed
13
+ - AI Client: Move prompt types and update thumbs feedback event. [#40746]
14
+
15
+ ## [0.25.3] - 2024-12-23
16
+ ### Added
17
+ - Jetpack AI: Add thumbs up/down component to AI logo generator. [#40610]
18
+
8
19
  ## [0.25.2] - 2024-12-16
9
20
  ### Changed
10
21
  - Updated package dependencies. [#40564]
@@ -483,6 +494,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
483
494
  - AI Client: stop using smart document visibility handling on the fetchEventSource library, so it does not restart the completion when changing tabs. [#32004]
484
495
  - Updated package dependencies. [#31468] [#31659] [#31785]
485
496
 
497
+ [0.25.4]: https://github.com/Automattic/jetpack-ai-client/compare/v0.25.3...v0.25.4
498
+ [0.25.3]: https://github.com/Automattic/jetpack-ai-client/compare/v0.25.2...v0.25.3
486
499
  [0.25.2]: https://github.com/Automattic/jetpack-ai-client/compare/v0.25.1...v0.25.2
487
500
  [0.25.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.25.0...v0.25.1
488
501
  [0.25.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.24.3...v0.25.0
@@ -24,6 +24,7 @@ type BlockAIControlProps = {
24
24
  showRemove?: boolean;
25
25
  banner?: ReactElement;
26
26
  error?: ReactElement;
27
+ lastAction?: string;
27
28
  };
28
29
  /**
29
30
  * BlockAIControl component. Used by the AI Assistant block, adding logic and components to the base AIControl component.
@@ -32,6 +33,6 @@ type BlockAIControlProps = {
32
33
  * @param {React.MutableRefObject} ref - Ref to the component
33
34
  * @return {ReactElement} Rendered component
34
35
  */
35
- export declare function BlockAIControl({ disabled, value, placeholder, showAccept, acceptLabel, showButtonLabels, isTransparent, state, showGuideLine, customFooter, onChange, onSend, onStop, onAccept, onDiscard, showRemove, banner, error, }: BlockAIControlProps, ref: React.MutableRefObject<HTMLInputElement>): ReactElement;
36
+ export declare function BlockAIControl({ disabled, value, placeholder, showAccept, acceptLabel, showButtonLabels, isTransparent, state, showGuideLine, customFooter, onChange, onSend, onStop, onAccept, onDiscard, showRemove, banner, error, lastAction, }: BlockAIControlProps, ref: React.MutableRefObject<HTMLInputElement>): ReactElement;
36
37
  declare const _default: React.ForwardRefExoticComponent<BlockAIControlProps & React.RefAttributes<HTMLInputElement>>;
37
38
  export default _default;
@@ -23,7 +23,7 @@ const debug = debugFactory('jetpack-ai-client:block-ai-control');
23
23
  * @param {React.MutableRefObject} ref - Ref to the component
24
24
  * @return {ReactElement} Rendered component
25
25
  */
26
- export function BlockAIControl({ disabled = false, value = '', placeholder = '', showAccept = false, acceptLabel = __('Accept', 'jetpack-ai-client'), showButtonLabels = true, isTransparent = false, state = 'init', showGuideLine = false, customFooter = null, onChange, onSend, onStop, onAccept, onDiscard, showRemove = false, banner = null, error = null, }, ref) {
26
+ export function BlockAIControl({ disabled = false, value = '', placeholder = '', showAccept = false, acceptLabel = __('Accept', 'jetpack-ai-client'), showButtonLabels = true, isTransparent = false, state = 'init', showGuideLine = false, customFooter = null, onChange, onSend, onStop, onAccept, onDiscard, showRemove = false, banner = null, error = null, lastAction, }, ref) {
27
27
  const loading = state === 'requesting' || state === 'suggesting';
28
28
  const [editRequest, setEditRequest] = useState(false);
29
29
  const [lastValue, setLastValue] = useState(value || null);
@@ -76,7 +76,15 @@ export function BlockAIControl({ disabled = false, value = '', placeholder = '',
76
76
  target: promptUserInputRef,
77
77
  });
78
78
  const actions = (_jsxs(_Fragment, { children: [(!showAccept || editRequest) && (_jsx("div", { className: "jetpack-components-ai-control__controls-prompt_button_wrapper", children: !loading ? (_jsxs(_Fragment, { children: [editRequest && (_jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: cancelEdit, variant: "secondary", label: __('Cancel', 'jetpack-ai-client'), children: showButtonLabels ? (__('Cancel', 'jetpack-ai-client')) : (_jsx(Icon, { icon: closeSmall })) })), showRemove && !editRequest && !value?.length && onDiscard && (_jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: discardHandler, variant: "secondary", label: __('Cancel', 'jetpack-ai-client'), children: showButtonLabels ? (__('Cancel', 'jetpack-ai-client')) : (_jsx(Icon, { icon: closeSmall })) })), value?.length > 0 && (_jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: sendHandler, variant: "primary", disabled: !value?.length || disabled, label: __('Send request', 'jetpack-ai-client'), children: showButtonLabels ? (__('Generate', 'jetpack-ai-client')) : (_jsx(Icon, { icon: arrowUp })) }))] })) : (_jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: onStop, variant: "secondary", label: __('Stop request', 'jetpack-ai-client'), children: showButtonLabels ? (__('Stop', 'jetpack-ai-client')) : (_jsx(Icon, { icon: closeSmall })) })) })), showAccept && !editRequest && (_jsxs("div", { className: "jetpack-components-ai-control__controls-prompt_button_wrapper", children: [(value?.length > 0 || lastValue === null) && (_jsxs(ButtonGroup, { children: [_jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", label: __('Discard', 'jetpack-ai-client'), onClick: discardHandler, tooltipPosition: "top", children: _jsx(Icon, { icon: trash }) }), _jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", label: __('Regenerate', 'jetpack-ai-client'), onClick: () => onSend?.(value), tooltipPosition: "top", disabled: !value?.length || value === null || disabled, children: _jsx(Icon, { icon: regenerate }) })] })), _jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: onAccept, variant: "primary", label: acceptLabel, children: showButtonLabels ? acceptLabel : _jsx(Icon, { icon: check }) })] }))] }));
79
- const message = showGuideLine && !loading && !editRequest && (customFooter || _jsx(GuidelineMessage, {}));
79
+ const message = showGuideLine &&
80
+ !loading &&
81
+ !editRequest &&
82
+ (customFooter || (_jsx(GuidelineMessage, { aiFeedbackThumbsOptions: {
83
+ showAIFeedbackThumbs: true,
84
+ ratedItem: 'ai-assistant',
85
+ prompt: lastAction,
86
+ block: 'ai-assistant',
87
+ } })));
80
88
  return (_jsx(AIControl, { disabled: disabled || loading, value: value, placeholder: placeholder, isTransparent: isTransparent, state: state, onChange: changeHandler, banner: banner, error: error, actions: actions, message: message, promptUserInputRef: promptUserInputRef }));
81
89
  }
82
90
  export default forwardRef(BlockAIControl);
@@ -27,6 +27,8 @@ type ExtensionAIControlProps = {
27
27
  onUndo?: () => void;
28
28
  onUpgrade?: (event: MouseEvent<HTMLButtonElement>) => void;
29
29
  onTryAgain?: () => void;
30
+ lastAction?: string;
31
+ blockType: string;
30
32
  };
31
33
  /**
32
34
  * ExtensionAIControl component. Used by the AI Assistant inline extensions, adding logic and components to the base AIControl component.
@@ -35,6 +37,6 @@ type ExtensionAIControlProps = {
35
37
  * @param {React.MutableRefObject} ref - Ref to the component
36
38
  * @return {ReactElement} Rendered component
37
39
  */
38
- export declare function ExtensionAIControl({ className, disabled, value, placeholder, showButtonLabels, isTransparent, state, showGuideLine, error, requestsRemaining, showUpgradeMessage, showFairUsageMessage, upgradeUrl, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, onTryAgain, }: ExtensionAIControlProps, ref: React.MutableRefObject<HTMLInputElement>): ReactElement;
40
+ export declare function ExtensionAIControl({ className, disabled, value, placeholder, showButtonLabels, isTransparent, state, showGuideLine, error, requestsRemaining, showUpgradeMessage, showFairUsageMessage, upgradeUrl, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, onTryAgain, lastAction, blockType, }: ExtensionAIControlProps, ref: React.MutableRefObject<HTMLInputElement>): ReactElement;
39
41
  declare const _default: React.ForwardRefExoticComponent<ExtensionAIControlProps & React.RefAttributes<HTMLInputElement>>;
40
42
  export default _default;
@@ -21,11 +21,12 @@ import './style.scss';
21
21
  * @param {React.MutableRefObject} ref - Ref to the component
22
22
  * @return {ReactElement} Rendered component
23
23
  */
24
- export function ExtensionAIControl({ className, disabled = false, value = '', placeholder = '', showButtonLabels = true, isTransparent = false, state = 'init', showGuideLine = false, error, requestsRemaining, showUpgradeMessage = false, showFairUsageMessage = false, upgradeUrl, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, onTryAgain, }, ref) {
24
+ export function ExtensionAIControl({ className, disabled = false, value = '', placeholder = '', showButtonLabels = true, isTransparent = false, state = 'init', showGuideLine = false, error, requestsRemaining, showUpgradeMessage = false, showFairUsageMessage = false, upgradeUrl, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, onTryAgain, lastAction, blockType, }, ref) {
25
25
  const loading = state === 'requesting' || state === 'suggesting';
26
26
  const [editRequest, setEditRequest] = useState(false);
27
27
  const [lastValue, setLastValue] = useState(value || null);
28
28
  const promptUserInputRef = useRef(null);
29
+ const isDone = value?.length <= 0 && state === 'done';
29
30
  // Pass the ref to forwardRef.
30
31
  useImperativeHandle(ref, () => promptUserInputRef.current);
31
32
  useEffect(() => {
@@ -73,7 +74,7 @@ export function ExtensionAIControl({ className, disabled = false, value = '', pl
73
74
  }, {
74
75
  target: promptUserInputRef,
75
76
  });
76
- const actions = (_jsx(_Fragment, { children: loading ? (_jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: stopHandler, variant: "secondary", label: __('Stop request', 'jetpack-ai-client'), children: showButtonLabels ? __('Stop', 'jetpack-ai-client') : _jsx(Icon, { icon: closeSmall }) })) : (_jsxs(_Fragment, { children: [value?.length > 0 && (_jsx("div", { className: "jetpack-components-ai-control__controls-prompt_button_wrapper", children: _jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: sendHandler, variant: "primary", disabled: !value?.length || disabled, label: __('Send request', 'jetpack-ai-client'), children: showButtonLabels ? (__('Generate', 'jetpack-ai-client')) : (_jsx(Icon, { icon: arrowUp })) }) })), value?.length <= 0 && state === 'done' && (_jsx("div", { className: "jetpack-components-ai-control__controls-prompt_button_wrapper", children: _jsxs(ButtonGroup, { children: [_jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", label: __('Undo', 'jetpack-ai-client'), onClick: undoHandler, tooltipPosition: "top", children: _jsx(Icon, { icon: undo }) }), _jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", label: __('Close', 'jetpack-ai-client'), onClick: closeHandler, variant: "tertiary", children: __('Close', 'jetpack-ai-client') })] }) }))] })) }));
77
+ const actions = (_jsx(_Fragment, { children: loading ? (_jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: stopHandler, variant: "secondary", label: __('Stop request', 'jetpack-ai-client'), children: showButtonLabels ? __('Stop', 'jetpack-ai-client') : _jsx(Icon, { icon: closeSmall }) })) : (_jsxs(_Fragment, { children: [value?.length > 0 && (_jsx("div", { className: "jetpack-components-ai-control__controls-prompt_button_wrapper", children: _jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: sendHandler, variant: "primary", disabled: !value?.length || disabled, label: __('Send request', 'jetpack-ai-client'), children: showButtonLabels ? (__('Generate', 'jetpack-ai-client')) : (_jsx(Icon, { icon: arrowUp })) }) })), isDone && (_jsx("div", { className: "jetpack-components-ai-control__controls-prompt_button_wrapper", children: _jsxs(ButtonGroup, { children: [_jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", label: __('Undo', 'jetpack-ai-client'), onClick: undoHandler, tooltipPosition: "top", children: _jsx(Icon, { icon: undo }) }), _jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", label: __('Close', 'jetpack-ai-client'), onClick: closeHandler, variant: "tertiary", children: __('Close', 'jetpack-ai-client') })] }) }))] })) }));
77
78
  let message = null;
78
79
  if (error?.message) {
79
80
  message = (_jsx(ErrorMessage, { error: error.message, code: error.code, onTryAgainClick: tryAgainHandler, onUpgradeClick: upgradeHandler, upgradeUrl: upgradeUrl }));
@@ -85,7 +86,12 @@ export function ExtensionAIControl({ className, disabled = false, value = '', pl
85
86
  message = (_jsx(UpgradeMessage, { requestsRemaining: requestsRemaining, onUpgradeClick: upgradeHandler, upgradeUrl: upgradeUrl }));
86
87
  }
87
88
  else if (showGuideLine) {
88
- message = _jsx(GuidelineMessage, {});
89
+ message = isDone ? (_jsx(GuidelineMessage, { aiFeedbackThumbsOptions: {
90
+ showAIFeedbackThumbs: true,
91
+ ratedItem: 'ai-assistant',
92
+ prompt: lastAction,
93
+ block: blockType,
94
+ } })) : (_jsx(GuidelineMessage, {}));
89
95
  }
90
96
  return (_jsx(AIControl, { className: className, disabled: disabled || loading, value: value, placeholder: placeholder, isTransparent: isTransparent, state: state, onChange: changeHandler, actions: actions, message: message, promptUserInputRef: promptUserInputRef, wrapperRef: wrapperRef }));
91
97
  }
@@ -0,0 +1,27 @@
1
+ import './style.scss';
2
+ /**
3
+ * Types
4
+ */
5
+ import type React from 'react';
6
+ type AiFeedbackThumbsProps = {
7
+ disabled?: boolean;
8
+ iconSize?: number;
9
+ ratedItem?: string;
10
+ feature?: string;
11
+ savedRatings?: Record<string, string>;
12
+ options?: {
13
+ mediaLibraryId?: number;
14
+ prompt?: string;
15
+ revisedPrompt?: string;
16
+ block?: string | null;
17
+ };
18
+ onRate?: (rating: string) => void;
19
+ };
20
+ /**
21
+ * AiFeedbackThumbs component.
22
+ *
23
+ * @param {AiFeedbackThumbsProps} props - component props.
24
+ * @return {React.ReactElement} - rendered component.
25
+ */
26
+ export default function AiFeedbackThumbs({ disabled, iconSize, ratedItem, feature, savedRatings, options, onRate, }: AiFeedbackThumbsProps): React.ReactElement;
27
+ export {};
@@ -0,0 +1,71 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * External dependencies
4
+ */
5
+ import { useAnalytics, getJetpackExtensionAvailability, } from '@automattic/jetpack-shared-extension-utils';
6
+ import { Button, Tooltip } from '@wordpress/components';
7
+ import { useEffect, useState } from '@wordpress/element';
8
+ import { __ } from '@wordpress/i18n';
9
+ import { thumbsUp, thumbsDown } from '@wordpress/icons';
10
+ import clsx from 'clsx';
11
+ /*
12
+ * Internal dependencies
13
+ */
14
+ import './style.scss';
15
+ /**
16
+ * Get the availability of a feature.
17
+ *
18
+ * @param {string} feature - The feature to check availability for.
19
+ * @return {boolean} - Whether the feature is available.
20
+ */
21
+ function getFeatureAvailability(feature) {
22
+ return getJetpackExtensionAvailability(feature).available === true;
23
+ }
24
+ /**
25
+ * AiFeedbackThumbs component.
26
+ *
27
+ * @param {AiFeedbackThumbsProps} props - component props.
28
+ * @return {React.ReactElement} - rendered component.
29
+ */
30
+ export default function AiFeedbackThumbs({ disabled = false, iconSize = 24, ratedItem = '', feature = '', savedRatings = {}, options = {}, onRate, }) {
31
+ if (!getFeatureAvailability('ai-response-feedback')) {
32
+ return null;
33
+ }
34
+ const [itemsRated, setItemsRated] = useState({});
35
+ const { tracks } = useAnalytics();
36
+ useEffect(() => {
37
+ const newItemsRated = { ...savedRatings, ...itemsRated };
38
+ if (JSON.stringify(newItemsRated) !== JSON.stringify(itemsRated)) {
39
+ setItemsRated(newItemsRated);
40
+ }
41
+ }, [savedRatings]);
42
+ const checkThumb = (thumbValue) => {
43
+ if (!itemsRated[ratedItem]) {
44
+ return false;
45
+ }
46
+ return itemsRated[ratedItem] === thumbValue;
47
+ };
48
+ const rateAI = (isThumbsUp) => {
49
+ const aiRating = isThumbsUp ? 'thumbs-up' : 'thumbs-down';
50
+ if (!checkThumb(aiRating)) {
51
+ setItemsRated({
52
+ ...itemsRated,
53
+ [ratedItem]: aiRating,
54
+ });
55
+ onRate?.(aiRating);
56
+ tracks.recordEvent('jetpack_ai_feedback', {
57
+ type: feature,
58
+ rating: aiRating,
59
+ mediaLibraryId: options.mediaLibraryId || null,
60
+ prompt: options.prompt || null,
61
+ revisedPrompt: options.revisedPrompt || null,
62
+ block: options.block || null,
63
+ });
64
+ }
65
+ };
66
+ return (_jsxs("div", { className: "ai-assistant-feedback__selection", children: [_jsx(Tooltip, { text: __('I like this', 'jetpack-ai-client'), children: _jsx(Button, { disabled: disabled, icon: thumbsUp, onClick: () => rateAI(true), iconSize: iconSize, showTooltip: false, className: clsx({
67
+ 'ai-assistant-feedback__thumb-selected': checkThumb('thumbs-up'),
68
+ }) }) }), _jsx(Tooltip, { text: __("I don't find this useful", 'jetpack-ai-client'), children: _jsx(Button, { disabled: disabled, icon: thumbsDown, onClick: () => rateAI(false), iconSize: iconSize, showTooltip: false, className: clsx({
69
+ 'ai-assistant-feedback__thumb-selected': checkThumb('thumbs-down'),
70
+ }) }) })] }));
71
+ }
@@ -1,4 +1,5 @@
1
1
  export { AIControl, BlockAIControl, ExtensionAIControl } from './ai-control/index.js';
2
+ export { default as AiFeedbackThumbs } from './ai-feedback/index.js';
2
3
  export { default as AiStatusIndicator } from './ai-status-indicator/index.js';
3
4
  export { default as AudioDurationDisplay } from './audio-duration-display/index.js';
4
5
  export { default as AiModalFooter } from './ai-modal-footer/index.js';
@@ -1,4 +1,5 @@
1
1
  export { AIControl, BlockAIControl, ExtensionAIControl } from './ai-control/index.js';
2
+ export { default as AiFeedbackThumbs } from './ai-feedback/index.js';
2
3
  export { default as AiStatusIndicator } from './ai-status-indicator/index.js';
3
4
  export { default as AudioDurationDisplay } from './audio-duration-display/index.js';
4
5
  export { default as AiModalFooter } from './ai-modal-footer/index.js';
@@ -12,13 +12,22 @@ export declare const MESSAGE_SEVERITY_ERROR = "error";
12
12
  export declare const MESSAGE_SEVERITY_SUCCESS = "success";
13
13
  export declare const MESSAGE_SEVERITY_INFO = "info";
14
14
  export type MessageSeverityProp = typeof MESSAGE_SEVERITY_WARNING | typeof MESSAGE_SEVERITY_ERROR | typeof MESSAGE_SEVERITY_SUCCESS | typeof MESSAGE_SEVERITY_INFO | null;
15
+ type AiFeedbackThumbsOptions = {
16
+ showAIFeedbackThumbs?: boolean;
17
+ ratedItem?: string;
18
+ prompt?: string;
19
+ block?: string | null;
20
+ onRate?: (rating: string) => void;
21
+ };
15
22
  export type MessageProps = {
16
23
  icon?: React.ReactNode;
17
24
  severity?: MessageSeverityProp;
18
- showSidebarIcon?: boolean;
19
- onSidebarIconClick?: () => void;
25
+ aiFeedbackThumbsOptions?: AiFeedbackThumbsOptions;
20
26
  children: React.ReactNode;
21
27
  };
28
+ export type GuidelineMessageProps = {
29
+ aiFeedbackThumbsOptions?: AiFeedbackThumbsOptions;
30
+ };
22
31
  export type OnUpgradeClick = (event?: React.MouseEvent<HTMLButtonElement>) => void;
23
32
  export type UpgradeMessageProps = {
24
33
  requestsRemaining: number;
@@ -39,13 +48,14 @@ export type ErrorMessageProps = {
39
48
  * @param {MessageProps} props - Component props.
40
49
  * @return {React.ReactElement} Banner component.
41
50
  */
42
- export default function Message({ severity, icon, showSidebarIcon, onSidebarIconClick, children, }: MessageProps): React.ReactElement;
51
+ export default function Message({ severity, icon, aiFeedbackThumbsOptions, children, }: MessageProps): React.ReactElement;
43
52
  /**
44
53
  * React component to render a guideline message.
45
54
  *
55
+ * @param {GuidelineMessageProps} props - Component props.
46
56
  * @return {React.ReactElement} - Message component.
47
57
  */
48
- export declare function GuidelineMessage(): React.ReactElement;
58
+ export declare function GuidelineMessage({ aiFeedbackThumbsOptions, }: GuidelineMessageProps): React.ReactElement;
49
59
  /**
50
60
  * React component to render a fair usage limit message.
51
61
  *
@@ -66,3 +76,4 @@ export declare function UpgradeMessage({ requestsRemaining, severity, onUpgradeC
66
76
  * @return {React.ReactElement} - Message component.
67
77
  */
68
78
  export declare function ErrorMessage({ error, code, onTryAgainClick, onUpgradeClick, upgradeUrl, }: ErrorMessageProps): React.ReactElement;
79
+ export {};
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  import { ExternalLink, Button } from '@wordpress/components';
6
6
  import { createInterpolateElement } from '@wordpress/element';
7
7
  import { __, sprintf } from '@wordpress/i18n';
8
- import { Icon, check, arrowRight } from '@wordpress/icons';
8
+ import { Icon, check } from '@wordpress/icons';
9
9
  import clsx from 'clsx';
10
10
  /**
11
11
  * Internal dependencies
@@ -13,6 +13,7 @@ import clsx from 'clsx';
13
13
  import './style.scss';
14
14
  import errorExclamation from '../../icons/error-exclamation.js';
15
15
  import { ERROR_QUOTA_EXCEEDED } from '../../types.js';
16
+ import AiFeedbackThumbs from '../ai-feedback/index.js';
16
17
  export const MESSAGE_SEVERITY_WARNING = 'warning';
17
18
  export const MESSAGE_SEVERITY_ERROR = 'error';
18
19
  export const MESSAGE_SEVERITY_SUCCESS = 'success';
@@ -29,8 +30,17 @@ const messageIconsMap = {
29
30
  * @param {MessageProps} props - Component props.
30
31
  * @return {React.ReactElement} Banner component.
31
32
  */
32
- export default function Message({ severity = MESSAGE_SEVERITY_INFO, icon = null, showSidebarIcon = false, onSidebarIconClick = () => { }, children, }) {
33
- return (_jsxs("div", { className: clsx('jetpack-ai-assistant__message', `jetpack-ai-assistant__message-severity-${severity}`), children: [(messageIconsMap[severity] || icon) && (_jsx(Icon, { icon: messageIconsMap[severity] || icon })), _jsx("div", { className: "jetpack-ai-assistant__message-content", children: children }), showSidebarIcon && (_jsx(Button, { className: "jetpack-ai-assistant__message-sidebar", onClick: onSidebarIconClick, children: _jsx(Icon, { size: 20, icon: arrowRight }) }))] }));
33
+ export default function Message({ severity = MESSAGE_SEVERITY_INFO, icon = null, aiFeedbackThumbsOptions = {
34
+ showAIFeedbackThumbs: false,
35
+ ratedItem: '',
36
+ prompt: '',
37
+ block: null,
38
+ onRate: () => { },
39
+ }, children, }) {
40
+ return (_jsxs("div", { className: clsx('jetpack-ai-assistant__message', `jetpack-ai-assistant__message-severity-${severity}`), children: [(messageIconsMap[severity] || icon) && (_jsx(Icon, { icon: messageIconsMap[severity] || icon })), _jsx("div", { className: "jetpack-ai-assistant__message-content", children: children }), aiFeedbackThumbsOptions.showAIFeedbackThumbs && aiFeedbackThumbsOptions.prompt && (_jsx(AiFeedbackThumbs, { disabled: false, ratedItem: aiFeedbackThumbsOptions.ratedItem, feature: "ai-assistant", options: {
41
+ prompt: aiFeedbackThumbsOptions.prompt,
42
+ block: aiFeedbackThumbsOptions.block,
43
+ }, onRate: aiFeedbackThumbsOptions.onRate }))] }));
34
44
  }
35
45
  /**
36
46
  * React component to render a learn more link.
@@ -43,10 +53,17 @@ function LearnMoreLink() {
43
53
  /**
44
54
  * React component to render a guideline message.
45
55
  *
56
+ * @param {GuidelineMessageProps} props - Component props.
46
57
  * @return {React.ReactElement} - Message component.
47
58
  */
48
- export function GuidelineMessage() {
49
- return (_jsxs(Message, { children: [_jsx("span", { children: __('AI-generated content could be inaccurate or biased.', 'jetpack-ai-client') }), _jsx(LearnMoreLink, {})] }));
59
+ export function GuidelineMessage({ aiFeedbackThumbsOptions = {
60
+ showAIFeedbackThumbs: false,
61
+ ratedItem: '',
62
+ prompt: '',
63
+ block: null,
64
+ onRate: () => { },
65
+ }, }) {
66
+ return (_jsxs(Message, { aiFeedbackThumbsOptions: aiFeedbackThumbsOptions, children: [_jsx("span", { children: __('AI-generated content could be inaccurate or biased.', 'jetpack-ai-client') }), _jsx(LearnMoreLink, {})] }));
50
67
  }
51
68
  /**
52
69
  * React component to render a fair usage limit message.
@@ -0,0 +1,106 @@
1
+ export declare const LANGUAGE_MAP: {
2
+ en: {
3
+ label: string;
4
+ };
5
+ es: {
6
+ label: string;
7
+ };
8
+ fr: {
9
+ label: string;
10
+ };
11
+ de: {
12
+ label: string;
13
+ };
14
+ it: {
15
+ label: string;
16
+ };
17
+ pt: {
18
+ label: string;
19
+ };
20
+ ru: {
21
+ label: string;
22
+ };
23
+ zh: {
24
+ label: string;
25
+ };
26
+ ja: {
27
+ label: string;
28
+ };
29
+ ar: {
30
+ label: string;
31
+ };
32
+ hi: {
33
+ label: string;
34
+ };
35
+ ko: {
36
+ label: string;
37
+ };
38
+ };
39
+ export declare const PROMPT_TONES_MAP: {
40
+ formal: {
41
+ label: string;
42
+ emoji: string;
43
+ };
44
+ informal: {
45
+ label: string;
46
+ emoji: string;
47
+ };
48
+ optimistic: {
49
+ label: string;
50
+ emoji: string;
51
+ };
52
+ humorous: {
53
+ label: string;
54
+ emoji: string;
55
+ };
56
+ serious: {
57
+ label: string;
58
+ emoji: string;
59
+ };
60
+ skeptical: {
61
+ label: string;
62
+ emoji: string;
63
+ };
64
+ empathetic: {
65
+ label: string;
66
+ emoji: string;
67
+ };
68
+ confident: {
69
+ label: string;
70
+ emoji: string;
71
+ };
72
+ passionate: {
73
+ label: string;
74
+ emoji: string;
75
+ };
76
+ provocative: {
77
+ label: string;
78
+ emoji: string;
79
+ };
80
+ };
81
+ export declare const PROMPT_TYPE_SUMMARY_BY_TITLE: "titleSummary";
82
+ export declare const PROMPT_TYPE_CONTINUE: "continue";
83
+ export declare const PROMPT_TYPE_SIMPLIFY: "simplify";
84
+ export declare const PROMPT_TYPE_CORRECT_SPELLING: "correctSpelling";
85
+ export declare const PROMPT_TYPE_GENERATE_TITLE: "generateTitle";
86
+ export declare const PROMPT_TYPE_MAKE_LONGER: "makeLonger";
87
+ export declare const PROMPT_TYPE_MAKE_SHORTER: "makeShorter";
88
+ export declare const PROMPT_TYPE_CHANGE_TONE: "changeTone";
89
+ export declare const PROMPT_TYPE_SUMMARIZE: "summarize";
90
+ export declare const PROMPT_TYPE_CHANGE_LANGUAGE: "changeLanguage";
91
+ export declare const PROMPT_TYPE_USER_PROMPT: "userPrompt";
92
+ export declare const PROMPT_TYPE_JETPACK_FORM_CUSTOM_PROMPT: "jetpackFormCustomPrompt";
93
+ export declare const PROMPT_TYPE_TRANSFORM_LIST_TO_TABLE: "transformListToTable";
94
+ export declare const PROMPT_TYPE_WRITE_POST_FROM_LIST: "writePostFromList";
95
+ export declare const TRANSLATE_LABEL: string;
96
+ export declare const TONE_LABEL: string;
97
+ export declare const CORRECT_SPELLING_LABEL: string;
98
+ export declare const SIMPLIFY_LABEL: string;
99
+ export declare const SUMMARIZE_LABEL: string;
100
+ export declare const MAKE_SHORTER_LABEL: string;
101
+ export declare const MAKE_LONGER_LABEL: string;
102
+ export declare const TURN_LIST_INTO_TABLE_LABEL: string;
103
+ export declare const WRITE_POST_FROM_LIST_LABEL: string;
104
+ export declare const GENERATE_TITLE_LABEL: string;
105
+ export declare const SUMMARY_BASED_ON_TITLE_LABEL: string;
106
+ export declare const CONTINUE_LABEL: string;
@@ -0,0 +1,113 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ // Mappings
6
+ export const LANGUAGE_MAP = {
7
+ en: {
8
+ label: __('English', 'jetpack-ai-client'),
9
+ },
10
+ es: {
11
+ label: __('Spanish', 'jetpack-ai-client'),
12
+ },
13
+ fr: {
14
+ label: __('French', 'jetpack-ai-client'),
15
+ },
16
+ de: {
17
+ label: __('German', 'jetpack-ai-client'),
18
+ },
19
+ it: {
20
+ label: __('Italian', 'jetpack-ai-client'),
21
+ },
22
+ pt: {
23
+ label: __('Portuguese', 'jetpack-ai-client'),
24
+ },
25
+ ru: {
26
+ label: __('Russian', 'jetpack-ai-client'),
27
+ },
28
+ zh: {
29
+ label: __('Chinese', 'jetpack-ai-client'),
30
+ },
31
+ ja: {
32
+ label: __('Japanese', 'jetpack-ai-client'),
33
+ },
34
+ ar: {
35
+ label: __('Arabic', 'jetpack-ai-client'),
36
+ },
37
+ hi: {
38
+ label: __('Hindi', 'jetpack-ai-client'),
39
+ },
40
+ ko: {
41
+ label: __('Korean', 'jetpack-ai-client'),
42
+ },
43
+ };
44
+ export const PROMPT_TONES_MAP = {
45
+ formal: {
46
+ label: __('Formal', 'jetpack-ai-client'),
47
+ emoji: '๐ŸŽฉ',
48
+ },
49
+ informal: {
50
+ label: __('Informal', 'jetpack-ai-client'),
51
+ emoji: '๐Ÿ˜Š',
52
+ },
53
+ optimistic: {
54
+ label: __('Optimistic', 'jetpack-ai-client'),
55
+ emoji: '๐Ÿ˜ƒ',
56
+ },
57
+ humorous: {
58
+ label: __('Humorous', 'jetpack-ai-client'),
59
+ emoji: '๐Ÿ˜‚',
60
+ },
61
+ serious: {
62
+ label: __('Serious', 'jetpack-ai-client'),
63
+ emoji: '๐Ÿ˜',
64
+ },
65
+ skeptical: {
66
+ label: __('Skeptical', 'jetpack-ai-client'),
67
+ emoji: '๐Ÿคจ',
68
+ },
69
+ empathetic: {
70
+ label: __('Empathetic', 'jetpack-ai-client'),
71
+ emoji: '๐Ÿ’—',
72
+ },
73
+ confident: {
74
+ label: __('Confident', 'jetpack-ai-client'),
75
+ emoji: '๐Ÿ˜Ž',
76
+ },
77
+ passionate: {
78
+ label: __('Passionate', 'jetpack-ai-client'),
79
+ emoji: 'โค๏ธ',
80
+ },
81
+ provocative: {
82
+ label: __('Provocative', 'jetpack-ai-client'),
83
+ emoji: '๐Ÿ”ฅ',
84
+ },
85
+ };
86
+ // Prompt types
87
+ export const PROMPT_TYPE_SUMMARY_BY_TITLE = 'titleSummary';
88
+ export const PROMPT_TYPE_CONTINUE = 'continue';
89
+ export const PROMPT_TYPE_SIMPLIFY = 'simplify';
90
+ export const PROMPT_TYPE_CORRECT_SPELLING = 'correctSpelling';
91
+ export const PROMPT_TYPE_GENERATE_TITLE = 'generateTitle';
92
+ export const PROMPT_TYPE_MAKE_LONGER = 'makeLonger';
93
+ export const PROMPT_TYPE_MAKE_SHORTER = 'makeShorter';
94
+ export const PROMPT_TYPE_CHANGE_TONE = 'changeTone';
95
+ export const PROMPT_TYPE_SUMMARIZE = 'summarize';
96
+ export const PROMPT_TYPE_CHANGE_LANGUAGE = 'changeLanguage';
97
+ export const PROMPT_TYPE_USER_PROMPT = 'userPrompt';
98
+ export const PROMPT_TYPE_JETPACK_FORM_CUSTOM_PROMPT = 'jetpackFormCustomPrompt';
99
+ export const PROMPT_TYPE_TRANSFORM_LIST_TO_TABLE = 'transformListToTable';
100
+ export const PROMPT_TYPE_WRITE_POST_FROM_LIST = 'writePostFromList';
101
+ // Human-readable labels
102
+ export const TRANSLATE_LABEL = __('Translate', 'jetpack-ai-client');
103
+ export const TONE_LABEL = __('Change tone', 'jetpack-ai-client');
104
+ export const CORRECT_SPELLING_LABEL = __('Correct spelling and grammar', 'jetpack-ai-client');
105
+ export const SIMPLIFY_LABEL = __('Simplify', 'jetpack-ai-client');
106
+ export const SUMMARIZE_LABEL = __('Summarize', 'jetpack-ai-client');
107
+ export const MAKE_SHORTER_LABEL = __('Make shorter', 'jetpack-ai-client');
108
+ export const MAKE_LONGER_LABEL = __('Expand', 'jetpack-ai-client');
109
+ export const TURN_LIST_INTO_TABLE_LABEL = __('Turn list into a table', 'jetpack-ai-client');
110
+ export const WRITE_POST_FROM_LIST_LABEL = __('Write a post from this list', 'jetpack-ai-client');
111
+ export const GENERATE_TITLE_LABEL = __('Generate a post title', 'jetpack-ai-client');
112
+ export const SUMMARY_BASED_ON_TITLE_LABEL = __('Summary based on title', 'jetpack-ai-client');
113
+ export const CONTINUE_LABEL = __('Continue writing', 'jetpack-ai-client');
@@ -15,4 +15,5 @@ export * from './components/index.js';
15
15
  export * from './data-flow/index.js';
16
16
  export * from './types.js';
17
17
  export * from './libs/index.js';
18
+ export * from './constants.js';
18
19
  export * from './logo-generator/index.js';
@@ -36,6 +36,10 @@ export * from './types.js';
36
36
  * Libs
37
37
  */
38
38
  export * from './libs/index.js';
39
+ /*
40
+ * Constants
41
+ */
42
+ export * from './constants.js';
39
43
  /*
40
44
  * Logo Generator
41
45
  */
@@ -1,2 +1,3 @@
1
1
  export { MarkdownToHTML, HTMLToMarkdown, renderHTMLFromMarkdown, renderMarkdownFromHTML, fixes, } from './markdown/index.js';
2
2
  export type { RenderHTMLRules } from './markdown/index.js';
3
+ export { mapActionToHumanText } from './map-action-to-human-text.js';
@@ -1 +1,2 @@
1
1
  export { MarkdownToHTML, HTMLToMarkdown, renderHTMLFromMarkdown, renderMarkdownFromHTML, fixes, } from './markdown/index.js';
2
+ export { mapActionToHumanText } from './map-action-to-human-text.js';
@@ -0,0 +1,13 @@
1
+ type MapActionToHumanTextOptions = {
2
+ language?: string;
3
+ tone?: string;
4
+ };
5
+ /**
6
+ * Maps an action to a human-readable text.
7
+ *
8
+ * @param action - The action to map.
9
+ * @param options - The options for the mapping.
10
+ * @return {string} The human-readable text.
11
+ */
12
+ export declare function mapActionToHumanText(action: string, options?: MapActionToHumanTextOptions): string | null;
13
+ export {};