@automattic/jetpack-ai-client 0.29.0 → 0.31.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 +18 -0
- package/build/chrome-ai/factory.js +2 -10
- package/build/chrome-ai/get-availability.d.ts +7 -0
- package/build/chrome-ai/get-availability.js +25 -0
- package/build/hooks/use-ai-feature/index.js +1 -16
- package/package.json +22 -22
- package/src/chrome-ai/factory.ts +2 -11
- package/src/chrome-ai/get-availability.ts +44 -0
- package/src/components/ai-control/style.scss +1 -1
- package/src/components/ai-feedback/style.scss +0 -2
- package/src/components/ai-image/components/carrousel.scss +13 -14
- package/src/components/ai-image/components/usage-counter.scss +1 -1
- package/src/components/ai-status-indicator/style.scss +1 -1
- package/src/components/message/style.scss +1 -1
- package/src/components/quota-exceeded-message/style.scss +1 -1
- package/src/hooks/use-ai-feature/index.ts +1 -17
- package/src/logo-generator/components/generator-modal.scss +1 -1
- package/src/logo-generator/components/history-carousel.scss +1 -1
- package/src/logo-generator/components/logo-presenter.scss +1 -1
- package/src/logo-generator/components/prompt.scss +1 -1
- package/src/logo-generator/components/upgrade-nudge.scss +1 -1
- package/src/logo-generator/components/visit-site-banner.scss +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,21 @@ 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.31.1] - 2025-06-05
|
|
9
|
+
### Changed
|
|
10
|
+
- Update package dependencies. [#43718] [#43766]
|
|
11
|
+
|
|
12
|
+
## [0.31.0] - 2025-06-02
|
|
13
|
+
### Changed
|
|
14
|
+
- Change how Chrome's built-in AI API tokens are injected. [#43682]
|
|
15
|
+
- sass: Remove unnecessary `@import` of `@wordpress/base-styles`. [#43607]
|
|
16
|
+
- Update package dependencies. [#43711]
|
|
17
|
+
|
|
18
|
+
## [0.30.0] - 2025-05-26
|
|
19
|
+
### Changed
|
|
20
|
+
- AI Assistant: Propagate the AI model used in the AI requests. [#43495]
|
|
21
|
+
- Update package dependencies. [#43578]
|
|
22
|
+
|
|
8
23
|
## [0.29.0] - 2025-05-19
|
|
9
24
|
### Added
|
|
10
25
|
- AI Assistant: Retrieve Chrome AI token from AI Features response and inject it from the frontend. [#43442]
|
|
@@ -616,6 +631,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
616
631
|
- AI Client: stop using smart document visibility handling on the fetchEventSource library, so it does not restart the completion when changing tabs. [#32004]
|
|
617
632
|
- Updated package dependencies. [#31468] [#31659] [#31785]
|
|
618
633
|
|
|
634
|
+
[0.31.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.31.0...v0.31.1
|
|
635
|
+
[0.31.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.30.0...v0.31.0
|
|
636
|
+
[0.30.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.29.0...v0.30.0
|
|
619
637
|
[0.29.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.28.1...v0.29.0
|
|
620
638
|
[0.28.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.28.0...v0.28.1
|
|
621
639
|
[0.28.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.27.10...v0.28.0
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { getJetpackExtensionAvailability } from '@automattic/jetpack-shared-extension-utils';
|
|
2
1
|
import { PROMPT_TYPE_CHANGE_LANGUAGE, PROMPT_TYPE_SUMMARIZE } from "../constants.js";
|
|
2
|
+
import { isChromeAIAvailable } from "./get-availability.js";
|
|
3
3
|
import ChromeAISuggestionsEventSource from "./suggestions.js";
|
|
4
|
-
/**
|
|
5
|
-
* Check for the feature flag.
|
|
6
|
-
*
|
|
7
|
-
* @return boolean
|
|
8
|
-
*/
|
|
9
|
-
function shouldUseChromeAI() {
|
|
10
|
-
return getJetpackExtensionAvailability('ai-use-chrome-ai-sometimes').available === true;
|
|
11
|
-
}
|
|
12
4
|
/**
|
|
13
5
|
* This will return an instance of ChromeAISuggestionsEventSource or false.
|
|
14
6
|
*
|
|
@@ -16,7 +8,7 @@ function shouldUseChromeAI() {
|
|
|
16
8
|
* @return ChromeAISuggestionsEventSource | bool
|
|
17
9
|
*/
|
|
18
10
|
export default async function ChromeAIFactory(promptArg) {
|
|
19
|
-
if (!
|
|
11
|
+
if (!isChromeAIAvailable()) {
|
|
20
12
|
return false;
|
|
21
13
|
}
|
|
22
14
|
const context = {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { getJetpackExtensionAvailability } from '@automattic/jetpack-shared-extension-utils';
|
|
5
|
+
import { select } from '@wordpress/data';
|
|
6
|
+
/**
|
|
7
|
+
* Get the AI Assistant feature.
|
|
8
|
+
*
|
|
9
|
+
* @return {object} The AI Assistant feature.
|
|
10
|
+
*/
|
|
11
|
+
function getAiAssistantFeature() {
|
|
12
|
+
const { getAiAssistantFeature: getFeature } = select('wordpress-com/plans');
|
|
13
|
+
return getFeature();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if Chrome AI can be enabled.
|
|
17
|
+
*
|
|
18
|
+
* @return {boolean} Whether Chrome AI can be enabled.
|
|
19
|
+
*/
|
|
20
|
+
export function isChromeAIAvailable() {
|
|
21
|
+
const { featuresControl } = getAiAssistantFeature();
|
|
22
|
+
return (featuresControl?.['chrome-ai']?.enabled !== false &&
|
|
23
|
+
getJetpackExtensionAvailability('ai-use-chrome-ai-sometimes').available !== false);
|
|
24
|
+
}
|
|
25
|
+
export default isChromeAIAvailable;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { PLAN_TYPE_FREE, usePlanType as getPlanType, } from '@automattic/jetpack-shared-extension-utils';
|
|
5
5
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
|
-
import { useMemo
|
|
6
|
+
import { useMemo } from '@wordpress/element';
|
|
7
7
|
/**
|
|
8
8
|
* Hook to get properties for AiFeature
|
|
9
9
|
* @return {object} - Object containing properties for AiFeature.
|
|
@@ -12,21 +12,6 @@ export default function useAiFeature() {
|
|
|
12
12
|
const data = useSelect(select => select('wordpress-com/plans').getAiAssistantFeature(), []);
|
|
13
13
|
const loading = useSelect(select => select('wordpress-com/plans').getIsRequestingAiAssistantFeature(), []);
|
|
14
14
|
const { fetchAiAssistantFeature: loadFeatures, increaseAiAssistantRequestsCount: increaseRequestsCount, dequeueAiAssistantFeatureAsyncRequest: dequeueAsyncRequest, } = useDispatch('wordpress-com/plans');
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (!loading && data) {
|
|
17
|
-
// Check if the meta tag already exists
|
|
18
|
-
const existingMeta = document.querySelector('meta[http-equiv="origin-trial"]');
|
|
19
|
-
if (!existingMeta && data?.chromeAiTokens) {
|
|
20
|
-
// iterate through chromeAiTokens and create a meta tag for each one
|
|
21
|
-
Object.keys(data.chromeAiTokens).forEach(token => {
|
|
22
|
-
const otMeta = document.createElement('meta');
|
|
23
|
-
otMeta.httpEquiv = 'origin-trial';
|
|
24
|
-
otMeta.content = data.chromeAiTokens[token];
|
|
25
|
-
document.head.appendChild(otMeta);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}, [loading, data]);
|
|
30
15
|
return useMemo(() => {
|
|
31
16
|
const planType = getPlanType(data?.currentTier);
|
|
32
17
|
const currentTierLimit = data?.currentTier?.limit || data?.requestsLimit;
|
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.31.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": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"jest": "^29.6.2",
|
|
35
35
|
"jest-environment-jsdom": "29.7.0",
|
|
36
36
|
"storybook": "8.6.7",
|
|
37
|
-
"typescript": "5.8.
|
|
37
|
+
"typescript": "5.8.3"
|
|
38
38
|
},
|
|
39
39
|
"exports": {
|
|
40
40
|
".": {
|
|
@@ -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": "^0.
|
|
49
|
-
"@automattic/jetpack-components": "^
|
|
50
|
-
"@automattic/jetpack-connection": "^
|
|
51
|
-
"@automattic/jetpack-shared-extension-utils": "^0.
|
|
48
|
+
"@automattic/jetpack-base-styles": "^1.0.0",
|
|
49
|
+
"@automattic/jetpack-components": "^1.1.0",
|
|
50
|
+
"@automattic/jetpack-connection": "^1.2.0",
|
|
51
|
+
"@automattic/jetpack-shared-extension-utils": "^1.0.1",
|
|
52
52
|
"@microsoft/fetch-event-source": "2.0.1",
|
|
53
53
|
"@types/jest": "29.5.14",
|
|
54
|
-
"@types/react": "18.3.
|
|
54
|
+
"@types/react": "18.3.23",
|
|
55
55
|
"@types/wordpress__block-editor": "11.5.16",
|
|
56
|
-
"@wordpress/api-fetch": "7.
|
|
57
|
-
"@wordpress/base-styles": "
|
|
58
|
-
"@wordpress/blob": "4.
|
|
59
|
-
"@wordpress/blocks": "14.
|
|
60
|
-
"@wordpress/block-editor": "14.
|
|
61
|
-
"@wordpress/components": "29.
|
|
62
|
-
"@wordpress/compose": "7.
|
|
63
|
-
"@wordpress/data": "10.
|
|
64
|
-
"@wordpress/editor": "14.
|
|
65
|
-
"@wordpress/element": "6.
|
|
66
|
-
"@wordpress/i18n": "5.
|
|
67
|
-
"@wordpress/icons": "10.
|
|
68
|
-
"@wordpress/primitives": "4.
|
|
69
|
-
"@wordpress/url": "4.
|
|
56
|
+
"@wordpress/api-fetch": "7.24.0",
|
|
57
|
+
"@wordpress/base-styles": "6.0.0",
|
|
58
|
+
"@wordpress/blob": "4.24.0",
|
|
59
|
+
"@wordpress/blocks": "14.13.0",
|
|
60
|
+
"@wordpress/block-editor": "14.19.0",
|
|
61
|
+
"@wordpress/components": "29.10.0",
|
|
62
|
+
"@wordpress/compose": "7.24.0",
|
|
63
|
+
"@wordpress/data": "10.24.0",
|
|
64
|
+
"@wordpress/editor": "14.24.0",
|
|
65
|
+
"@wordpress/element": "6.24.0",
|
|
66
|
+
"@wordpress/i18n": "5.24.0",
|
|
67
|
+
"@wordpress/icons": "10.24.0",
|
|
68
|
+
"@wordpress/primitives": "4.24.0",
|
|
69
|
+
"@wordpress/url": "4.24.0",
|
|
70
70
|
"clsx": "2.1.1",
|
|
71
|
-
"debug": "4.4.
|
|
71
|
+
"debug": "4.4.1",
|
|
72
72
|
"markdown-it": "14.1.0",
|
|
73
73
|
"react": "18.3.1",
|
|
74
74
|
"react-dom": "18.3.1",
|
package/src/chrome-ai/factory.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import { getJetpackExtensionAvailability } from '@automattic/jetpack-shared-extension-utils';
|
|
2
1
|
import { PROMPT_TYPE_CHANGE_LANGUAGE, PROMPT_TYPE_SUMMARIZE } from '../constants.ts';
|
|
3
2
|
import { PromptProp, PromptItemProps } from '../types.ts';
|
|
3
|
+
import { isChromeAIAvailable } from './get-availability.ts';
|
|
4
4
|
import ChromeAISuggestionsEventSource from './suggestions.ts';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Check for the feature flag.
|
|
8
|
-
*
|
|
9
|
-
* @return boolean
|
|
10
|
-
*/
|
|
11
|
-
function shouldUseChromeAI() {
|
|
12
|
-
return getJetpackExtensionAvailability( 'ai-use-chrome-ai-sometimes' ).available === true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
6
|
interface PromptContext {
|
|
16
7
|
type?: string;
|
|
17
8
|
content?: string;
|
|
@@ -27,7 +18,7 @@ interface PromptContext {
|
|
|
27
18
|
* @return ChromeAISuggestionsEventSource | bool
|
|
28
19
|
*/
|
|
29
20
|
export default async function ChromeAIFactory( promptArg: PromptProp ) {
|
|
30
|
-
if ( !
|
|
21
|
+
if ( ! isChromeAIAvailable() ) {
|
|
31
22
|
return false;
|
|
32
23
|
}
|
|
33
24
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { getJetpackExtensionAvailability } from '@automattic/jetpack-shared-extension-utils';
|
|
5
|
+
import { select } from '@wordpress/data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Types
|
|
9
|
+
*/
|
|
10
|
+
type FeatureControl = {
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type PlansSelect = {
|
|
15
|
+
getAiAssistantFeature: () => {
|
|
16
|
+
currentTier?: { value: number };
|
|
17
|
+
featuresControl?: Record< string, FeatureControl >;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get the AI Assistant feature.
|
|
23
|
+
*
|
|
24
|
+
* @return {object} The AI Assistant feature.
|
|
25
|
+
*/
|
|
26
|
+
function getAiAssistantFeature() {
|
|
27
|
+
const { getAiAssistantFeature: getFeature } = select( 'wordpress-com/plans' ) as PlansSelect;
|
|
28
|
+
return getFeature();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Check if Chrome AI can be enabled.
|
|
33
|
+
*
|
|
34
|
+
* @return {boolean} Whether Chrome AI can be enabled.
|
|
35
|
+
*/
|
|
36
|
+
export function isChromeAIAvailable() {
|
|
37
|
+
const { featuresControl } = getAiAssistantFeature();
|
|
38
|
+
return (
|
|
39
|
+
featuresControl?.[ 'chrome-ai' ]?.enabled !== false &&
|
|
40
|
+
getJetpackExtensionAvailability( 'ai-use-chrome-ai-sometimes' ).available !== false
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default isChromeAIAvailable;
|
|
@@ -64,20 +64,6 @@ $scale-factor: 0.55;
|
|
|
64
64
|
|
|
65
65
|
&__prev,
|
|
66
66
|
&__next {
|
|
67
|
-
|
|
68
|
-
&:hover {
|
|
69
|
-
background-color: rgba( 0, 0, 0, 0.3 );
|
|
70
|
-
opacity: 1;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
&-icon {
|
|
74
|
-
fill: #fff;
|
|
75
|
-
|
|
76
|
-
&.is-disabled {
|
|
77
|
-
fill: #808080;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
67
|
cursor: pointer;
|
|
82
68
|
z-index: 1;
|
|
83
69
|
display: flex;
|
|
@@ -92,6 +78,19 @@ $scale-factor: 0.55;
|
|
|
92
78
|
width: 60px;
|
|
93
79
|
opacity: 0;
|
|
94
80
|
background: transparent;
|
|
81
|
+
|
|
82
|
+
&:hover {
|
|
83
|
+
background-color: rgba( 0, 0, 0, 0.3 );
|
|
84
|
+
opacity: 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&-icon {
|
|
88
|
+
fill: #fff;
|
|
89
|
+
|
|
90
|
+
&.is-disabled {
|
|
91
|
+
fill: #808080;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
usePlanType as getPlanType,
|
|
7
7
|
} from '@automattic/jetpack-shared-extension-utils';
|
|
8
8
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
9
|
-
import { useMemo
|
|
9
|
+
import { useMemo } from '@wordpress/element';
|
|
10
10
|
import type { WordPressPlansSelectors } from '@automattic/jetpack-shared-extension-utils/store/wordpress-com';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -34,22 +34,6 @@ export default function useAiFeature() {
|
|
|
34
34
|
dequeueAiAssistantFeatureAsyncRequest: dequeueAsyncRequest,
|
|
35
35
|
} = useDispatch( 'wordpress-com/plans' );
|
|
36
36
|
|
|
37
|
-
useEffect( () => {
|
|
38
|
-
if ( ! loading && data ) {
|
|
39
|
-
// Check if the meta tag already exists
|
|
40
|
-
const existingMeta = document.querySelector( 'meta[http-equiv="origin-trial"]' );
|
|
41
|
-
if ( ! existingMeta && data?.chromeAiTokens ) {
|
|
42
|
-
// iterate through chromeAiTokens and create a meta tag for each one
|
|
43
|
-
Object.keys( data.chromeAiTokens ).forEach( token => {
|
|
44
|
-
const otMeta = document.createElement( 'meta' );
|
|
45
|
-
otMeta.httpEquiv = 'origin-trial';
|
|
46
|
-
otMeta.content = data.chromeAiTokens[ token ];
|
|
47
|
-
document.head.appendChild( otMeta );
|
|
48
|
-
} );
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}, [ loading, data ] );
|
|
52
|
-
|
|
53
37
|
return useMemo( () => {
|
|
54
38
|
const planType = getPlanType( data?.currentTier );
|
|
55
39
|
const currentTierLimit = data?.currentTier?.limit || data?.requestsLimit;
|