@automattic/jetpack-ai-client 0.13.0 → 0.13.1
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 +9 -0
- package/build/components/ai-control/ai-control.d.ts +2 -1
- package/build/components/ai-control/ai-control.js +2 -2
- package/build/components/ai-control/extension-ai-control.d.ts +5 -3
- package/build/components/ai-control/extension-ai-control.js +8 -5
- package/build/components/message/index.d.ts +1 -1
- package/build/components/message/index.js +1 -1
- package/package.json +3 -3
- package/src/components/ai-control/ai-control.tsx +6 -1
- package/src/components/ai-control/extension-ai-control.tsx +18 -6
- package/src/components/message/index.tsx +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ 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.13.1] - 2024-05-13
|
|
9
|
+
### Added
|
|
10
|
+
- AI Client: Add className to AI Control component. [#37322]
|
|
11
|
+
- AI Client: Add "try again" prop on Extension AI Control. [#37250]
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- AI Client: Add event to upgrade handler function of Extension AI Control. [#37224]
|
|
15
|
+
|
|
8
16
|
## [0.13.0] - 2024-05-06
|
|
9
17
|
### Added
|
|
10
18
|
- AI Client: Add wrapper ref to AI Control. [#37145]
|
|
@@ -306,6 +314,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
306
314
|
- Updated package dependencies. [#31659]
|
|
307
315
|
- Updated package dependencies. [#31785]
|
|
308
316
|
|
|
317
|
+
[0.13.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.13.0...v0.13.1
|
|
309
318
|
[0.13.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.12.4...v0.13.0
|
|
310
319
|
[0.12.4]: https://github.com/Automattic/jetpack-ai-client/compare/v0.12.3...v0.12.4
|
|
311
320
|
[0.12.3]: https://github.com/Automattic/jetpack-ai-client/compare/v0.12.2...v0.12.3
|
|
@@ -6,6 +6,7 @@ import './style.scss';
|
|
|
6
6
|
import type { RequestingStateProp } from '../../types.js';
|
|
7
7
|
import type { ReactElement } from 'react';
|
|
8
8
|
type AIControlProps = {
|
|
9
|
+
className?: string;
|
|
9
10
|
disabled?: boolean;
|
|
10
11
|
value: string;
|
|
11
12
|
placeholder?: string;
|
|
@@ -25,5 +26,5 @@ type AIControlProps = {
|
|
|
25
26
|
* @param {AIControlProps} props - Component props
|
|
26
27
|
* @returns {ReactElement} Rendered component
|
|
27
28
|
*/
|
|
28
|
-
export default function AIControl({ disabled, value, placeholder, isTransparent, state, onChange, banner, error, actions, message, promptUserInputRef, wrapperRef, }: AIControlProps): ReactElement;
|
|
29
|
+
export default function AIControl({ className, disabled, value, placeholder, isTransparent, state, onChange, banner, error, actions, message, promptUserInputRef, wrapperRef, }: AIControlProps): ReactElement;
|
|
29
30
|
export {};
|
|
@@ -15,8 +15,8 @@ import './style.scss';
|
|
|
15
15
|
* @param {AIControlProps} props - Component props
|
|
16
16
|
* @returns {ReactElement} Rendered component
|
|
17
17
|
*/
|
|
18
|
-
export default function AIControl({ disabled = false, value = '', placeholder = '', isTransparent = false, state = 'init', onChange, banner = null, error = null, actions = null, message = null, promptUserInputRef = null, wrapperRef = null, }) {
|
|
19
|
-
return (_jsxs("div", { className:
|
|
18
|
+
export default function AIControl({ className, disabled = false, value = '', placeholder = '', isTransparent = false, state = 'init', onChange, banner = null, error = null, actions = null, message = null, promptUserInputRef = null, wrapperRef = null, }) {
|
|
19
|
+
return (_jsxs("div", { className: classNames('jetpack-components-ai-control__container-wrapper', className), ref: wrapperRef, children: [error, _jsxs("div", { className: "jetpack-components-ai-control__container", children: [banner, _jsxs("div", { className: classNames('jetpack-components-ai-control__wrapper', {
|
|
20
20
|
'is-transparent': isTransparent,
|
|
21
21
|
}), children: [_jsx(AiStatusIndicator, { state: state }), _jsx("div", { className: "jetpack-components-ai-control__input-wrapper", children: _jsx(PlainText, { value: value, onChange: onChange, placeholder: placeholder, className: "jetpack-components-ai-control__input", disabled: disabled, ref: promptUserInputRef }) }), actions] }), message] })] }));
|
|
22
22
|
}
|
|
@@ -4,8 +4,9 @@ import './style.scss';
|
|
|
4
4
|
* Types
|
|
5
5
|
*/
|
|
6
6
|
import type { RequestingStateProp } from '../../types.js';
|
|
7
|
-
import type { ReactElement } from 'react';
|
|
7
|
+
import type { ReactElement, MouseEvent } from 'react';
|
|
8
8
|
type ExtensionAIControlProps = {
|
|
9
|
+
className?: string;
|
|
9
10
|
disabled?: boolean;
|
|
10
11
|
value: string;
|
|
11
12
|
placeholder?: string;
|
|
@@ -22,7 +23,8 @@ type ExtensionAIControlProps = {
|
|
|
22
23
|
onStop?: () => void;
|
|
23
24
|
onClose?: () => void;
|
|
24
25
|
onUndo?: () => void;
|
|
25
|
-
onUpgrade?: () => void;
|
|
26
|
+
onUpgrade?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
27
|
+
onTryAgain?: () => void;
|
|
26
28
|
};
|
|
27
29
|
/**
|
|
28
30
|
* ExtensionAIControl component. Used by the AI Assistant inline extensions, adding logic and components to the base AIControl component.
|
|
@@ -31,6 +33,6 @@ type ExtensionAIControlProps = {
|
|
|
31
33
|
* @param {React.MutableRefObject} ref - Ref to the component
|
|
32
34
|
* @returns {ReactElement} Rendered component
|
|
33
35
|
*/
|
|
34
|
-
export declare function ExtensionAIControl({ disabled, value, placeholder, showButtonLabels, isTransparent, state, showGuideLine, error, requestsRemaining, showUpgradeMessage, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, }: ExtensionAIControlProps, ref: React.MutableRefObject<HTMLInputElement>): ReactElement;
|
|
36
|
+
export declare function ExtensionAIControl({ className, disabled, value, placeholder, showButtonLabels, isTransparent, state, showGuideLine, error, requestsRemaining, showUpgradeMessage, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, onTryAgain, }: ExtensionAIControlProps, ref: React.MutableRefObject<HTMLInputElement>): ReactElement;
|
|
35
37
|
declare const _default: React.ForwardRefExoticComponent<ExtensionAIControlProps & React.RefAttributes<HTMLInputElement>>;
|
|
36
38
|
export default _default;
|
|
@@ -21,7 +21,7 @@ import './style.scss';
|
|
|
21
21
|
* @param {React.MutableRefObject} ref - Ref to the component
|
|
22
22
|
* @returns {ReactElement} Rendered component
|
|
23
23
|
*/
|
|
24
|
-
export function ExtensionAIControl({ disabled = false, value = '', placeholder = '', showButtonLabels = true, isTransparent = false, state = 'init', showGuideLine = false, error, requestsRemaining, showUpgradeMessage = false, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, }, ref) {
|
|
24
|
+
export function ExtensionAIControl({ className, disabled = false, value = '', placeholder = '', showButtonLabels = true, isTransparent = false, state = 'init', showGuideLine = false, error, requestsRemaining, showUpgradeMessage = false, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, onTryAgain, }, ref) {
|
|
25
25
|
const loading = state === 'requesting' || state === 'suggesting';
|
|
26
26
|
const [editRequest, setEditRequest] = useState(false);
|
|
27
27
|
const [lastValue, setLastValue] = useState(value || null);
|
|
@@ -61,9 +61,12 @@ export function ExtensionAIControl({ disabled = false, value = '', placeholder =
|
|
|
61
61
|
const undoHandler = useCallback(() => {
|
|
62
62
|
onUndo?.();
|
|
63
63
|
}, [onUndo]);
|
|
64
|
-
const upgradeHandler = useCallback(() => {
|
|
65
|
-
onUpgrade?.();
|
|
64
|
+
const upgradeHandler = useCallback((event) => {
|
|
65
|
+
onUpgrade?.(event);
|
|
66
66
|
}, [onUpgrade]);
|
|
67
|
+
const tryAgainHandler = useCallback(() => {
|
|
68
|
+
onTryAgain?.();
|
|
69
|
+
}, [onTryAgain]);
|
|
67
70
|
useKeyboardShortcut('enter', e => {
|
|
68
71
|
e.preventDefault();
|
|
69
72
|
sendHandler();
|
|
@@ -73,7 +76,7 @@ export function ExtensionAIControl({ disabled = false, value = '', placeholder =
|
|
|
73
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') })] }) }))] })) }));
|
|
74
77
|
let message = null;
|
|
75
78
|
if (error) {
|
|
76
|
-
message = _jsx(ErrorMessage, { error: error, onTryAgainClick:
|
|
79
|
+
message = _jsx(ErrorMessage, { error: error, onTryAgainClick: tryAgainHandler });
|
|
77
80
|
}
|
|
78
81
|
else if (showUpgradeMessage) {
|
|
79
82
|
message = (_jsx(UpgradeMessage, { requestsRemaining: requestsRemaining, onUpgradeClick: upgradeHandler }));
|
|
@@ -81,6 +84,6 @@ export function ExtensionAIControl({ disabled = false, value = '', placeholder =
|
|
|
81
84
|
else if (showGuideLine) {
|
|
82
85
|
message = _jsx(GuidelineMessage, {});
|
|
83
86
|
}
|
|
84
|
-
return (_jsx(AIControl, { disabled: disabled || loading, value: value, placeholder: placeholder, isTransparent: isTransparent, state: state, onChange: changeHandler, actions: actions, message: message, promptUserInputRef: promptUserInputRef, wrapperRef: wrapperRef }));
|
|
87
|
+
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 }));
|
|
85
88
|
}
|
|
86
89
|
export default forwardRef(ExtensionAIControl);
|
|
@@ -21,7 +21,7 @@ export type MessageProps = {
|
|
|
21
21
|
};
|
|
22
22
|
export type UpgradeMessageProps = {
|
|
23
23
|
requestsRemaining: number;
|
|
24
|
-
onUpgradeClick: () => void;
|
|
24
|
+
onUpgradeClick: (event?: React.MouseEvent<HTMLButtonElement>) => void;
|
|
25
25
|
};
|
|
26
26
|
export type ErrorMessageProps = {
|
|
27
27
|
error?: string;
|
|
@@ -65,5 +65,5 @@ export function ErrorMessage({ error, onTryAgainClick }) {
|
|
|
65
65
|
const errorMessage = error || __('Something went wrong', 'jetpack-ai-client');
|
|
66
66
|
return (_jsxs(Message, { severity: MESSAGE_SEVERITY_ERROR, children: [_jsx("span", { children: sprintf(
|
|
67
67
|
// translators: %1$d: A dynamic error message
|
|
68
|
-
__('Error: %1$s
|
|
68
|
+
__('Error: %1$s', 'jetpack-ai-client'), errorMessage) }), _jsx(Button, { variant: "link", onClick: onTryAgainClick, children: __('Try Again', 'jetpack-ai-client') })] }));
|
|
69
69
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@automattic/jetpack-ai-client",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.1",
|
|
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": {
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"types": "./build/index.d.ts",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@automattic/jetpack-base-styles": "^0.6.24",
|
|
46
|
-
"@automattic/jetpack-connection": "^0.33.
|
|
47
|
-
"@automattic/jetpack-shared-extension-utils": "^0.14.
|
|
46
|
+
"@automattic/jetpack-connection": "^0.33.10",
|
|
47
|
+
"@automattic/jetpack-shared-extension-utils": "^0.14.12",
|
|
48
48
|
"@microsoft/fetch-event-source": "2.0.1",
|
|
49
49
|
"@types/react": "18.3.1",
|
|
50
50
|
"@wordpress/api-fetch": "6.53.0",
|
|
@@ -16,6 +16,7 @@ import type { RequestingStateProp } from '../../types.js';
|
|
|
16
16
|
import type { ReactElement } from 'react';
|
|
17
17
|
|
|
18
18
|
type AIControlProps = {
|
|
19
|
+
className?: string;
|
|
19
20
|
disabled?: boolean;
|
|
20
21
|
value: string;
|
|
21
22
|
placeholder?: string;
|
|
@@ -37,6 +38,7 @@ type AIControlProps = {
|
|
|
37
38
|
* @returns {ReactElement} Rendered component
|
|
38
39
|
*/
|
|
39
40
|
export default function AIControl( {
|
|
41
|
+
className,
|
|
40
42
|
disabled = false,
|
|
41
43
|
value = '',
|
|
42
44
|
placeholder = '',
|
|
@@ -51,7 +53,10 @@ export default function AIControl( {
|
|
|
51
53
|
wrapperRef = null,
|
|
52
54
|
}: AIControlProps ): ReactElement {
|
|
53
55
|
return (
|
|
54
|
-
<div
|
|
56
|
+
<div
|
|
57
|
+
className={ classNames( 'jetpack-components-ai-control__container-wrapper', className ) }
|
|
58
|
+
ref={ wrapperRef }
|
|
59
|
+
>
|
|
55
60
|
{ error }
|
|
56
61
|
<div className="jetpack-components-ai-control__container">
|
|
57
62
|
{ banner }
|
|
@@ -17,9 +17,10 @@ import './style.scss';
|
|
|
17
17
|
* Types
|
|
18
18
|
*/
|
|
19
19
|
import type { RequestingStateProp } from '../../types.js';
|
|
20
|
-
import type { ReactElement } from 'react';
|
|
20
|
+
import type { ReactElement, MouseEvent } from 'react';
|
|
21
21
|
|
|
22
22
|
type ExtensionAIControlProps = {
|
|
23
|
+
className?: string;
|
|
23
24
|
disabled?: boolean;
|
|
24
25
|
value: string;
|
|
25
26
|
placeholder?: string;
|
|
@@ -36,7 +37,8 @@ type ExtensionAIControlProps = {
|
|
|
36
37
|
onStop?: () => void;
|
|
37
38
|
onClose?: () => void;
|
|
38
39
|
onUndo?: () => void;
|
|
39
|
-
onUpgrade?: () => void;
|
|
40
|
+
onUpgrade?: ( event: MouseEvent< HTMLButtonElement > ) => void;
|
|
41
|
+
onTryAgain?: () => void;
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
/**
|
|
@@ -48,6 +50,7 @@ type ExtensionAIControlProps = {
|
|
|
48
50
|
*/
|
|
49
51
|
export function ExtensionAIControl(
|
|
50
52
|
{
|
|
53
|
+
className,
|
|
51
54
|
disabled = false,
|
|
52
55
|
value = '',
|
|
53
56
|
placeholder = '',
|
|
@@ -65,6 +68,7 @@ export function ExtensionAIControl(
|
|
|
65
68
|
onClose,
|
|
66
69
|
onUndo,
|
|
67
70
|
onUpgrade,
|
|
71
|
+
onTryAgain,
|
|
68
72
|
}: ExtensionAIControlProps,
|
|
69
73
|
ref: React.MutableRefObject< HTMLInputElement >
|
|
70
74
|
): ReactElement {
|
|
@@ -118,9 +122,16 @@ export function ExtensionAIControl(
|
|
|
118
122
|
onUndo?.();
|
|
119
123
|
}, [ onUndo ] );
|
|
120
124
|
|
|
121
|
-
const upgradeHandler = useCallback(
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
const upgradeHandler = useCallback(
|
|
126
|
+
( event: MouseEvent< HTMLButtonElement > ) => {
|
|
127
|
+
onUpgrade?.( event );
|
|
128
|
+
},
|
|
129
|
+
[ onUpgrade ]
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const tryAgainHandler = useCallback( () => {
|
|
133
|
+
onTryAgain?.();
|
|
134
|
+
}, [ onTryAgain ] );
|
|
124
135
|
|
|
125
136
|
useKeyboardShortcut(
|
|
126
137
|
'enter',
|
|
@@ -192,7 +203,7 @@ export function ExtensionAIControl(
|
|
|
192
203
|
|
|
193
204
|
let message = null;
|
|
194
205
|
if ( error ) {
|
|
195
|
-
message = <ErrorMessage error={ error } onTryAgainClick={
|
|
206
|
+
message = <ErrorMessage error={ error } onTryAgainClick={ tryAgainHandler } />;
|
|
196
207
|
} else if ( showUpgradeMessage ) {
|
|
197
208
|
message = (
|
|
198
209
|
<UpgradeMessage requestsRemaining={ requestsRemaining } onUpgradeClick={ upgradeHandler } />
|
|
@@ -203,6 +214,7 @@ export function ExtensionAIControl(
|
|
|
203
214
|
|
|
204
215
|
return (
|
|
205
216
|
<AIControl
|
|
217
|
+
className={ className }
|
|
206
218
|
disabled={ disabled || loading }
|
|
207
219
|
value={ value }
|
|
208
220
|
placeholder={ placeholder }
|
|
@@ -39,7 +39,7 @@ export type MessageProps = {
|
|
|
39
39
|
|
|
40
40
|
export type UpgradeMessageProps = {
|
|
41
41
|
requestsRemaining: number;
|
|
42
|
-
onUpgradeClick: () => void;
|
|
42
|
+
onUpgradeClick: ( event?: React.MouseEvent< HTMLButtonElement > ) => void;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
export type ErrorMessageProps = {
|
|
@@ -145,7 +145,7 @@ export function ErrorMessage( { error, onTryAgainClick }: ErrorMessageProps ): R
|
|
|
145
145
|
<span>
|
|
146
146
|
{ sprintf(
|
|
147
147
|
// translators: %1$d: A dynamic error message
|
|
148
|
-
__( 'Error: %1$s
|
|
148
|
+
__( 'Error: %1$s', 'jetpack-ai-client' ),
|
|
149
149
|
errorMessage
|
|
150
150
|
) }
|
|
151
151
|
</span>
|