@automattic/jetpack-ai-client 0.24.2 → 0.25.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 +16 -5
- package/build/ai-client/src/logo-generator/components/prompt.d.ts +2 -1
- package/build/ai-client/src/logo-generator/components/prompt.js +16 -4
- package/package.json +13 -13
- package/src/logo-generator/components/prompt.scss +4 -0
- package/src/logo-generator/components/prompt.tsx +20 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ 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.0] - 2024-11-25
|
|
9
|
+
### Added
|
|
10
|
+
- AI Client: split disabled prop to allow disabling input and action button separately [#40210]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- AI Client: fix prompt cursor to text when editable [#40247]
|
|
14
|
+
- Updated package dependencies. [#40288]
|
|
15
|
+
|
|
16
|
+
## [0.24.3] - 2024-11-18
|
|
17
|
+
### Changed
|
|
18
|
+
- AI Client: add effect on AiModalInputPrompt to update/set prompt on prop update [#40113]
|
|
19
|
+
|
|
8
20
|
## [0.24.2] - 2024-11-11
|
|
9
21
|
### Changed
|
|
10
22
|
- Updated package dependencies. [#39999] [#40000]
|
|
@@ -228,8 +240,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
228
240
|
### Changed
|
|
229
241
|
- AI Client: change loading and error state handling on media recording hook. [#36001]
|
|
230
242
|
- AI Client: publish audio information on the validation success callback of the audio validation hook. [#36094]
|
|
231
|
-
- Updated package dependencies. [#36095]
|
|
232
|
-
- Updated package dependencies. [#36143]
|
|
243
|
+
- Updated package dependencies. [#36095] [#36143]
|
|
233
244
|
|
|
234
245
|
### Fixed
|
|
235
246
|
- AI Client: fixed transcription request from P2 editor [#36081]
|
|
@@ -458,10 +469,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
458
469
|
|
|
459
470
|
### Changed
|
|
460
471
|
- AI Client: stop using smart document visibility handling on the fetchEventSource library, so it does not restart the completion when changing tabs. [#32004]
|
|
461
|
-
- Updated package dependencies. [#31468]
|
|
462
|
-
- Updated package dependencies. [#31659]
|
|
463
|
-
- Updated package dependencies. [#31785]
|
|
472
|
+
- Updated package dependencies. [#31468] [#31659] [#31785]
|
|
464
473
|
|
|
474
|
+
[0.25.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.24.3...v0.25.0
|
|
475
|
+
[0.24.3]: https://github.com/Automattic/jetpack-ai-client/compare/v0.24.2...v0.24.3
|
|
465
476
|
[0.24.2]: https://github.com/Automattic/jetpack-ai-client/compare/v0.24.1...v0.24.2
|
|
466
477
|
[0.24.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.24.0...v0.24.1
|
|
467
478
|
[0.24.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.23.0...v0.24.0
|
|
@@ -3,10 +3,11 @@ import './prompt.scss';
|
|
|
3
3
|
type PromptProps = {
|
|
4
4
|
initialPrompt?: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const AiModalPromptInput: ({ prompt, setPrompt, disabled, generateHandler, placeholder, buttonLabel, }: {
|
|
6
|
+
export declare const AiModalPromptInput: ({ prompt, setPrompt, disabled, actionDisabled, generateHandler, placeholder, buttonLabel, }: {
|
|
7
7
|
prompt: string;
|
|
8
8
|
setPrompt: Dispatch<SetStateAction<string>>;
|
|
9
9
|
disabled: boolean;
|
|
10
|
+
actionDisabled: boolean;
|
|
10
11
|
generateHandler: () => void;
|
|
11
12
|
placeholder?: string;
|
|
12
13
|
buttonLabel?: string;
|
|
@@ -21,9 +21,8 @@ import { FairUsageNotice } from './fair-usage-notice.js';
|
|
|
21
21
|
import { UpgradeNudge } from './upgrade-nudge.js';
|
|
22
22
|
import './prompt.scss';
|
|
23
23
|
const debug = debugFactory('jetpack-ai-calypso:prompt-box');
|
|
24
|
-
export const AiModalPromptInput = ({ prompt = '', setPrompt = () => { }, disabled = false, generateHandler = () => { }, placeholder = '', buttonLabel = '', }) => {
|
|
24
|
+
export const AiModalPromptInput = ({ prompt = '', setPrompt = () => { }, disabled = false, actionDisabled = false, generateHandler = () => { }, placeholder = '', buttonLabel = '', }) => {
|
|
25
25
|
const inputRef = useRef(null);
|
|
26
|
-
const hasPrompt = prompt?.length >= MINIMUM_PROMPT_LENGTH;
|
|
27
26
|
const onPromptInput = (event) => {
|
|
28
27
|
setPrompt(event.target.textContent || '');
|
|
29
28
|
};
|
|
@@ -48,9 +47,22 @@ export const AiModalPromptInput = ({ prompt = '', setPrompt = () => { }, disable
|
|
|
48
47
|
}
|
|
49
48
|
event.stopPropagation();
|
|
50
49
|
};
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
// Update prompt text node when prop changes
|
|
52
|
+
if (inputRef.current && inputRef.current.textContent !== prompt) {
|
|
53
|
+
inputRef.current.textContent = prompt;
|
|
54
|
+
}
|
|
55
|
+
}, [prompt]);
|
|
56
|
+
// fix for contenteditable divs not being able to be cleared by the user
|
|
57
|
+
// as per default browser behavior
|
|
58
|
+
const onKeyUp = () => {
|
|
59
|
+
if (inputRef.current?.textContent === '') {
|
|
60
|
+
inputRef.current.innerHTML = '';
|
|
61
|
+
}
|
|
62
|
+
};
|
|
51
63
|
return (_jsxs("div", { className: "jetpack-ai-logo-generator__prompt-query", children: [_jsx("div", { role: "textbox", tabIndex: 0, ref: inputRef, contentEditable: !disabled,
|
|
52
64
|
// The content editable div is expected to be updated by the enhance prompt, so warnings are suppressed
|
|
53
|
-
suppressContentEditableWarning: true, className: "prompt-query__input", onInput: onPromptInput, onPaste: onPromptPaste, onKeyDown: onKeyDown, "data-placeholder": placeholder }), _jsx(Button, { variant: "primary", className: "jetpack-ai-logo-generator__prompt-submit", onClick: generateHandler, disabled:
|
|
65
|
+
suppressContentEditableWarning: true, className: "prompt-query__input", onInput: onPromptInput, onPaste: onPromptPaste, onKeyDown: onKeyDown, onKeyUp: onKeyUp, "data-placeholder": placeholder }), _jsx(Button, { variant: "primary", className: "jetpack-ai-logo-generator__prompt-submit", onClick: generateHandler, disabled: actionDisabled, children: buttonLabel || __('Generate', 'jetpack-ai-client') })] }));
|
|
54
66
|
};
|
|
55
67
|
export const Prompt = ({ initialPrompt = '' }) => {
|
|
56
68
|
const { tracks } = useAnalytics();
|
|
@@ -142,7 +154,7 @@ export const Prompt = ({ initialPrompt = '' }) => {
|
|
|
142
154
|
setStyle(imageStyle);
|
|
143
155
|
recordTracksEvent(EVENT_SWITCH_STYLE, { context, style: imageStyle });
|
|
144
156
|
}, [context, setStyle, recordTracksEvent]);
|
|
145
|
-
return (_jsxs("div", { className: "jetpack-ai-logo-generator__prompt", children: [_jsxs("div", { className: "jetpack-ai-logo-generator__prompt-header", children: [_jsx("div", { className: "jetpack-ai-logo-generator__prompt-label", children: __('Describe your site:', 'jetpack-ai-client') }), _jsx("div", { className: "jetpack-ai-logo-generator__prompt-actions", children: _jsxs(Button, { variant: "link", disabled: isBusy || requireUpgrade || !hasPrompt, onClick: onEnhance, children: [_jsx(AiIcon, {}), enhanceButtonLabel] }) }), showStyleSelector && (_jsx(SelectControl, { __nextHasNoMarginBottom: true, value: style, options: styles, onChange: updateStyle, disabled: isBusy || requireUpgrade }))] }), _jsx(AiModalPromptInput, { prompt: prompt, setPrompt: setPrompt, generateHandler: onGenerate, disabled: isBusy || requireUpgrade, placeholder: __('Describe your site or simply ask for a logo specifying some details about it', 'jetpack-ai-client') }), _jsxs("div", { className: "jetpack-ai-logo-generator__prompt-footer", children: [!isUnlimited && !requireUpgrade && (_jsxs("div", { className: "jetpack-ai-logo-generator__prompt-requests", children: [_jsx("div", { children: sprintf(
|
|
157
|
+
return (_jsxs("div", { className: "jetpack-ai-logo-generator__prompt", children: [_jsxs("div", { className: "jetpack-ai-logo-generator__prompt-header", children: [_jsx("div", { className: "jetpack-ai-logo-generator__prompt-label", children: __('Describe your site:', 'jetpack-ai-client') }), _jsx("div", { className: "jetpack-ai-logo-generator__prompt-actions", children: _jsxs(Button, { variant: "link", disabled: isBusy || requireUpgrade || !hasPrompt, onClick: onEnhance, children: [_jsx(AiIcon, {}), enhanceButtonLabel] }) }), showStyleSelector && (_jsx(SelectControl, { __nextHasNoMarginBottom: true, value: style, options: styles, onChange: updateStyle, disabled: isBusy || requireUpgrade }))] }), _jsx(AiModalPromptInput, { prompt: prompt, setPrompt: setPrompt, generateHandler: onGenerate, disabled: isBusy || requireUpgrade, actionDisabled: isBusy || requireUpgrade || !hasPrompt, placeholder: __('Describe your site or simply ask for a logo specifying some details about it', 'jetpack-ai-client') }), _jsxs("div", { className: "jetpack-ai-logo-generator__prompt-footer", children: [!isUnlimited && !requireUpgrade && (_jsxs("div", { className: "jetpack-ai-logo-generator__prompt-requests", children: [_jsx("div", { children: sprintf(
|
|
146
158
|
// translators: %u is the number of requests
|
|
147
159
|
__('%u requests remaining.', 'jetpack-ai-client'), requestsRemaining) }), hasNextTier && (_jsxs(_Fragment, { children: ["\u00A0", _jsx(Button, { variant: "link", href: checkoutUrl, target: "_blank", onClick: onUpgradeClick, children: __('Upgrade', 'jetpack-ai-client') })] })), "\u00A0", _jsx(Tooltip, { text: __('Logo generation costs 10 requests; prompt enhancement costs 1 request each', 'jetpack-ai-client'), placement: "bottom", children: _jsx(Icon, { className: "prompt-footer__icon", icon: info }) })] })), requireUpgrade && tierPlansEnabled && _jsx(UpgradeNudge, {}), requireUpgrade && !tierPlansEnabled && _jsx(FairUsageNotice, {}), enhancePromptFetchError && (_jsx("div", { className: "jetpack-ai-logo-generator__prompt-error", children: __('Error enhancing prompt. Please try again.', 'jetpack-ai-client') })), logoFetchError && (_jsx("div", { className: "jetpack-ai-logo-generator__prompt-error", children: __('Error generating logo. Please try again.', 'jetpack-ai-client') }))] })] }));
|
|
148
160
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@automattic/jetpack-ai-client",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.25.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,21 +44,21 @@
|
|
|
44
44
|
"main": "./build/index.js",
|
|
45
45
|
"types": "./build/index.d.ts",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@automattic/jetpack-base-styles": "^0.6.
|
|
48
|
-
"@automattic/jetpack-connection": "^0.35.
|
|
49
|
-
"@automattic/jetpack-shared-extension-utils": "^0.15.
|
|
47
|
+
"@automattic/jetpack-base-styles": "^0.6.37",
|
|
48
|
+
"@automattic/jetpack-connection": "^0.35.19",
|
|
49
|
+
"@automattic/jetpack-shared-extension-utils": "^0.15.18",
|
|
50
50
|
"@microsoft/fetch-event-source": "2.0.1",
|
|
51
51
|
"@types/react": "18.3.12",
|
|
52
52
|
"@types/wordpress__block-editor": "11.5.15",
|
|
53
|
-
"@wordpress/api-fetch": "7.
|
|
54
|
-
"@wordpress/blob": "4.
|
|
55
|
-
"@wordpress/block-editor": "14.
|
|
56
|
-
"@wordpress/components": "28.
|
|
57
|
-
"@wordpress/compose": "7.
|
|
58
|
-
"@wordpress/data": "10.
|
|
59
|
-
"@wordpress/element": "6.
|
|
60
|
-
"@wordpress/i18n": "5.
|
|
61
|
-
"@wordpress/icons": "10.
|
|
53
|
+
"@wordpress/api-fetch": "7.12.0",
|
|
54
|
+
"@wordpress/blob": "4.12.0",
|
|
55
|
+
"@wordpress/block-editor": "14.7.0",
|
|
56
|
+
"@wordpress/components": "28.12.0",
|
|
57
|
+
"@wordpress/compose": "7.12.0",
|
|
58
|
+
"@wordpress/data": "10.12.0",
|
|
59
|
+
"@wordpress/element": "6.12.0",
|
|
60
|
+
"@wordpress/i18n": "5.12.0",
|
|
61
|
+
"@wordpress/icons": "10.12.0",
|
|
62
62
|
"clsx": "2.1.1",
|
|
63
63
|
"debug": "4.3.4",
|
|
64
64
|
"markdown-it": "14.0.0",
|
|
@@ -42,6 +42,7 @@ export const AiModalPromptInput = ( {
|
|
|
42
42
|
prompt = '',
|
|
43
43
|
setPrompt = () => {},
|
|
44
44
|
disabled = false,
|
|
45
|
+
actionDisabled = false,
|
|
45
46
|
generateHandler = () => {},
|
|
46
47
|
placeholder = '',
|
|
47
48
|
buttonLabel = '',
|
|
@@ -49,12 +50,12 @@ export const AiModalPromptInput = ( {
|
|
|
49
50
|
prompt: string;
|
|
50
51
|
setPrompt: Dispatch< SetStateAction< string > >;
|
|
51
52
|
disabled: boolean;
|
|
53
|
+
actionDisabled: boolean;
|
|
52
54
|
generateHandler: () => void;
|
|
53
55
|
placeholder?: string;
|
|
54
56
|
buttonLabel?: string;
|
|
55
57
|
} ) => {
|
|
56
58
|
const inputRef = useRef< HTMLDivElement | null >( null );
|
|
57
|
-
const hasPrompt = prompt?.length >= MINIMUM_PROMPT_LENGTH;
|
|
58
59
|
|
|
59
60
|
const onPromptInput = ( event: React.ChangeEvent< HTMLInputElement > ) => {
|
|
60
61
|
setPrompt( event.target.textContent || '' );
|
|
@@ -87,6 +88,21 @@ export const AiModalPromptInput = ( {
|
|
|
87
88
|
event.stopPropagation();
|
|
88
89
|
};
|
|
89
90
|
|
|
91
|
+
useEffect( () => {
|
|
92
|
+
// Update prompt text node when prop changes
|
|
93
|
+
if ( inputRef.current && inputRef.current.textContent !== prompt ) {
|
|
94
|
+
inputRef.current.textContent = prompt;
|
|
95
|
+
}
|
|
96
|
+
}, [ prompt ] );
|
|
97
|
+
|
|
98
|
+
// fix for contenteditable divs not being able to be cleared by the user
|
|
99
|
+
// as per default browser behavior
|
|
100
|
+
const onKeyUp = () => {
|
|
101
|
+
if ( inputRef.current?.textContent === '' ) {
|
|
102
|
+
inputRef.current.innerHTML = '';
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
90
106
|
return (
|
|
91
107
|
<div className="jetpack-ai-logo-generator__prompt-query">
|
|
92
108
|
<div
|
|
@@ -100,13 +116,14 @@ export const AiModalPromptInput = ( {
|
|
|
100
116
|
onInput={ onPromptInput }
|
|
101
117
|
onPaste={ onPromptPaste }
|
|
102
118
|
onKeyDown={ onKeyDown }
|
|
119
|
+
onKeyUp={ onKeyUp }
|
|
103
120
|
data-placeholder={ placeholder }
|
|
104
121
|
></div>
|
|
105
122
|
<Button
|
|
106
123
|
variant="primary"
|
|
107
124
|
className="jetpack-ai-logo-generator__prompt-submit"
|
|
108
125
|
onClick={ generateHandler }
|
|
109
|
-
disabled={
|
|
126
|
+
disabled={ actionDisabled }
|
|
110
127
|
>
|
|
111
128
|
{ buttonLabel || __( 'Generate', 'jetpack-ai-client' ) }
|
|
112
129
|
</Button>
|
|
@@ -264,6 +281,7 @@ export const Prompt = ( { initialPrompt = '' }: PromptProps ) => {
|
|
|
264
281
|
setPrompt={ setPrompt }
|
|
265
282
|
generateHandler={ onGenerate }
|
|
266
283
|
disabled={ isBusy || requireUpgrade }
|
|
284
|
+
actionDisabled={ isBusy || requireUpgrade || ! hasPrompt }
|
|
267
285
|
placeholder={ __(
|
|
268
286
|
'Describe your site or simply ask for a logo specifying some details about it',
|
|
269
287
|
'jetpack-ai-client'
|