@automattic/jetpack-ai-client 0.16.2 → 0.16.3
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 +5 -0
- package/build/ask-question/index.d.ts +3 -3
- package/build/ask-question/index.js +3 -3
- package/build/ask-question/sync.d.ts +3 -3
- package/build/ask-question/sync.js +3 -3
- package/build/audio-transcription/index.d.ts +3 -3
- package/build/audio-transcription/index.js +3 -3
- package/build/components/ai-control/ai-control.d.ts +1 -1
- package/build/components/ai-control/ai-control.js +1 -1
- package/build/components/ai-control/block-ai-control.d.ts +3 -3
- package/build/components/ai-control/block-ai-control.js +3 -3
- package/build/components/ai-control/extension-ai-control.d.ts +3 -3
- package/build/components/ai-control/extension-ai-control.js +3 -3
- package/build/components/ai-status-indicator/index.d.ts +1 -1
- package/build/components/ai-status-indicator/index.js +1 -1
- package/build/components/audio-duration-display/index.d.ts +1 -1
- package/build/components/audio-duration-display/index.js +1 -1
- package/build/components/audio-duration-display/lib/media.d.ts +2 -2
- package/build/components/audio-duration-display/lib/media.js +2 -2
- package/build/components/message/index.d.ts +4 -4
- package/build/components/message/index.js +4 -4
- package/build/data-flow/context.d.ts +2 -2
- package/build/data-flow/context.js +2 -2
- package/build/data-flow/use-ai-context.d.ts +1 -1
- package/build/data-flow/use-ai-context.js +1 -1
- package/build/data-flow/with-ai-assistant-data.d.ts +1 -1
- package/build/data-flow/with-ai-assistant-data.js +1 -1
- package/build/hooks/use-ai-suggestions/index.d.ts +3 -3
- package/build/hooks/use-ai-suggestions/index.js +11 -11
- package/build/hooks/use-audio-transcription/index.d.ts +1 -1
- package/build/hooks/use-audio-transcription/index.js +2 -2
- package/build/hooks/use-audio-validation/index.d.ts +1 -1
- package/build/hooks/use-audio-validation/index.js +1 -1
- package/build/hooks/use-image-generator/index.js +9 -9
- package/build/hooks/use-media-recording/index.d.ts +1 -1
- package/build/hooks/use-media-recording/index.js +4 -4
- package/build/hooks/use-save-to-media-library/index.d.ts +1 -1
- package/build/hooks/use-save-to-media-library/index.js +1 -1
- package/build/hooks/use-transcription-post-processing/index.d.ts +1 -1
- package/build/hooks/use-transcription-post-processing/index.js +1 -1
- package/build/jwt/index.d.ts +1 -1
- package/build/jwt/index.js +1 -1
- package/build/libs/markdown/html-to-markdown.d.ts +1 -1
- package/build/libs/markdown/html-to-markdown.js +1 -1
- package/build/libs/markdown/markdown-to-html.d.ts +4 -4
- package/build/libs/markdown/markdown-to-html.js +4 -4
- package/build/logo-generator/lib/logo-storage.d.ts +17 -17
- package/build/logo-generator/lib/logo-storage.js +17 -17
- package/build/logo-generator/lib/media-exists.d.ts +2 -2
- package/build/logo-generator/lib/media-exists.js +2 -2
- package/build/logo-generator/lib/set-site-logo.d.ts +3 -3
- package/build/logo-generator/lib/set-site-logo.js +3 -3
- package/build/logo-generator/lib/wpcom-limited-request.d.ts +1 -1
- package/build/logo-generator/lib/wpcom-limited-request.js +1 -1
- package/build/logo-generator/store/actions.d.ts +3 -3
- package/build/logo-generator/store/actions.js +3 -3
- package/build/logo-generator/store/reducer.d.ts +22 -22
- package/build/logo-generator/store/reducer.js +22 -22
- package/build/logo-generator/store/selectors.d.ts +20 -20
- package/build/logo-generator/store/selectors.js +20 -20
- package/build/suggestions-event-source/index.d.ts +1 -1
- package/build/suggestions-event-source/index.js +1 -1
- package/package.json +3 -3
- package/src/ask-question/index.ts +3 -3
- package/src/ask-question/sync.ts +3 -3
- package/src/audio-transcription/index.ts +3 -3
- package/src/components/ai-control/ai-control.tsx +1 -1
- package/src/components/ai-control/block-ai-control.tsx +3 -3
- package/src/components/ai-control/extension-ai-control.tsx +3 -3
- package/src/components/ai-status-indicator/index.tsx +1 -1
- package/src/components/audio-duration-display/index.tsx +1 -1
- package/src/components/audio-duration-display/lib/media.ts +2 -2
- package/src/components/message/index.tsx +4 -4
- package/src/data-flow/context.tsx +2 -2
- package/src/data-flow/use-ai-context.ts +1 -1
- package/src/data-flow/with-ai-assistant-data.tsx +1 -1
- package/src/hooks/use-ai-suggestions/index.ts +11 -11
- package/src/hooks/use-audio-transcription/index.ts +2 -2
- package/src/hooks/use-audio-validation/index.ts +1 -1
- package/src/hooks/use-image-generator/index.ts +9 -9
- package/src/hooks/use-media-recording/index.ts +4 -4
- package/src/hooks/use-save-to-media-library/index.ts +1 -1
- package/src/hooks/use-transcription-post-processing/index.ts +1 -1
- package/src/jwt/index.ts +1 -1
- package/src/libs/markdown/html-to-markdown.ts +1 -1
- package/src/libs/markdown/markdown-to-html.ts +4 -4
- package/src/logo-generator/assets/images/jetpack-logo.svg +4 -1
- package/src/logo-generator/lib/logo-storage.ts +17 -17
- package/src/logo-generator/lib/media-exists.ts +2 -2
- package/src/logo-generator/lib/set-site-logo.ts +3 -3
- package/src/logo-generator/lib/wpcom-limited-request.ts +1 -1
- package/src/logo-generator/store/actions.ts +3 -3
- package/src/logo-generator/store/reducer.ts +22 -22
- package/src/logo-generator/store/selectors.ts +20 -20
- package/src/suggestions-event-source/index.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ 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.16.3] - 2024-08-21
|
|
9
|
+
### Fixed
|
|
10
|
+
- Revert recent SVG image optimizations. [#38981]
|
|
11
|
+
|
|
8
12
|
## [0.16.2] - 2024-08-19
|
|
9
13
|
### Changed
|
|
10
14
|
- Update dependencies. [#38861] [#38662] [#38665] [#38893]
|
|
@@ -384,6 +388,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
384
388
|
- Updated package dependencies. [#31659]
|
|
385
389
|
- Updated package dependencies. [#31785]
|
|
386
390
|
|
|
391
|
+
[0.16.3]: https://github.com/Automattic/jetpack-ai-client/compare/v0.16.2...v0.16.3
|
|
387
392
|
[0.16.2]: https://github.com/Automattic/jetpack-ai-client/compare/v0.16.1...v0.16.2
|
|
388
393
|
[0.16.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.16.0...v0.16.1
|
|
389
394
|
[0.16.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.15.0...v0.16.0
|
|
@@ -15,9 +15,9 @@ export type AskQuestionOptionsArgProps = {
|
|
|
15
15
|
* An asynchronous function that asks a question
|
|
16
16
|
* and returns an event source with suggestions.
|
|
17
17
|
*
|
|
18
|
-
* @param {PromptProp}
|
|
19
|
-
* @param {AskQuestionOptionsArgProps} options
|
|
20
|
-
* @
|
|
18
|
+
* @param {PromptProp} question - The question to ask. It can be a simple string or an array of PromptMessageItemProps objects.
|
|
19
|
+
* @param {AskQuestionOptionsArgProps} options - An optional object for additional configuration:
|
|
20
|
+
* @return {Promise<SuggestionsEventSource>} A promise that resolves to an instance of the SuggestionsEventSource
|
|
21
21
|
* @example
|
|
22
22
|
* const question = "What is the meaning of life?";
|
|
23
23
|
* const options = {
|
|
@@ -8,9 +8,9 @@ const debug = debugFactory('jetpack-ai-client:ask-question');
|
|
|
8
8
|
* An asynchronous function that asks a question
|
|
9
9
|
* and returns an event source with suggestions.
|
|
10
10
|
*
|
|
11
|
-
* @param {PromptProp}
|
|
12
|
-
* @param {AskQuestionOptionsArgProps} options
|
|
13
|
-
* @
|
|
11
|
+
* @param {PromptProp} question - The question to ask. It can be a simple string or an array of PromptMessageItemProps objects.
|
|
12
|
+
* @param {AskQuestionOptionsArgProps} options - An optional object for additional configuration:
|
|
13
|
+
* @return {Promise<SuggestionsEventSource>} A promise that resolves to an instance of the SuggestionsEventSource
|
|
14
14
|
* @example
|
|
15
15
|
* const question = "What is the meaning of life?";
|
|
16
16
|
* const options = {
|
|
@@ -7,9 +7,9 @@ export type ResponseData = string;
|
|
|
7
7
|
/**
|
|
8
8
|
* A function that asks a question without streaming.
|
|
9
9
|
*
|
|
10
|
-
* @param {PromptProp}
|
|
11
|
-
* @param {AskQuestionOptionsArgProps} options
|
|
12
|
-
* @
|
|
10
|
+
* @param {PromptProp} question - The question to ask. It can be a simple string or an array of PromptMessageItemProps objects.
|
|
11
|
+
* @param {AskQuestionOptionsArgProps} options - An optional object for additional configuration: postId, feature, model.
|
|
12
|
+
* @return {Promise<ResponseData>} - A promise that resolves to an instance of the ResponseData
|
|
13
13
|
* @example
|
|
14
14
|
* const question = "What is the meaning of life?";
|
|
15
15
|
* const options = {
|
|
@@ -10,9 +10,9 @@ const debug = debugFactory('jetpack-ai-client:ask-question-sync');
|
|
|
10
10
|
/**
|
|
11
11
|
* A function that asks a question without streaming.
|
|
12
12
|
*
|
|
13
|
-
* @param {PromptProp}
|
|
14
|
-
* @param {AskQuestionOptionsArgProps} options
|
|
15
|
-
* @
|
|
13
|
+
* @param {PromptProp} question - The question to ask. It can be a simple string or an array of PromptMessageItemProps objects.
|
|
14
|
+
* @param {AskQuestionOptionsArgProps} options - An optional object for additional configuration: postId, feature, model.
|
|
15
|
+
* @return {Promise<ResponseData>} - A promise that resolves to an instance of the ResponseData
|
|
16
16
|
* @example
|
|
17
17
|
* const question = "What is the meaning of life?";
|
|
18
18
|
* const options = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A function that takes an audio blob and transcribes it.
|
|
3
3
|
*
|
|
4
|
-
* @param {Blob}
|
|
5
|
-
* @param {string}
|
|
4
|
+
* @param {Blob} audio - The audio to be transcribed, from a recording or from a file.
|
|
5
|
+
* @param {string} feature - The feature name that is calling the transcription.
|
|
6
6
|
* @param {AbortSignal} requestAbortSignal - The signal to abort the request.
|
|
7
|
-
* @
|
|
7
|
+
* @return {Promise<string>} - The promise of a string containing the transcribed audio.
|
|
8
8
|
*/
|
|
9
9
|
export default function transcribeAudio(audio: Blob, feature?: string, requestAbortSignal?: AbortSignal): Promise<string>;
|
|
@@ -10,10 +10,10 @@ const debug = debugFactory('jetpack-ai-client:audio-transcription');
|
|
|
10
10
|
/**
|
|
11
11
|
* A function that takes an audio blob and transcribes it.
|
|
12
12
|
*
|
|
13
|
-
* @param {Blob}
|
|
14
|
-
* @param {string}
|
|
13
|
+
* @param {Blob} audio - The audio to be transcribed, from a recording or from a file.
|
|
14
|
+
* @param {string} feature - The feature name that is calling the transcription.
|
|
15
15
|
* @param {AbortSignal} requestAbortSignal - The signal to abort the request.
|
|
16
|
-
* @
|
|
16
|
+
* @return {Promise<string>} - The promise of a string containing the transcribed audio.
|
|
17
17
|
*/
|
|
18
18
|
export default async function transcribeAudio(audio, feature, requestAbortSignal) {
|
|
19
19
|
debug('Transcribing audio: %o. Feature: %o', audio, feature);
|
|
@@ -24,7 +24,7 @@ type AIControlProps = {
|
|
|
24
24
|
* Base AIControl component. Contains the main structure of the control component and slots for banner, error, actions and message.
|
|
25
25
|
*
|
|
26
26
|
* @param {AIControlProps} props - Component props
|
|
27
|
-
* @
|
|
27
|
+
* @return {ReactElement} Rendered component
|
|
28
28
|
*/
|
|
29
29
|
export default function AIControl({ className, disabled, value, placeholder, isTransparent, state, onChange, banner, error, actions, message, promptUserInputRef, wrapperRef, }: AIControlProps): ReactElement;
|
|
30
30
|
export {};
|
|
@@ -13,7 +13,7 @@ import './style.scss';
|
|
|
13
13
|
* Base AIControl component. Contains the main structure of the control component and slots for banner, error, actions and message.
|
|
14
14
|
*
|
|
15
15
|
* @param {AIControlProps} props - Component props
|
|
16
|
-
* @
|
|
16
|
+
* @return {ReactElement} Rendered component
|
|
17
17
|
*/
|
|
18
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
19
|
return (_jsxs("div", { className: clsx('jetpack-components-ai-control__container-wrapper', className), ref: wrapperRef, children: [error, _jsxs("div", { className: "jetpack-components-ai-control__container", children: [banner, _jsxs("div", { className: clsx('jetpack-components-ai-control__wrapper', {
|
|
@@ -28,9 +28,9 @@ type BlockAIControlProps = {
|
|
|
28
28
|
/**
|
|
29
29
|
* BlockAIControl component. Used by the AI Assistant block, adding logic and components to the base AIControl component.
|
|
30
30
|
*
|
|
31
|
-
* @param {BlockAIControlProps}
|
|
32
|
-
* @param {React.MutableRefObject} ref
|
|
33
|
-
* @
|
|
31
|
+
* @param {BlockAIControlProps} props - Component props
|
|
32
|
+
* @param {React.MutableRefObject} ref - Ref to the component
|
|
33
|
+
* @return {ReactElement} Rendered component
|
|
34
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
36
|
declare const _default: React.ForwardRefExoticComponent<BlockAIControlProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -19,9 +19,9 @@ const debug = debugFactory('jetpack-ai-client:block-ai-control');
|
|
|
19
19
|
/**
|
|
20
20
|
* BlockAIControl component. Used by the AI Assistant block, adding logic and components to the base AIControl component.
|
|
21
21
|
*
|
|
22
|
-
* @param {BlockAIControlProps}
|
|
23
|
-
* @param {React.MutableRefObject} ref
|
|
24
|
-
* @
|
|
22
|
+
* @param {BlockAIControlProps} props - Component props
|
|
23
|
+
* @param {React.MutableRefObject} ref - Ref to the component
|
|
24
|
+
* @return {ReactElement} Rendered component
|
|
25
25
|
*/
|
|
26
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) {
|
|
27
27
|
const loading = state === 'requesting' || state === 'suggesting';
|
|
@@ -30,9 +30,9 @@ type ExtensionAIControlProps = {
|
|
|
30
30
|
/**
|
|
31
31
|
* ExtensionAIControl component. Used by the AI Assistant inline extensions, adding logic and components to the base AIControl component.
|
|
32
32
|
*
|
|
33
|
-
* @param {ExtensionAIControlProps} props
|
|
34
|
-
* @param {React.MutableRefObject}
|
|
35
|
-
* @
|
|
33
|
+
* @param {ExtensionAIControlProps} props - Component props
|
|
34
|
+
* @param {React.MutableRefObject} ref - Ref to the component
|
|
35
|
+
* @return {ReactElement} Rendered component
|
|
36
36
|
*/
|
|
37
37
|
export declare function ExtensionAIControl({ className, disabled, value, placeholder, showButtonLabels, isTransparent, state, showGuideLine, error, requestsRemaining, showUpgradeMessage, upgradeUrl, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, onTryAgain, }: ExtensionAIControlProps, ref: React.MutableRefObject<HTMLInputElement>): ReactElement;
|
|
38
38
|
declare const _default: React.ForwardRefExoticComponent<ExtensionAIControlProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -17,9 +17,9 @@ import './style.scss';
|
|
|
17
17
|
/**
|
|
18
18
|
* ExtensionAIControl component. Used by the AI Assistant inline extensions, adding logic and components to the base AIControl component.
|
|
19
19
|
*
|
|
20
|
-
* @param {ExtensionAIControlProps} props
|
|
21
|
-
* @param {React.MutableRefObject}
|
|
22
|
-
* @
|
|
20
|
+
* @param {ExtensionAIControlProps} props - Component props
|
|
21
|
+
* @param {React.MutableRefObject} ref - Ref to the component
|
|
22
|
+
* @return {ReactElement} Rendered component
|
|
23
23
|
*/
|
|
24
24
|
export function ExtensionAIControl({ className, disabled = false, value = '', placeholder = '', showButtonLabels = true, isTransparent = false, state = 'init', showGuideLine = false, error, requestsRemaining, showUpgradeMessage = false, upgradeUrl, wrapperRef, onChange, onSend, onStop, onClose, onUndo, onUpgrade, onTryAgain, }, ref) {
|
|
25
25
|
const loading = state === 'requesting' || state === 'suggesting';
|
|
@@ -10,6 +10,6 @@ export type AiStatusIndicatorProps = {
|
|
|
10
10
|
* AiStatusIndicator component.
|
|
11
11
|
*
|
|
12
12
|
* @param {AiStatusIndicatorProps} props - component props.
|
|
13
|
-
* @
|
|
13
|
+
* @return {React.ReactElement} - rendered component.
|
|
14
14
|
*/
|
|
15
15
|
export default function AiStatusIndicator({ state }: AiStatusIndicatorProps): React.ReactElement;
|
|
@@ -9,7 +9,7 @@ import './style.scss';
|
|
|
9
9
|
* AiStatusIndicator component.
|
|
10
10
|
*
|
|
11
11
|
* @param {AiStatusIndicatorProps} props - component props.
|
|
12
|
-
* @
|
|
12
|
+
* @return {React.ReactElement} - rendered component.
|
|
13
13
|
*/
|
|
14
14
|
export default function AiStatusIndicator({ state }) {
|
|
15
15
|
return (_jsx("div", { className: clsx('jetpack-ai-status-indicator__icon-wrapper', {
|
|
@@ -7,7 +7,7 @@ type AudioDurationDisplayProps = {
|
|
|
7
7
|
* AudioDurationDisplay component.
|
|
8
8
|
*
|
|
9
9
|
* @param {AudioDurationDisplayProps} props - Component props.
|
|
10
|
-
* @
|
|
10
|
+
* @return {React.ReactElement} Rendered component.
|
|
11
11
|
*/
|
|
12
12
|
export default function AudioDurationDisplay({ duration, className, }: AudioDurationDisplayProps): React.ReactElement;
|
|
13
13
|
export {};
|
|
@@ -7,7 +7,7 @@ import { formatTime } from './lib/media.js';
|
|
|
7
7
|
* AudioDurationDisplay component.
|
|
8
8
|
*
|
|
9
9
|
* @param {AudioDurationDisplayProps} props - Component props.
|
|
10
|
-
* @
|
|
10
|
+
* @return {React.ReactElement} Rendered component.
|
|
11
11
|
*/
|
|
12
12
|
export default function AudioDurationDisplay({ duration, className, }) {
|
|
13
13
|
return _jsx("span", { className: className, children: formatTime(duration, { addDecimalPart: false }) });
|
|
@@ -16,9 +16,9 @@ type FormatTimeOptions = {
|
|
|
16
16
|
* Formats the given time in milliseconds into a string with the format HH:MM:SS.DD,
|
|
17
17
|
* adding hours and minutes only when needed.
|
|
18
18
|
*
|
|
19
|
-
* @param {number}
|
|
19
|
+
* @param {number} time - The time in milliseconds to format.
|
|
20
20
|
* @param {FormatTimeOptions} options - The arguments.
|
|
21
|
-
* @
|
|
21
|
+
* @return {string} The formatted time string.
|
|
22
22
|
* @example
|
|
23
23
|
* const formattedTime1 = formatTime( 1234567, { addDecimalPart: true } ); // Returns "20:34.56"
|
|
24
24
|
* const formattedTime2 = formatTime( 45123 ); // Returns "00.45"
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Formats the given time in milliseconds into a string with the format HH:MM:SS.DD,
|
|
3
3
|
* adding hours and minutes only when needed.
|
|
4
4
|
*
|
|
5
|
-
* @param {number}
|
|
5
|
+
* @param {number} time - The time in milliseconds to format.
|
|
6
6
|
* @param {FormatTimeOptions} options - The arguments.
|
|
7
|
-
* @
|
|
7
|
+
* @return {string} The formatted time string.
|
|
8
8
|
* @example
|
|
9
9
|
* const formattedTime1 = formatTime( 1234567, { addDecimalPart: true } ); // Returns "20:34.56"
|
|
10
10
|
* const formattedTime2 = formatTime( 45123 ); // Returns "00.45"
|
|
@@ -38,27 +38,27 @@ export type ErrorMessageProps = {
|
|
|
38
38
|
* React component to render a block message.
|
|
39
39
|
*
|
|
40
40
|
* @param {MessageProps} props - Component props.
|
|
41
|
-
* @
|
|
41
|
+
* @return {React.ReactElement } Banner component.
|
|
42
42
|
*/
|
|
43
43
|
export default function Message({ severity, icon, showSidebarIcon, onSidebarIconClick, children, }: MessageProps): React.ReactElement;
|
|
44
44
|
/**
|
|
45
45
|
* React component to render a guideline message.
|
|
46
46
|
*
|
|
47
|
-
* @
|
|
47
|
+
* @return {React.ReactElement } - Message component.
|
|
48
48
|
*/
|
|
49
49
|
export declare function GuidelineMessage(): React.ReactElement;
|
|
50
50
|
/**
|
|
51
51
|
* React component to render an upgrade message for free tier users
|
|
52
52
|
*
|
|
53
53
|
* @param {number} requestsRemaining - Number of requests remaining.
|
|
54
|
-
* @
|
|
54
|
+
* @return {React.ReactElement } - Message component.
|
|
55
55
|
*/
|
|
56
56
|
export declare function UpgradeMessage({ requestsRemaining, severity, onUpgradeClick, upgradeUrl, }: UpgradeMessageProps): React.ReactElement;
|
|
57
57
|
/**
|
|
58
58
|
* React component to render an error message
|
|
59
59
|
*
|
|
60
60
|
* @param {number} requestsRemaining - Number of requests remaining.
|
|
61
|
-
* @
|
|
61
|
+
* @return {React.ReactElement } - Message component.
|
|
62
62
|
*/
|
|
63
63
|
export declare function ErrorMessage({ error, code, onTryAgainClick, onUpgradeClick, upgradeUrl, }: ErrorMessageProps): React.ReactElement;
|
|
64
64
|
export {};
|
|
@@ -32,7 +32,7 @@ const messageIconsMap = {
|
|
|
32
32
|
* React component to render a block message.
|
|
33
33
|
*
|
|
34
34
|
* @param {MessageProps} props - Component props.
|
|
35
|
-
* @
|
|
35
|
+
* @return {React.ReactElement } Banner component.
|
|
36
36
|
*/
|
|
37
37
|
export default function Message({ severity = MESSAGE_SEVERITY_INFO, icon = null, showSidebarIcon = false, onSidebarIconClick = () => { }, children, }) {
|
|
38
38
|
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 }) }))] }));
|
|
@@ -40,7 +40,7 @@ export default function Message({ severity = MESSAGE_SEVERITY_INFO, icon = null,
|
|
|
40
40
|
/**
|
|
41
41
|
* React component to render a guideline message.
|
|
42
42
|
*
|
|
43
|
-
* @
|
|
43
|
+
* @return {React.ReactElement } - Message component.
|
|
44
44
|
*/
|
|
45
45
|
export function GuidelineMessage() {
|
|
46
46
|
return (_jsxs(Message, { children: [_jsx("span", { children: __('AI-generated content could be inaccurate or biased.', 'jetpack-ai-client') }), _jsx(ExternalLink, { href: "https://automattic.com/ai-guidelines", children: __('Learn more', 'jetpack-ai-client') })] }));
|
|
@@ -49,7 +49,7 @@ export function GuidelineMessage() {
|
|
|
49
49
|
* React component to render an upgrade message for free tier users
|
|
50
50
|
*
|
|
51
51
|
* @param {number} requestsRemaining - Number of requests remaining.
|
|
52
|
-
* @
|
|
52
|
+
* @return {React.ReactElement } - Message component.
|
|
53
53
|
*/
|
|
54
54
|
export function UpgradeMessage({ requestsRemaining, severity, onUpgradeClick, upgradeUrl, }) {
|
|
55
55
|
let messageSeverity = severity;
|
|
@@ -64,7 +64,7 @@ export function UpgradeMessage({ requestsRemaining, severity, onUpgradeClick, up
|
|
|
64
64
|
* React component to render an error message
|
|
65
65
|
*
|
|
66
66
|
* @param {number} requestsRemaining - Number of requests remaining.
|
|
67
|
-
* @
|
|
67
|
+
* @return {React.ReactElement } - Message component.
|
|
68
68
|
*/
|
|
69
69
|
export function ErrorMessage({ error, code, onTryAgainClick, onUpgradeClick, upgradeUrl, }) {
|
|
70
70
|
const errorMessage = error || __('Something went wrong', 'jetpack-ai-client');
|
|
@@ -25,14 +25,14 @@ type AiDataContextProviderProps = {
|
|
|
25
25
|
/**
|
|
26
26
|
* AI Data Context
|
|
27
27
|
*
|
|
28
|
-
* @
|
|
28
|
+
* @return {AiDataContextProps} Context.
|
|
29
29
|
*/
|
|
30
30
|
export declare const AiDataContext: React.Context<object | AiDataContextProps>;
|
|
31
31
|
/**
|
|
32
32
|
* AI Data Context Provider
|
|
33
33
|
*
|
|
34
34
|
* @param {AiDataContextProviderProps} props - Component props.
|
|
35
|
-
* @
|
|
35
|
+
* @return {React.ReactElement} Context provider.
|
|
36
36
|
* @example
|
|
37
37
|
* <AiDataContextProvider value={ value }>
|
|
38
38
|
* { children }
|
|
@@ -6,14 +6,14 @@ import { createContext } from 'react';
|
|
|
6
6
|
/**
|
|
7
7
|
* AI Data Context
|
|
8
8
|
*
|
|
9
|
-
* @
|
|
9
|
+
* @return {AiDataContextProps} Context.
|
|
10
10
|
*/
|
|
11
11
|
export const AiDataContext = createContext({});
|
|
12
12
|
/**
|
|
13
13
|
* AI Data Context Provider
|
|
14
14
|
*
|
|
15
15
|
* @param {AiDataContextProviderProps} props - Component props.
|
|
16
|
-
* @
|
|
16
|
+
* @return {React.ReactElement} Context provider.
|
|
17
17
|
* @example
|
|
18
18
|
* <AiDataContextProvider value={ value }>
|
|
19
19
|
* { children }
|
|
@@ -19,6 +19,6 @@ export type UseAiContextOptions = {
|
|
|
19
19
|
* and to subscribe to the request events (onDone, onSuggestion).
|
|
20
20
|
*
|
|
21
21
|
* @param {UseAiContextOptions} options - the hook options.
|
|
22
|
-
* @
|
|
22
|
+
* @return {AiDataContextProps} the AI Assistant data context.
|
|
23
23
|
*/
|
|
24
24
|
export default function useAiContext({ onDone, onSuggestion, onError, }?: UseAiContextOptions): AiDataContextProps;
|
|
@@ -13,7 +13,7 @@ import { AiDataContext } from './index.js';
|
|
|
13
13
|
* and to subscribe to the request events (onDone, onSuggestion).
|
|
14
14
|
*
|
|
15
15
|
* @param {UseAiContextOptions} options - the hook options.
|
|
16
|
-
* @
|
|
16
|
+
* @return {AiDataContextProps} the AI Assistant data context.
|
|
17
17
|
*/
|
|
18
18
|
export default function useAiContext({ onDone, onSuggestion, onError, } = {}) {
|
|
19
19
|
const context = useContext(AiDataContext);
|
|
@@ -4,7 +4,7 @@ import React from 'react';
|
|
|
4
4
|
* AI Assistant Data context to the wrapped component.
|
|
5
5
|
*
|
|
6
6
|
* @param {React.ReactElement} WrappedComponent - component to wrap.
|
|
7
|
-
* @
|
|
7
|
+
* @return {React.ReactElement} Wrapped component, with the AI Assistant Data context.
|
|
8
8
|
*/
|
|
9
9
|
declare const withAiDataProvider: (Inner: React.ComponentType<{}>) => (props: any) => import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
export default withAiDataProvider;
|
|
@@ -14,7 +14,7 @@ import { AiDataContextProvider } from './index.js';
|
|
|
14
14
|
* AI Assistant Data context to the wrapped component.
|
|
15
15
|
*
|
|
16
16
|
* @param {React.ReactElement} WrappedComponent - component to wrap.
|
|
17
|
-
* @
|
|
17
|
+
* @return {React.ReactElement} Wrapped component, with the AI Assistant Data context.
|
|
18
18
|
*/
|
|
19
19
|
const withAiDataProvider = createHigherOrderComponent((WrappedComponent) => {
|
|
20
20
|
return props => {
|
|
@@ -38,14 +38,14 @@ type useAiSuggestionsProps = {
|
|
|
38
38
|
* Get the error data for a given error code.
|
|
39
39
|
*
|
|
40
40
|
* @param {SuggestionErrorCode} errorCode - The error code.
|
|
41
|
-
* @
|
|
41
|
+
* @return {RequestingErrorProps} The error data.
|
|
42
42
|
*/
|
|
43
43
|
export declare function getErrorData(errorCode: SuggestionErrorCode): RequestingErrorProps;
|
|
44
44
|
/**
|
|
45
45
|
* Remove the llama artifact from a suggestion.
|
|
46
46
|
*
|
|
47
47
|
* @param {string} suggestion - The suggestion.
|
|
48
|
-
* @
|
|
48
|
+
* @return {string} The suggestion without the llama artifact.
|
|
49
49
|
*/
|
|
50
50
|
export declare function removeLlamaArtifact(suggestion: string): string;
|
|
51
51
|
/**
|
|
@@ -53,7 +53,7 @@ export declare function removeLlamaArtifact(suggestion: string): string;
|
|
|
53
53
|
* by hitting the query endpoint.
|
|
54
54
|
*
|
|
55
55
|
* @param {useAiSuggestionsOptions} options - The options for the hook.
|
|
56
|
-
* @
|
|
56
|
+
* @return {useAiSuggestionsProps} The props for the hook.
|
|
57
57
|
*/
|
|
58
58
|
export default function useAiSuggestions({ prompt, autoRequest, askQuestionOptions, initialRequestingState, onSuggestion, onDone, onStop, onError, onAllErrors, }?: useAiSuggestionsOptions): useAiSuggestionsProps;
|
|
59
59
|
export {};
|
|
@@ -12,7 +12,7 @@ import { ERROR_CONTEXT_TOO_LARGE, ERROR_MODERATION, ERROR_NETWORK, ERROR_QUOTA_E
|
|
|
12
12
|
* Get the error data for a given error code.
|
|
13
13
|
*
|
|
14
14
|
* @param {SuggestionErrorCode} errorCode - The error code.
|
|
15
|
-
* @
|
|
15
|
+
* @return {RequestingErrorProps} The error data.
|
|
16
16
|
*/
|
|
17
17
|
export function getErrorData(errorCode) {
|
|
18
18
|
switch (errorCode) {
|
|
@@ -59,7 +59,7 @@ export function getErrorData(errorCode) {
|
|
|
59
59
|
* Remove the llama artifact from a suggestion.
|
|
60
60
|
*
|
|
61
61
|
* @param {string} suggestion - The suggestion.
|
|
62
|
-
* @
|
|
62
|
+
* @return {string} The suggestion without the llama artifact.
|
|
63
63
|
*/
|
|
64
64
|
export function removeLlamaArtifact(suggestion) {
|
|
65
65
|
return suggestion.replace(/^<\|start_header_id\|>assistant<\|end_header_id\|>[\n]+/, '');
|
|
@@ -69,7 +69,7 @@ export function removeLlamaArtifact(suggestion) {
|
|
|
69
69
|
* by hitting the query endpoint.
|
|
70
70
|
*
|
|
71
71
|
* @param {useAiSuggestionsOptions} options - The options for the hook.
|
|
72
|
-
* @
|
|
72
|
+
* @return {useAiSuggestionsProps} The props for the hook.
|
|
73
73
|
*/
|
|
74
74
|
export default function useAiSuggestions({ prompt, autoRequest = false, askQuestionOptions = {}, initialRequestingState = 'init', onSuggestion, onDone, onStop, onError, onAllErrors, } = {}) {
|
|
75
75
|
const [requestingState, setRequestingState] = useState(initialRequestingState);
|
|
@@ -81,7 +81,7 @@ export default function useAiSuggestions({ prompt, autoRequest = false, askQuest
|
|
|
81
81
|
* onSuggestion function handler.
|
|
82
82
|
*
|
|
83
83
|
* @param {string} suggestion - The suggestion.
|
|
84
|
-
* @
|
|
84
|
+
* @return {void}
|
|
85
85
|
*/
|
|
86
86
|
const handleSuggestion = useCallback((event) => {
|
|
87
87
|
const partialSuggestion = removeLlamaArtifact(event?.detail);
|
|
@@ -95,7 +95,7 @@ export default function useAiSuggestions({ prompt, autoRequest = false, askQuest
|
|
|
95
95
|
* onDone function handler.
|
|
96
96
|
*
|
|
97
97
|
* @param {string} content - The content.
|
|
98
|
-
* @
|
|
98
|
+
* @return {void}
|
|
99
99
|
*/
|
|
100
100
|
const handleDone = useCallback((event) => {
|
|
101
101
|
closeEventSource();
|
|
@@ -120,9 +120,9 @@ export default function useAiSuggestions({ prompt, autoRequest = false, askQuest
|
|
|
120
120
|
/**
|
|
121
121
|
* Request handler.
|
|
122
122
|
*
|
|
123
|
-
* @param {PromptProp}
|
|
124
|
-
* @param {AskQuestionOptionsArgProps} options
|
|
125
|
-
* @
|
|
123
|
+
* @param {PromptProp} promptArg - The messages array of the prompt.
|
|
124
|
+
* @param {AskQuestionOptionsArgProps} options - The options for the askQuestion request. Uses the hook's askQuestionOptions by default.
|
|
125
|
+
* @return {Promise<void>} The promise.
|
|
126
126
|
*/
|
|
127
127
|
const request = useCallback(async (promptArg, options = { ...askQuestionOptions }) => {
|
|
128
128
|
// Clear any error.
|
|
@@ -157,7 +157,7 @@ export default function useAiSuggestions({ prompt, autoRequest = false, askQuest
|
|
|
157
157
|
/**
|
|
158
158
|
* Reset the request state.
|
|
159
159
|
*
|
|
160
|
-
* @
|
|
160
|
+
* @return {void}
|
|
161
161
|
*/
|
|
162
162
|
const reset = useCallback(() => {
|
|
163
163
|
setRequestingState('init');
|
|
@@ -167,7 +167,7 @@ export default function useAiSuggestions({ prompt, autoRequest = false, askQuest
|
|
|
167
167
|
/**
|
|
168
168
|
* Close the event source connection.
|
|
169
169
|
*
|
|
170
|
-
* @
|
|
170
|
+
* @return {void}
|
|
171
171
|
*/
|
|
172
172
|
const closeEventSource = useCallback(() => {
|
|
173
173
|
if (!eventSourceRef?.current) {
|
|
@@ -198,7 +198,7 @@ export default function useAiSuggestions({ prompt, autoRequest = false, askQuest
|
|
|
198
198
|
/**
|
|
199
199
|
* Stop suggestion handler.
|
|
200
200
|
*
|
|
201
|
-
* @
|
|
201
|
+
* @return {void}
|
|
202
202
|
*/
|
|
203
203
|
const stopSuggestion = useCallback(() => {
|
|
204
204
|
closeEventSource();
|
|
@@ -20,6 +20,6 @@ export type UseAudioTranscriptionProps = {
|
|
|
20
20
|
* A hook to handle audio transcription.
|
|
21
21
|
*
|
|
22
22
|
* @param {string} feature - The feature name that is calling the transcription.
|
|
23
|
-
* @
|
|
23
|
+
* @return {UseAudioTranscriptionReturn} - Object with properties to get the transcription data.
|
|
24
24
|
*/
|
|
25
25
|
export default function useAudioTranscription({ feature, onReady, onError, }: UseAudioTranscriptionProps): UseAudioTranscriptionReturn;
|
|
@@ -12,7 +12,7 @@ const debug = debugFactory('jetpack-ai-client:use-audio-transcription');
|
|
|
12
12
|
/**
|
|
13
13
|
* Map error response to a string.
|
|
14
14
|
* @param {Error | string | AudioTranscriptionErrorResponse} error - The error response from the audio transcription service.
|
|
15
|
-
* @
|
|
15
|
+
* @return {string} the translated error message
|
|
16
16
|
*/
|
|
17
17
|
const mapErrorResponse = (error) => {
|
|
18
18
|
if (typeof error === 'string') {
|
|
@@ -45,7 +45,7 @@ const mapErrorResponse = (error) => {
|
|
|
45
45
|
* A hook to handle audio transcription.
|
|
46
46
|
*
|
|
47
47
|
* @param {string} feature - The feature name that is calling the transcription.
|
|
48
|
-
* @
|
|
48
|
+
* @return {UseAudioTranscriptionReturn} - Object with properties to get the transcription data.
|
|
49
49
|
*/
|
|
50
50
|
export default function useAudioTranscription({ feature, onReady, onError, }) {
|
|
51
51
|
const [transcriptionResult, setTranscriptionResult] = useState('');
|
|
@@ -16,6 +16,6 @@ export type ValidatedAudioInformation = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Hook to handle the validation of an audio file.
|
|
18
18
|
*
|
|
19
|
-
* @
|
|
19
|
+
* @return {UseAudioValidationReturn} - Object with the audio validation state and the function to validate the audio.
|
|
20
20
|
*/
|
|
21
21
|
export default function useAudioValidation(): UseAudioValidationReturn;
|
|
@@ -22,7 +22,7 @@ const ALLOWED_MEDIA_TYPES = [
|
|
|
22
22
|
/**
|
|
23
23
|
* Hook to handle the validation of an audio file.
|
|
24
24
|
*
|
|
25
|
-
* @
|
|
25
|
+
* @return {UseAudioValidationReturn} - Object with the audio validation state and the function to validate the audio.
|
|
26
26
|
*/
|
|
27
27
|
export default function useAudioValidation() {
|
|
28
28
|
const [isValidatingAudio, setIsValidatingAudio] = useState(false);
|
|
@@ -10,9 +10,9 @@ import requestJwt from '../../jwt/index.js';
|
|
|
10
10
|
const debug = debugFactory('ai-client:use-image-generator');
|
|
11
11
|
/**
|
|
12
12
|
* Cut the post content on a given lenght so the total length of the prompt is not longer than 4000 characters.
|
|
13
|
-
* @param {string} content
|
|
13
|
+
* @param {string} content - the content to be truncated
|
|
14
14
|
* @param {number} currentPromptLength - the length of the prompt already in use
|
|
15
|
-
* @
|
|
15
|
+
* @return {string} a truncated version of the content respecting the prompt length limit
|
|
16
16
|
*/
|
|
17
17
|
const truncateContent = (content, currentPromptLength) => {
|
|
18
18
|
const maxLength = 4000;
|
|
@@ -25,8 +25,8 @@ const truncateContent = (content, currentPromptLength) => {
|
|
|
25
25
|
/**
|
|
26
26
|
* Create the prompt string based on the provided context.
|
|
27
27
|
* @param {string} postContent - the content of the post
|
|
28
|
-
* @param {string} userPrompt
|
|
29
|
-
* @
|
|
28
|
+
* @param {string} userPrompt - the user prompt for the image generation, if provided. Max length is 1000 characters, will be truncated.
|
|
29
|
+
* @return {string} the prompt string
|
|
30
30
|
*/
|
|
31
31
|
const getDalleImageGenerationPrompt = (postContent, userPrompt) => {
|
|
32
32
|
/**
|
|
@@ -77,8 +77,8 @@ This is the post content:
|
|
|
77
77
|
/**
|
|
78
78
|
* Create the Stable Diffusion pre-processing prompt based on the provided context.
|
|
79
79
|
* @param {string} postContent - the content of the post.
|
|
80
|
-
* @param {string} userPrompt
|
|
81
|
-
* @
|
|
80
|
+
* @param {string} userPrompt - the user prompt for the image generation, if provided. Max length is 1000 characters, will be truncated.
|
|
81
|
+
* @return {string} the prompt string to be fed to the AI Assistant model.
|
|
82
82
|
*/
|
|
83
83
|
const getStableDiffusionPreProcessingPrompt = (postContent, userPrompt) => {
|
|
84
84
|
/**
|
|
@@ -116,9 +116,9 @@ Return just the prompt, without comments. The content is:
|
|
|
116
116
|
/**
|
|
117
117
|
* Uses the Jetpack AI query endpoint to produce a prompt for the stable diffusion model.
|
|
118
118
|
* @param {string} postContent - the content of the post.
|
|
119
|
-
* @param {string} userPrompt
|
|
120
|
-
* @param {string} feature
|
|
121
|
-
* @
|
|
119
|
+
* @param {string} userPrompt - the user prompt for the image generation, if provided. Max length is 1000 characters, will be truncated
|
|
120
|
+
* @param {string} feature - the feature to be used for the image generation.
|
|
121
|
+
* @return {string} the prompt string to be used on stable diffusion image generation.
|
|
122
122
|
*/
|
|
123
123
|
const getStableDiffusionImageGenerationPrompt = async (postContent, userPrompt, feature) => {
|
|
124
124
|
const prompt = getStableDiffusionPreProcessingPrompt(postContent, userPrompt);
|
|
@@ -54,7 +54,7 @@ type UseMediaRecordingReturn = {
|
|
|
54
54
|
* react custom hook to handle media recording.
|
|
55
55
|
*
|
|
56
56
|
* @param {UseMediaRecordingProps} props - The props
|
|
57
|
-
* @
|
|
57
|
+
* @return {UseMediaRecordingReturn} The media recorder instance
|
|
58
58
|
*/
|
|
59
59
|
export default function useMediaRecording({ onDone, }?: UseMediaRecordingProps): UseMediaRecordingReturn;
|
|
60
60
|
export {};
|