@automattic/jetpack-ai-client 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,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.4.0] - 2024-01-15
9
+ ### Added
10
+ - AI Client: introduce bannerComponent prop, React.Element, to render on top of the AI Control [#34918]
11
+
12
+ ### Fixed
13
+ - Jetpack AI: Check for post id type and only include numbers [#34974]
14
+
15
+ ## [0.3.1] - 2024-01-04
16
+ ### Changed
17
+ - Updated package dependencies. [#34815]
18
+
8
19
  ## [0.3.0] - 2023-12-20
9
20
  ### Changed
10
21
  - AI Client: improved usability with new block positioning, prompt and suggestion action buttons. [#34383]
@@ -176,6 +187,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
176
187
  - Updated package dependencies. [#31659]
177
188
  - Updated package dependencies. [#31785]
178
189
 
190
+ [0.4.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.3.1...v0.4.0
191
+ [0.3.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.3.0...v0.3.1
179
192
  [0.3.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.2.1...v0.3.0
180
193
  [0.2.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.2.0...v0.2.1
181
194
  [0.2.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.1.16...v0.2.0
@@ -24,6 +24,7 @@ type AiControlProps = {
24
24
  onAccept?: () => void;
25
25
  onDiscard?: () => void;
26
26
  showRemove?: boolean;
27
+ bannerComponent?: React.ReactElement;
27
28
  };
28
29
  /**
29
30
  * AI Control component.
@@ -32,6 +33,6 @@ type AiControlProps = {
32
33
  * @param {React.MutableRefObject} ref - Ref to the component.
33
34
  * @returns {React.ReactElement} Rendered component.
34
35
  */
35
- export declare function AIControl({ disabled, value, placeholder, showAccept, acceptLabel, showButtonLabels, isTransparent, state, showGuideLine, customFooter, onChange, onSend, onStop, onAccept, onDiscard, showRemove, }: AiControlProps, ref: React.MutableRefObject<null>): React.ReactElement;
36
+ export declare function AIControl({ disabled, value, placeholder, showAccept, acceptLabel, showButtonLabels, isTransparent, state, showGuideLine, customFooter, onChange, onSend, onStop, onAccept, onDiscard, showRemove, bannerComponent, }: AiControlProps, ref: React.MutableRefObject<null>): React.ReactElement;
36
37
  declare const _default: React.ForwardRefExoticComponent<AiControlProps & React.RefAttributes<null>>;
37
38
  export default _default;
@@ -25,7 +25,7 @@ const noop = () => { };
25
25
  * @param {React.MutableRefObject} ref - Ref to the component.
26
26
  * @returns {React.ReactElement} Rendered component.
27
27
  */
28
- export function AIControl({ disabled = false, value = '', placeholder = '', showAccept = false, acceptLabel = __('Accept', 'jetpack-ai-client'), showButtonLabels = true, isTransparent = false, state = 'init', showGuideLine = false, customFooter = null, onChange = noop, onSend = noop, onStop = noop, onAccept = noop, onDiscard = null, showRemove = false, }, ref // eslint-disable-line @typescript-eslint/ban-types
28
+ export function AIControl({ disabled = false, value = '', placeholder = '', showAccept = false, acceptLabel = __('Accept', 'jetpack-ai-client'), showButtonLabels = true, isTransparent = false, state = 'init', showGuideLine = false, customFooter = null, onChange = noop, onSend = noop, onStop = noop, onAccept = noop, onDiscard = null, showRemove = false, bannerComponent = null, }, ref // eslint-disable-line @typescript-eslint/ban-types
29
29
  ) {
30
30
  const promptUserInputRef = useRef(null);
31
31
  const loading = state === 'requesting' || state === 'suggesting';
@@ -81,7 +81,7 @@ export function AIControl({ disabled = false, value = '', placeholder = '', show
81
81
  }, {
82
82
  target: promptUserInputRef,
83
83
  });
84
- return (_jsx("div", { className: "jetpack-components-ai-control__container-wrapper", children: _jsxs("div", { className: "jetpack-components-ai-control__container", children: [_jsxs("div", { className: classNames('jetpack-components-ai-control__wrapper', {
84
+ return (_jsx("div", { className: "jetpack-components-ai-control__container-wrapper", children: _jsxs("div", { className: "jetpack-components-ai-control__container", children: [bannerComponent, _jsxs("div", { className: classNames('jetpack-components-ai-control__wrapper', {
85
85
  'is-transparent': isTransparent,
86
86
  }), children: [_jsx(AiStatusIndicator, { state: state }), _jsx("div", { className: "jetpack-components-ai-control__input-wrapper", children: _jsx(PlainText, { value: value, onChange: changeHandler, placeholder: placeholder, className: "jetpack-components-ai-control__input", disabled: loading || disabled, ref: promptUserInputRef }) }), (!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: sendRequest, 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: reusableBlock }) })] })), _jsx(Button, { className: "jetpack-components-ai-control__controls-prompt_button", onClick: onAccept, variant: "primary", label: acceptLabel, children: showButtonLabels ? acceptLabel : _jsx(Icon, { icon: check }) })] }))] }), showGuideLine && !loading && !editRequest && (customFooter || _jsx(GuidelineMessage, {}))] }) }));
87
87
  }
@@ -8,7 +8,7 @@ type SuggestionsEventSourceConstructorArgs = {
8
8
  question: PromptProp;
9
9
  token?: string;
10
10
  options?: {
11
- postId?: number;
11
+ postId?: number | string;
12
12
  feature?: 'ai-assistant-experimental' | string | undefined;
13
13
  fromCache?: boolean;
14
14
  functions?: Array<object>;
@@ -64,9 +64,9 @@ export default class SuggestionsEventSource extends EventTarget {
64
64
  }
65
65
  }
66
66
  const bodyData = {};
67
- // Populate body data with post id
68
- if (options?.postId) {
69
- bodyData.post_id = options.postId;
67
+ // Populate body data with post id only if it is an integer
68
+ if (Number.isInteger(parseInt(options.postId))) {
69
+ bodyData.post_id = +options.postId;
70
70
  }
71
71
  // If the url is not provided, we use the default one
72
72
  if (!url) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@automattic/jetpack-ai-client",
4
- "version": "0.3.0",
4
+ "version": "0.4.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": {
@@ -38,19 +38,19 @@
38
38
  "main": "./build/index.js",
39
39
  "types": "./build/index.d.ts",
40
40
  "dependencies": {
41
- "@automattic/jetpack-base-styles": "^0.6.14",
42
- "@automattic/jetpack-connection": "^0.30.11",
43
- "@automattic/jetpack-shared-extension-utils": "^0.13.5",
41
+ "@automattic/jetpack-base-styles": "^0.6.15",
42
+ "@automattic/jetpack-connection": "^0.30.12",
43
+ "@automattic/jetpack-shared-extension-utils": "^0.13.8",
44
44
  "@microsoft/fetch-event-source": "2.0.1",
45
45
  "@types/react": "18.2.33",
46
- "@wordpress/api-fetch": "6.44.0",
47
- "@wordpress/block-editor": "12.15.0",
48
- "@wordpress/components": "25.13.0",
49
- "@wordpress/compose": "6.24.0",
50
- "@wordpress/data": "9.17.0",
51
- "@wordpress/element": "5.24.0",
52
- "@wordpress/i18n": "4.47.0",
53
- "@wordpress/icons": "9.38.0",
46
+ "@wordpress/api-fetch": "6.45.0",
47
+ "@wordpress/block-editor": "12.16.0",
48
+ "@wordpress/components": "25.14.0",
49
+ "@wordpress/compose": "6.25.0",
50
+ "@wordpress/data": "9.18.0",
51
+ "@wordpress/element": "5.25.0",
52
+ "@wordpress/i18n": "4.48.0",
53
+ "@wordpress/icons": "9.39.0",
54
54
  "classnames": "2.3.2",
55
55
  "debug": "4.3.4",
56
56
  "react": "18.2.0",
@@ -42,6 +42,7 @@ type AiControlProps = {
42
42
  onAccept?: () => void;
43
43
  onDiscard?: () => void;
44
44
  showRemove?: boolean;
45
+ bannerComponent?: React.ReactElement;
45
46
  };
46
47
 
47
48
  // eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -72,6 +73,7 @@ export function AIControl(
72
73
  onAccept = noop,
73
74
  onDiscard = null,
74
75
  showRemove = false,
76
+ bannerComponent = null,
75
77
  }: AiControlProps,
76
78
  ref: React.MutableRefObject< null > // eslint-disable-line @typescript-eslint/ban-types
77
79
  ): React.ReactElement {
@@ -153,6 +155,7 @@ export function AIControl(
153
155
  return (
154
156
  <div className="jetpack-components-ai-control__container-wrapper">
155
157
  <div className="jetpack-components-ai-control__container">
158
+ { bannerComponent }
156
159
  <div
157
160
  className={ classNames( 'jetpack-components-ai-control__wrapper', {
158
161
  'is-transparent': isTransparent,
@@ -32,7 +32,7 @@ type SuggestionsEventSourceConstructorArgs = {
32
32
  question: PromptProp;
33
33
  token?: string;
34
34
  options?: {
35
- postId?: number;
35
+ postId?: number | string;
36
36
  feature?: 'ai-assistant-experimental' | string | undefined;
37
37
  fromCache?: boolean;
38
38
  functions?: Array< object >;
@@ -117,9 +117,9 @@ export default class SuggestionsEventSource extends EventTarget {
117
117
  model?: AiModelTypeProp;
118
118
  } = {};
119
119
 
120
- // Populate body data with post id
121
- if ( options?.postId ) {
122
- bodyData.post_id = options.postId;
120
+ // Populate body data with post id only if it is an integer
121
+ if ( Number.isInteger( parseInt( options.postId as string ) ) ) {
122
+ bodyData.post_id = +options.postId;
123
123
  }
124
124
 
125
125
  // If the url is not provided, we use the default one