@automattic/jetpack-ai-client 0.32.1 → 0.33.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 +11 -0
- package/build/api-fetch/index.d.ts +9 -1
- package/build/chrome-ai/get-availability.js +35 -3
- package/build/components/ai-control/ai-control.d.ts +2 -3
- package/build/components/ai-control/block-ai-control.d.ts +5 -6
- package/build/components/ai-control/block-ai-control.js +2 -2
- package/build/components/ai-control/extension-ai-control.d.ts +5 -6
- package/build/components/ai-control/extension-ai-control.js +1 -1
- package/build/components/ai-feedback/index.d.ts +3 -3
- package/build/components/ai-feedback/index.js +1 -1
- package/build/components/ai-icon/index.d.ts +1 -1
- package/build/components/ai-icon/index.js +1 -4
- package/build/components/ai-image/components/ai-image-modal.d.ts +3 -5
- package/build/components/ai-image/components/ai-image-modal.js +1 -7
- package/build/components/ai-image/components/carrousel.d.ts +3 -2
- package/build/components/ai-image/components/carrousel.js +2 -8
- package/build/components/ai-image/components/usage-counter.d.ts +1 -4
- package/build/components/ai-image/components/usage-counter.js +1 -7
- package/build/components/ai-image/featured-image.d.ts +1 -4
- package/build/components/ai-image/featured-image.js +1 -7
- package/build/components/ai-image/general-purpose-image.d.ts +1 -4
- package/build/components/ai-image/general-purpose-image.js +1 -7
- package/build/components/ai-image/hooks/use-ai-image.d.ts +2 -3
- package/build/components/ai-modal-footer/index.d.ts +3 -3
- package/build/components/ai-modal-footer/index.js +1 -1
- package/build/components/ai-status-indicator/index.d.ts +3 -3
- package/build/components/ai-status-indicator/index.js +1 -1
- package/build/components/audio-duration-display/index.d.ts +3 -3
- package/build/components/audio-duration-display/index.js +1 -1
- package/build/components/message/index.d.ts +14 -14
- package/build/components/message/index.js +6 -6
- package/build/components/modal/index.d.ts +3 -2
- package/build/components/modal/index.js +1 -7
- package/build/data-flow/context.d.ts +5 -8
- package/build/data-flow/context.js +1 -1
- package/build/data-flow/with-ai-assistant-data.d.ts +4 -4
- package/build/data-flow/with-ai-assistant-data.js +2 -2
- package/build/jwt/index.js +4 -4
- package/build/logo-generator/components/feature-fetch-failure-screen.d.ts +2 -2
- package/build/logo-generator/components/first-load-screen.d.ts +2 -2
- package/build/logo-generator/components/generator-modal.d.ts +2 -2
- package/build/logo-generator/components/history-carousel.d.ts +2 -2
- package/build/logo-generator/components/image-loader.d.ts +2 -2
- package/build/logo-generator/components/logo-presenter.d.ts +2 -2
- package/build/logo-generator/components/logo-presenter.js +1 -1
- package/build/logo-generator/components/upgrade-screen.d.ts +2 -2
- package/build/logo-generator/components/visit-site-banner.d.ts +2 -2
- package/package.json +19 -19
- package/src/api-fetch/index.ts +11 -1
- package/src/chrome-ai/get-availability.ts +50 -5
- package/src/components/ai-control/ai-control.tsx +2 -3
- package/src/components/ai-control/block-ai-control.tsx +5 -5
- package/src/components/ai-control/extension-ai-control.tsx +5 -5
- package/src/components/ai-feedback/index.tsx +3 -3
- package/src/components/ai-icon/index.tsx +2 -4
- package/src/components/ai-image/components/ai-image-modal.tsx +3 -8
- package/src/components/ai-image/components/carrousel.tsx +5 -10
- package/src/components/ai-image/components/usage-counter.tsx +2 -7
- package/src/components/ai-image/featured-image.tsx +2 -7
- package/src/components/ai-image/general-purpose-image.tsx +2 -7
- package/src/components/ai-image/hooks/use-ai-image.ts +2 -2
- package/src/components/ai-modal-footer/index.tsx +3 -3
- package/src/components/ai-status-indicator/index.tsx +3 -3
- package/src/components/audio-duration-display/index.tsx +3 -3
- package/src/components/message/index.tsx +16 -16
- package/src/components/modal/index.tsx +3 -8
- package/src/data-flow/Readme.md +2 -2
- package/src/data-flow/context.tsx +5 -4
- package/src/data-flow/with-ai-assistant-data.tsx +38 -41
- package/src/icons/ai-assistant.tsx +0 -1
- package/src/icons/mic.tsx +0 -1
- package/src/icons/origami-plane.tsx +0 -1
- package/src/icons/player-pause.tsx +0 -1
- package/src/icons/player-play.tsx +0 -1
- package/src/icons/player-stop.tsx +0 -1
- package/src/icons/speak-tone.tsx +0 -1
- package/src/jwt/index.ts +4 -4
- package/src/logo-generator/components/feature-fetch-failure-screen.tsx +2 -2
- package/src/logo-generator/components/first-load-screen.tsx +2 -2
- package/src/logo-generator/components/generator-modal.tsx +3 -3
- package/src/logo-generator/components/history-carousel.tsx +2 -2
- package/src/logo-generator/components/image-loader.tsx +2 -2
- package/src/logo-generator/components/logo-presenter.tsx +11 -13
- package/src/logo-generator/components/prompt.tsx +4 -3
- package/src/logo-generator/components/upgrade-screen.tsx +2 -2
- package/src/logo-generator/components/visit-site-banner.tsx +2 -2
- package/src/logo-generator/lib/wpcom-limited-request.ts +2 -2
|
@@ -6,7 +6,7 @@ import './style.scss';
|
|
|
6
6
|
* Types
|
|
7
7
|
*/
|
|
8
8
|
import type { SuggestionErrorCode } from '../../types.ts';
|
|
9
|
-
import type
|
|
9
|
+
import type { MouseEvent, ReactElement, ReactNode } from 'react';
|
|
10
10
|
export declare const MESSAGE_SEVERITY_WARNING = "warning";
|
|
11
11
|
export declare const MESSAGE_SEVERITY_ERROR = "error";
|
|
12
12
|
export declare const MESSAGE_SEVERITY_SUCCESS = "success";
|
|
@@ -20,15 +20,15 @@ type AiFeedbackThumbsOptions = {
|
|
|
20
20
|
onRate?: (rating: string) => void;
|
|
21
21
|
};
|
|
22
22
|
export type MessageProps = {
|
|
23
|
-
icon?:
|
|
23
|
+
icon?: ReactNode;
|
|
24
24
|
severity?: MessageSeverityProp;
|
|
25
25
|
aiFeedbackThumbsOptions?: AiFeedbackThumbsOptions;
|
|
26
|
-
children:
|
|
26
|
+
children: ReactNode;
|
|
27
27
|
};
|
|
28
28
|
export type GuidelineMessageProps = {
|
|
29
29
|
aiFeedbackThumbsOptions?: AiFeedbackThumbsOptions;
|
|
30
30
|
};
|
|
31
|
-
export type OnUpgradeClick = (event?:
|
|
31
|
+
export type OnUpgradeClick = (event?: MouseEvent<HTMLButtonElement>) => void;
|
|
32
32
|
export type UpgradeMessageProps = {
|
|
33
33
|
requestsRemaining: number;
|
|
34
34
|
severity?: MessageSeverityProp;
|
|
@@ -46,34 +46,34 @@ export type ErrorMessageProps = {
|
|
|
46
46
|
* React component to render a block message.
|
|
47
47
|
*
|
|
48
48
|
* @param {MessageProps} props - Component props.
|
|
49
|
-
* @return {
|
|
49
|
+
* @return {ReactElement} Banner component.
|
|
50
50
|
*/
|
|
51
|
-
export default function Message({ severity, icon, aiFeedbackThumbsOptions, children, }: MessageProps):
|
|
51
|
+
export default function Message({ severity, icon, aiFeedbackThumbsOptions, children, }: MessageProps): ReactElement;
|
|
52
52
|
/**
|
|
53
53
|
* React component to render a guideline message.
|
|
54
54
|
*
|
|
55
55
|
* @param {GuidelineMessageProps} props - Component props.
|
|
56
|
-
* @return {
|
|
56
|
+
* @return {ReactElement} - Message component.
|
|
57
57
|
*/
|
|
58
|
-
export declare function GuidelineMessage({ aiFeedbackThumbsOptions, }: GuidelineMessageProps):
|
|
58
|
+
export declare function GuidelineMessage({ aiFeedbackThumbsOptions, }: GuidelineMessageProps): ReactElement;
|
|
59
59
|
/**
|
|
60
60
|
* React component to render a fair usage limit message.
|
|
61
61
|
*
|
|
62
|
-
* @return {
|
|
62
|
+
* @return {ReactElement} - Message component.
|
|
63
63
|
*/
|
|
64
|
-
export declare function FairUsageLimitMessage():
|
|
64
|
+
export declare function FairUsageLimitMessage(): ReactElement;
|
|
65
65
|
/**
|
|
66
66
|
* React component to render an upgrade message for free tier users
|
|
67
67
|
*
|
|
68
68
|
* @param {number} requestsRemaining - Number of requests remaining.
|
|
69
|
-
* @return {
|
|
69
|
+
* @return {ReactElement} - Message component.
|
|
70
70
|
*/
|
|
71
|
-
export declare function UpgradeMessage({ requestsRemaining, severity, onUpgradeClick, upgradeUrl, }: UpgradeMessageProps):
|
|
71
|
+
export declare function UpgradeMessage({ requestsRemaining, severity, onUpgradeClick, upgradeUrl, }: UpgradeMessageProps): ReactElement;
|
|
72
72
|
/**
|
|
73
73
|
* React component to render an error message
|
|
74
74
|
*
|
|
75
75
|
* @param {number} requestsRemaining - Number of requests remaining.
|
|
76
|
-
* @return {
|
|
76
|
+
* @return {ReactElement} - Message component.
|
|
77
77
|
*/
|
|
78
|
-
export declare function ErrorMessage({ error, code, onTryAgainClick, onUpgradeClick, upgradeUrl, }: ErrorMessageProps):
|
|
78
|
+
export declare function ErrorMessage({ error, code, onTryAgainClick, onUpgradeClick, upgradeUrl, }: ErrorMessageProps): ReactElement;
|
|
79
79
|
export {};
|
|
@@ -28,7 +28,7 @@ const messageIconsMap = {
|
|
|
28
28
|
* React component to render a block message.
|
|
29
29
|
*
|
|
30
30
|
* @param {MessageProps} props - Component props.
|
|
31
|
-
* @return {
|
|
31
|
+
* @return {ReactElement} Banner component.
|
|
32
32
|
*/
|
|
33
33
|
export default function Message({ severity = MESSAGE_SEVERITY_INFO, icon = null, aiFeedbackThumbsOptions = {
|
|
34
34
|
showAIFeedbackThumbs: false,
|
|
@@ -45,7 +45,7 @@ export default function Message({ severity = MESSAGE_SEVERITY_INFO, icon = null,
|
|
|
45
45
|
/**
|
|
46
46
|
* React component to render a learn more link.
|
|
47
47
|
*
|
|
48
|
-
* @return {
|
|
48
|
+
* @return {ReactElement} - Learn more link component.
|
|
49
49
|
*/
|
|
50
50
|
function LearnMoreLink() {
|
|
51
51
|
return (_jsx(ExternalLink, { href: "https://jetpack.com/redirect/?source=ai-guidelines", children: __('Learn more', 'jetpack-ai-client') }));
|
|
@@ -54,7 +54,7 @@ function LearnMoreLink() {
|
|
|
54
54
|
* React component to render a guideline message.
|
|
55
55
|
*
|
|
56
56
|
* @param {GuidelineMessageProps} props - Component props.
|
|
57
|
-
* @return {
|
|
57
|
+
* @return {ReactElement} - Message component.
|
|
58
58
|
*/
|
|
59
59
|
export function GuidelineMessage({ aiFeedbackThumbsOptions = {
|
|
60
60
|
showAIFeedbackThumbs: false,
|
|
@@ -68,7 +68,7 @@ export function GuidelineMessage({ aiFeedbackThumbsOptions = {
|
|
|
68
68
|
/**
|
|
69
69
|
* React component to render a fair usage limit message.
|
|
70
70
|
*
|
|
71
|
-
* @return {
|
|
71
|
+
* @return {ReactElement} - Message component.
|
|
72
72
|
*/
|
|
73
73
|
export function FairUsageLimitMessage() {
|
|
74
74
|
const message = __("You've reached this month's request limit, per our <link>fair usage policy</link>", 'jetpack-ai-client');
|
|
@@ -81,7 +81,7 @@ export function FairUsageLimitMessage() {
|
|
|
81
81
|
* React component to render an upgrade message for free tier users
|
|
82
82
|
*
|
|
83
83
|
* @param {number} requestsRemaining - Number of requests remaining.
|
|
84
|
-
* @return {
|
|
84
|
+
* @return {ReactElement} - Message component.
|
|
85
85
|
*/
|
|
86
86
|
export function UpgradeMessage({ requestsRemaining, severity, onUpgradeClick, upgradeUrl, }) {
|
|
87
87
|
let messageSeverity = severity;
|
|
@@ -96,7 +96,7 @@ export function UpgradeMessage({ requestsRemaining, severity, onUpgradeClick, up
|
|
|
96
96
|
* React component to render an error message
|
|
97
97
|
*
|
|
98
98
|
* @param {number} requestsRemaining - Number of requests remaining.
|
|
99
|
-
* @return {
|
|
99
|
+
* @return {ReactElement} - Message component.
|
|
100
100
|
*/
|
|
101
101
|
export function ErrorMessage({ error, code, onTryAgainClick, onUpgradeClick, upgradeUrl, }) {
|
|
102
102
|
const errorMessage = error || __('Something went wrong', 'jetpack-ai-client');
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { RequestingStateProp } from '../../types.ts';
|
|
2
2
|
import './style.scss';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
3
4
|
type AiAssistantModalProps = {
|
|
4
|
-
children:
|
|
5
|
+
children: ReactNode;
|
|
5
6
|
handleClose: () => void;
|
|
6
7
|
hideHeader?: boolean;
|
|
7
8
|
requestingState?: RequestingStateProp;
|
|
@@ -11,7 +12,7 @@ type AiAssistantModalProps = {
|
|
|
11
12
|
/**
|
|
12
13
|
* AiAssistantModal component
|
|
13
14
|
* @param {AiAssistantModalProps} props - The component properties.
|
|
14
|
-
* @return {
|
|
15
|
+
* @return {ReactElement} - rendered component.
|
|
15
16
|
*/
|
|
16
17
|
export default function AiAssistantModal({ children, handleClose, hideHeader, requestingState, title, maxWidth, }: AiAssistantModalProps): import("react/jsx-runtime").JSX.Element;
|
|
17
18
|
export {};
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* External dependencies
|
|
4
|
-
*/
|
|
5
2
|
import { Modal, Button } from '@wordpress/components';
|
|
6
3
|
import { __ } from '@wordpress/i18n';
|
|
7
4
|
import { close } from '@wordpress/icons';
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
5
|
import AiStatusIndicator from "../ai-status-indicator/index.js";
|
|
12
6
|
import './style.scss';
|
|
13
7
|
const ModalHeader = ({ requestingState, onClose, title, }) => {
|
|
@@ -16,7 +10,7 @@ const ModalHeader = ({ requestingState, onClose, title, }) => {
|
|
|
16
10
|
/**
|
|
17
11
|
* AiAssistantModal component
|
|
18
12
|
* @param {AiAssistantModalProps} props - The component properties.
|
|
19
|
-
* @return {
|
|
13
|
+
* @return {ReactElement} - rendered component.
|
|
20
14
|
*/
|
|
21
15
|
export default function AiAssistantModal({ children, handleClose, hideHeader = true, requestingState = 'init', title = __('AI Assistant', 'jetpack-ai-client'), maxWidth = 720, }) {
|
|
22
16
|
return (_jsx(Modal, { __experimentalHideHeader: hideHeader, className: "ai-assistant-modal", shouldCloseOnClickOutside: false, onRequestClose: handleClose, children: _jsxs("div", { className: "ai-assistant-modal__content", style: { maxWidth }, children: [_jsx(ModalHeader, { requestingState: requestingState, onClose: handleClose, title: title }), _jsx("hr", { className: "ai-assistant-modal__divider" }), children] }) }));
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import React from 'react';
|
|
5
1
|
/**
|
|
6
2
|
* Types & Constants
|
|
7
3
|
*/
|
|
@@ -9,6 +5,7 @@ import SuggestionsEventSource from '../suggestions-event-source/index.ts';
|
|
|
9
5
|
import type { AskQuestionOptionsArgProps } from '../ask-question/index.ts';
|
|
10
6
|
import type { RequestingErrorProps } from '../hooks/use-ai-suggestions/index.ts';
|
|
11
7
|
import type { PromptProp, RequestingStateProp } from '../types.ts';
|
|
8
|
+
import type { ReactElement } from 'react';
|
|
12
9
|
export type AiDataContextProps = {
|
|
13
10
|
suggestion: string;
|
|
14
11
|
requestingError: RequestingErrorProps;
|
|
@@ -19,23 +16,23 @@ export type AiDataContextProps = {
|
|
|
19
16
|
};
|
|
20
17
|
type AiDataContextProviderProps = {
|
|
21
18
|
value: AiDataContextProps;
|
|
22
|
-
children:
|
|
19
|
+
children: ReactElement;
|
|
23
20
|
};
|
|
24
21
|
/**
|
|
25
22
|
* AI Data Context
|
|
26
23
|
*
|
|
27
24
|
* @return {AiDataContextProps} Context.
|
|
28
25
|
*/
|
|
29
|
-
export declare const AiDataContext:
|
|
26
|
+
export declare const AiDataContext: import("react").Context<object | AiDataContextProps>;
|
|
30
27
|
/**
|
|
31
28
|
* AI Data Context Provider
|
|
32
29
|
*
|
|
33
30
|
* @param {AiDataContextProviderProps} props - Component props.
|
|
34
|
-
* @return {
|
|
31
|
+
* @return {ReactElement} Context provider.
|
|
35
32
|
* @example
|
|
36
33
|
* <AiDataContextProvider value={ value }>
|
|
37
34
|
* { children }
|
|
38
35
|
* </AiDataContextProvider>
|
|
39
36
|
*/
|
|
40
|
-
export declare const AiDataContextProvider: ({ value, children, }: AiDataContextProviderProps) =>
|
|
37
|
+
export declare const AiDataContextProvider: ({ value, children, }: AiDataContextProviderProps) => ReactElement;
|
|
41
38
|
export {};
|
|
@@ -13,7 +13,7 @@ export const AiDataContext = createContext({});
|
|
|
13
13
|
* AI Data Context Provider
|
|
14
14
|
*
|
|
15
15
|
* @param {AiDataContextProviderProps} props - Component props.
|
|
16
|
-
* @return {
|
|
16
|
+
* @return {ReactElement} Context provider.
|
|
17
17
|
* @example
|
|
18
18
|
* <AiDataContextProvider value={ value }>
|
|
19
19
|
* { children }
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* High Order Component that provides the
|
|
4
4
|
* AI Assistant Data context to the wrapped component.
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
7
|
-
* @return {
|
|
6
|
+
* @param {ReactElement} WrappedComponent - component to wrap.
|
|
7
|
+
* @return {ReactElement} Wrapped component, with the AI Assistant Data context.
|
|
8
8
|
*/
|
|
9
|
-
declare const withAiDataProvider: (Inner:
|
|
9
|
+
declare const withAiDataProvider: (Inner: ComponentType) => (props: any) => import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
export default withAiDataProvider;
|
|
@@ -13,8 +13,8 @@ import { AiDataContextProvider } from "./index.js";
|
|
|
13
13
|
* High Order Component that provides the
|
|
14
14
|
* AI Assistant Data context to the wrapped component.
|
|
15
15
|
*
|
|
16
|
-
* @param {
|
|
17
|
-
* @return {
|
|
16
|
+
* @param {ReactElement} WrappedComponent - component to wrap.
|
|
17
|
+
* @return {ReactElement} Wrapped component, with the AI Assistant Data context.
|
|
18
18
|
*/
|
|
19
19
|
const withAiDataProvider = createHigherOrderComponent((WrappedComponent) => {
|
|
20
20
|
return props => {
|
package/build/jwt/index.js
CHANGED
|
@@ -39,7 +39,7 @@ export default async function requestJwt({ apiNonce, siteId, expirationTime, } =
|
|
|
39
39
|
let data;
|
|
40
40
|
const isSimple = isSimpleSite();
|
|
41
41
|
if (!isSimple) {
|
|
42
|
-
data = await apiFetch({
|
|
42
|
+
data = (await apiFetch({
|
|
43
43
|
/*
|
|
44
44
|
* This endpoint is registered in the Jetpack plugin.
|
|
45
45
|
* Provably we should move it to another package, but for now it's here.
|
|
@@ -51,13 +51,13 @@ export default async function requestJwt({ apiNonce, siteId, expirationTime, } =
|
|
|
51
51
|
'X-WP-Nonce': apiNonce,
|
|
52
52
|
},
|
|
53
53
|
method: 'POST',
|
|
54
|
-
});
|
|
54
|
+
}));
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
|
-
data = await apiFetch({
|
|
57
|
+
data = (await apiFetch({
|
|
58
58
|
path: '/wpcom/v2/sites/' + siteId + '/jetpack-openai-query/jwt',
|
|
59
59
|
method: 'POST',
|
|
60
|
-
});
|
|
60
|
+
}));
|
|
61
61
|
}
|
|
62
62
|
const newTokenData = {
|
|
63
63
|
token: data.token,
|
|
@@ -3,5 +3,5 @@ import './generator-modal.scss';
|
|
|
3
3
|
* Types
|
|
4
4
|
*/
|
|
5
5
|
import type { GeneratorModalProps } from '../types.ts';
|
|
6
|
-
import type
|
|
7
|
-
export declare const GeneratorModal:
|
|
6
|
+
import type { FC } from 'react';
|
|
7
|
+
export declare const GeneratorModal: FC<GeneratorModalProps>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import './logo-presenter.scss';
|
|
2
2
|
import type { LogoPresenterProps } from '../types.ts';
|
|
3
|
-
import type
|
|
4
|
-
export declare const LogoPresenter:
|
|
3
|
+
import type { FC } from 'react';
|
|
4
|
+
export declare const LogoPresenter: FC<LogoPresenterProps>;
|
|
@@ -56,7 +56,7 @@ const SaveInLibraryButton = ({ siteId }) => {
|
|
|
56
56
|
const savedLabel = __('Saved', 'jetpack-ai-client');
|
|
57
57
|
return !saving && !saved ? (_jsxs(Button, { className: "jetpack-ai-logo-generator-modal-presenter__action", onClick: handleClick, children: [_jsx(Icon, { icon: _jsx(MediaIcon, {}) }), _jsx("span", { className: "action-text", children: __('Save in Library', 'jetpack-ai-client') })] })) : (_jsxs(Button, { className: "jetpack-ai-logo-generator-modal-presenter__action", children: [_jsx(Icon, { icon: saving ? _jsx(MediaIcon, {}) : _jsx(CheckIcon, {}) }), _jsx("span", { className: "action-text", children: saving ? savingLabel : savedLabel })] }));
|
|
58
58
|
};
|
|
59
|
-
const UseOnSiteButton = ({ onApplyLogo
|
|
59
|
+
const UseOnSiteButton = ({ onApplyLogo }) => {
|
|
60
60
|
const { tracks } = useAnalytics();
|
|
61
61
|
const { recordEvent: recordTracksEvent } = tracks;
|
|
62
62
|
const { isSavingLogoToLibrary, selectedLogo, logos, selectedLogoIndex, context } = useLogoGenerator();
|
|
@@ -2,8 +2,8 @@ import './visit-site-banner.scss';
|
|
|
2
2
|
/**
|
|
3
3
|
* Types
|
|
4
4
|
*/
|
|
5
|
-
import type
|
|
6
|
-
export declare const VisitSiteBanner:
|
|
5
|
+
import type { FC } from 'react';
|
|
6
|
+
export declare const VisitSiteBanner: FC<{
|
|
7
7
|
className?: string;
|
|
8
8
|
onVisitBlankTarget?: () => void;
|
|
9
9
|
}>;
|
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.33.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": {
|
|
@@ -45,30 +45,30 @@
|
|
|
45
45
|
"main": "./build/index.js",
|
|
46
46
|
"types": "./build/index.d.ts",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@automattic/jetpack-base-styles": "^1.0.
|
|
49
|
-
"@automattic/jetpack-components": "^1.1.
|
|
50
|
-
"@automattic/jetpack-connection": "^1.2.
|
|
48
|
+
"@automattic/jetpack-base-styles": "^1.0.3",
|
|
49
|
+
"@automattic/jetpack-components": "^1.1.10",
|
|
50
|
+
"@automattic/jetpack-connection": "^1.2.10",
|
|
51
51
|
"@automattic/jetpack-script-data": "^0.4.4",
|
|
52
52
|
"@automattic/jetpack-explat": "workspace:*",
|
|
53
|
-
"@automattic/jetpack-shared-extension-utils": "^1.
|
|
53
|
+
"@automattic/jetpack-shared-extension-utils": "^1.3.0",
|
|
54
54
|
"@microsoft/fetch-event-source": "2.0.1",
|
|
55
55
|
"@types/jest": "30.0.0",
|
|
56
56
|
"@types/react": "18.3.23",
|
|
57
57
|
"@types/wordpress__block-editor": "11.5.16",
|
|
58
|
-
"@wordpress/api-fetch": "7.
|
|
59
|
-
"@wordpress/base-styles": "6.
|
|
60
|
-
"@wordpress/blob": "4.
|
|
61
|
-
"@wordpress/block-editor": "14.
|
|
62
|
-
"@wordpress/blocks": "14.
|
|
63
|
-
"@wordpress/components": "29.
|
|
64
|
-
"@wordpress/compose": "7.
|
|
65
|
-
"@wordpress/data": "10.
|
|
66
|
-
"@wordpress/editor": "14.
|
|
67
|
-
"@wordpress/element": "6.
|
|
68
|
-
"@wordpress/i18n": "5.
|
|
69
|
-
"@wordpress/icons": "10.
|
|
70
|
-
"@wordpress/primitives": "4.
|
|
71
|
-
"@wordpress/url": "4.
|
|
58
|
+
"@wordpress/api-fetch": "7.26.0",
|
|
59
|
+
"@wordpress/base-styles": "6.2.0",
|
|
60
|
+
"@wordpress/blob": "4.26.0",
|
|
61
|
+
"@wordpress/block-editor": "14.21.0",
|
|
62
|
+
"@wordpress/blocks": "14.15.0",
|
|
63
|
+
"@wordpress/components": "29.12.0",
|
|
64
|
+
"@wordpress/compose": "7.26.0",
|
|
65
|
+
"@wordpress/data": "10.26.0",
|
|
66
|
+
"@wordpress/editor": "14.26.0",
|
|
67
|
+
"@wordpress/element": "6.26.0",
|
|
68
|
+
"@wordpress/i18n": "5.26.0",
|
|
69
|
+
"@wordpress/icons": "10.26.0",
|
|
70
|
+
"@wordpress/primitives": "4.26.0",
|
|
71
|
+
"@wordpress/url": "4.26.0",
|
|
72
72
|
"clsx": "2.1.1",
|
|
73
73
|
"debug": "4.4.1",
|
|
74
74
|
"markdown-it": "14.1.0",
|
package/src/api-fetch/index.ts
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import apiFetchMod from '@wordpress/api-fetch';
|
|
5
|
+
/**
|
|
6
|
+
* Types
|
|
7
|
+
*/
|
|
8
|
+
import type { APIFetchOptions } from '@wordpress/api-fetch';
|
|
5
9
|
|
|
6
10
|
// @wordpress/api-fetch (as of 6.47.0) declares itself in such a way that tsc and node see the function at apiFetchMod.default
|
|
7
11
|
// while some other environments (including code running inside WordPress itself) see it at apiFetch.
|
|
@@ -11,4 +15,10 @@ const apiFetch = 'default' in apiFetchMod ? apiFetchMod.default : apiFetchMod;
|
|
|
11
15
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
12
16
|
type ApiFetchType = typeof apiFetch extends Function ? typeof apiFetch : typeof apiFetchMod;
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
type AugmentedAPIFetchOptions = APIFetchOptions & {
|
|
19
|
+
global?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type AugmentedApiFetchType = ( options: AugmentedAPIFetchOptions ) => ReturnType< ApiFetchType >;
|
|
23
|
+
|
|
24
|
+
export default apiFetch as AugmentedApiFetchType;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { initializeExPlat,
|
|
4
|
+
import { initializeExPlat, createExPlatClient } from '@automattic/jetpack-explat';
|
|
5
5
|
import { select } from '@wordpress/data';
|
|
6
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
6
7
|
import debugFactory from 'debug';
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import apiFetch from '../api-fetch/index.ts';
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* Types
|
|
@@ -21,6 +24,8 @@ type PlansSelect = {
|
|
|
21
24
|
};
|
|
22
25
|
};
|
|
23
26
|
|
|
27
|
+
const debug = debugFactory( 'ai-client:chrome-ai-availability' );
|
|
28
|
+
|
|
24
29
|
/**
|
|
25
30
|
* Get the AI Assistant feature.
|
|
26
31
|
*
|
|
@@ -31,6 +36,40 @@ function getAiAssistantFeature() {
|
|
|
31
36
|
return getFeature();
|
|
32
37
|
}
|
|
33
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Fetch an experiment assignment.
|
|
41
|
+
*
|
|
42
|
+
* @param {boolean} asConnectedUser - Whether the user is connected.
|
|
43
|
+
* @return {Function} A function that fetches an experiment assignment.
|
|
44
|
+
*/
|
|
45
|
+
const fetchExperimentAssignmentWithConnectedUser = async ( {
|
|
46
|
+
experimentName,
|
|
47
|
+
}: {
|
|
48
|
+
experimentName: string;
|
|
49
|
+
} ): Promise< unknown > => {
|
|
50
|
+
const params = {
|
|
51
|
+
experiment_name: experimentName,
|
|
52
|
+
anon_id: undefined,
|
|
53
|
+
as_connected_user: true,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
debug( 'params', params );
|
|
57
|
+
|
|
58
|
+
const assignmentsRequestUrl = addQueryArgs(
|
|
59
|
+
'https://public-api.wordpress.com/wpcom/v2/experiments/0.1.0/assignments/jetpack',
|
|
60
|
+
params
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
debug( 'assignmentsRequestUrl', assignmentsRequestUrl );
|
|
64
|
+
|
|
65
|
+
return apiFetch( {
|
|
66
|
+
url: assignmentsRequestUrl,
|
|
67
|
+
credentials: 'include',
|
|
68
|
+
mode: 'cors',
|
|
69
|
+
global: true,
|
|
70
|
+
} );
|
|
71
|
+
};
|
|
72
|
+
|
|
34
73
|
/**
|
|
35
74
|
* Check if Chrome AI can be enabled.
|
|
36
75
|
*
|
|
@@ -46,10 +85,16 @@ export async function isChromeAIAvailable() {
|
|
|
46
85
|
}
|
|
47
86
|
|
|
48
87
|
initializeExPlat();
|
|
49
|
-
|
|
88
|
+
|
|
89
|
+
const { loadExperimentAssignment: loadExperimentAssignmentWithAuth } = createExPlatClient( {
|
|
90
|
+
fetchExperimentAssignment: fetchExperimentAssignmentWithConnectedUser,
|
|
91
|
+
getAnonId: async () => null,
|
|
92
|
+
logError: debug,
|
|
93
|
+
isDevelopmentMode: false,
|
|
94
|
+
} );
|
|
50
95
|
|
|
51
96
|
const { variationName } = await loadExperimentAssignmentWithAuth(
|
|
52
|
-
'
|
|
97
|
+
'calypso_jetpack_ai_gemini_api_202503_v2'
|
|
53
98
|
);
|
|
54
99
|
|
|
55
100
|
debug( 'variationName', variationName );
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { PlainText } from '@wordpress/block-editor';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
-
import React from 'react';
|
|
7
6
|
/**
|
|
8
7
|
* Internal dependencies
|
|
9
8
|
*/
|
|
@@ -13,7 +12,7 @@ import './style.scss';
|
|
|
13
12
|
* Types
|
|
14
13
|
*/
|
|
15
14
|
import type { RequestingStateProp } from '../../types.ts';
|
|
16
|
-
import type { ReactElement } from 'react';
|
|
15
|
+
import type { MutableRefObject, ReactElement } from 'react';
|
|
17
16
|
|
|
18
17
|
type AIControlProps = {
|
|
19
18
|
className?: string;
|
|
@@ -28,7 +27,7 @@ type AIControlProps = {
|
|
|
28
27
|
actions?: ReactElement;
|
|
29
28
|
message?: ReactElement;
|
|
30
29
|
promptUserInputRef?: PlainText.Props[ 'ref' ];
|
|
31
|
-
wrapperRef?:
|
|
30
|
+
wrapperRef?: MutableRefObject< HTMLDivElement | null >;
|
|
32
31
|
};
|
|
33
32
|
|
|
34
33
|
/**
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
reusableBlock as regenerate,
|
|
15
15
|
} from '@wordpress/icons';
|
|
16
16
|
import debugFactory from 'debug';
|
|
17
|
-
import
|
|
17
|
+
import { forwardRef } from 'react';
|
|
18
18
|
/**
|
|
19
19
|
* Internal dependencies
|
|
20
20
|
*/
|
|
@@ -25,7 +25,7 @@ import './style.scss';
|
|
|
25
25
|
* Types
|
|
26
26
|
*/
|
|
27
27
|
import type { RequestingStateProp } from '../../types.ts';
|
|
28
|
-
import type { ReactElement } from 'react';
|
|
28
|
+
import type { MutableRefObject, ReactElement } from 'react';
|
|
29
29
|
|
|
30
30
|
type BlockAIControlProps = {
|
|
31
31
|
disabled?: boolean;
|
|
@@ -54,8 +54,8 @@ const debug = debugFactory( 'jetpack-ai-client:block-ai-control' );
|
|
|
54
54
|
/**
|
|
55
55
|
* BlockAIControl component. Used by the AI Assistant block, adding logic and components to the base AIControl component.
|
|
56
56
|
*
|
|
57
|
-
* @param {BlockAIControlProps}
|
|
58
|
-
* @param {
|
|
57
|
+
* @param {BlockAIControlProps} props - Component props
|
|
58
|
+
* @param {MutableRefObject} ref - Ref to the component
|
|
59
59
|
* @return {ReactElement} Rendered component
|
|
60
60
|
*/
|
|
61
61
|
export function BlockAIControl(
|
|
@@ -80,7 +80,7 @@ export function BlockAIControl(
|
|
|
80
80
|
error = null,
|
|
81
81
|
lastAction,
|
|
82
82
|
}: BlockAIControlProps,
|
|
83
|
-
ref:
|
|
83
|
+
ref: MutableRefObject< HTMLInputElement >
|
|
84
84
|
): ReactElement {
|
|
85
85
|
const loading = state === 'requesting' || state === 'suggesting';
|
|
86
86
|
const [ editRequest, setEditRequest ] = useState( false );
|
|
@@ -6,7 +6,7 @@ import { useKeyboardShortcut } from '@wordpress/compose';
|
|
|
6
6
|
import { useImperativeHandle, useRef, useEffect, useCallback, useState } from '@wordpress/element';
|
|
7
7
|
import { __ } from '@wordpress/i18n';
|
|
8
8
|
import { Icon, closeSmall, arrowUp, undo } from '@wordpress/icons';
|
|
9
|
-
import
|
|
9
|
+
import { forwardRef } from 'react';
|
|
10
10
|
/**
|
|
11
11
|
* Internal dependencies
|
|
12
12
|
*/
|
|
@@ -22,7 +22,7 @@ import './style.scss';
|
|
|
22
22
|
* Types
|
|
23
23
|
*/
|
|
24
24
|
import type { RequestingErrorProps, RequestingStateProp } from '../../types.ts';
|
|
25
|
-
import type { ReactElement, MouseEvent } from 'react';
|
|
25
|
+
import type { MutableRefObject, ReactElement, MouseEvent } from 'react';
|
|
26
26
|
|
|
27
27
|
type ExtensionAIControlProps = {
|
|
28
28
|
className?: string;
|
|
@@ -38,7 +38,7 @@ type ExtensionAIControlProps = {
|
|
|
38
38
|
showUpgradeMessage?: boolean;
|
|
39
39
|
showFairUsageMessage?: boolean;
|
|
40
40
|
upgradeUrl?: string;
|
|
41
|
-
wrapperRef?:
|
|
41
|
+
wrapperRef?: MutableRefObject< HTMLDivElement | null >;
|
|
42
42
|
onChange?: ( newValue: string ) => void;
|
|
43
43
|
onSend?: ( currentValue: string ) => void;
|
|
44
44
|
onStop?: () => void;
|
|
@@ -54,7 +54,7 @@ type ExtensionAIControlProps = {
|
|
|
54
54
|
* ExtensionAIControl component. Used by the AI Assistant inline extensions, adding logic and components to the base AIControl component.
|
|
55
55
|
*
|
|
56
56
|
* @param {ExtensionAIControlProps} props - Component props
|
|
57
|
-
* @param {
|
|
57
|
+
* @param {MutableRefObject} ref - Ref to the component
|
|
58
58
|
* @return {ReactElement} Rendered component
|
|
59
59
|
*/
|
|
60
60
|
export function ExtensionAIControl(
|
|
@@ -83,7 +83,7 @@ export function ExtensionAIControl(
|
|
|
83
83
|
lastAction,
|
|
84
84
|
blockType,
|
|
85
85
|
}: ExtensionAIControlProps,
|
|
86
|
-
ref:
|
|
86
|
+
ref: MutableRefObject< HTMLInputElement >
|
|
87
87
|
): ReactElement {
|
|
88
88
|
const loading = state === 'requesting' || state === 'suggesting';
|
|
89
89
|
const [ editRequest, setEditRequest ] = useState( false );
|