@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 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 (!shouldUseChromeAI()) {
11
+ if (!isChromeAIAvailable()) {
20
12
  return false;
21
13
  }
22
14
  const context = {
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if Chrome AI can be enabled.
3
+ *
4
+ * @return {boolean} Whether Chrome AI can be enabled.
5
+ */
6
+ export declare function isChromeAIAvailable(): boolean;
7
+ export default isChromeAIAvailable;
@@ -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, useEffect } from '@wordpress/element';
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.29.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.2"
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.7.4",
49
- "@automattic/jetpack-components": "^0.73.1",
50
- "@automattic/jetpack-connection": "^0.39.15",
51
- "@automattic/jetpack-shared-extension-utils": "^0.20.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.18",
54
+ "@types/react": "18.3.23",
55
55
  "@types/wordpress__block-editor": "11.5.16",
56
- "@wordpress/api-fetch": "7.22.0",
57
- "@wordpress/base-styles": "5.22.0",
58
- "@wordpress/blob": "4.22.0",
59
- "@wordpress/blocks": "14.11.0",
60
- "@wordpress/block-editor": "14.17.0",
61
- "@wordpress/components": "29.8.0",
62
- "@wordpress/compose": "7.22.0",
63
- "@wordpress/data": "10.22.0",
64
- "@wordpress/editor": "14.22.0",
65
- "@wordpress/element": "6.22.0",
66
- "@wordpress/i18n": "5.22.0",
67
- "@wordpress/icons": "10.22.0",
68
- "@wordpress/primitives": "4.22.0",
69
- "@wordpress/url": "4.22.0",
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.0",
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",
@@ -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 ( ! shouldUseChromeAI() ) {
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;
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/root-variables';
1
+ @use '@automattic/jetpack-base-styles/root-variables';
2
2
 
3
3
  .jetpack-components-ai-control__container-wrapper {
4
4
  position: sticky;
@@ -1,5 +1,3 @@
1
- @import "@wordpress/base-styles/colors";
2
-
3
1
  .ai-assistant-feedback {
4
2
 
5
3
  &__selection {
@@ -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
  }
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/style';
1
+ @use '@automattic/jetpack-base-styles/style';
2
2
 
3
3
  .ai-assistant-featured-image__usage-counter {
4
4
  color: var(--studio-gray-50, #646970);
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/style';
1
+ @use '@automattic/jetpack-base-styles/style';
2
2
 
3
3
  .jetpack-ai-status-indicator__icon-wrapper {
4
4
  transition: opacity 0.25s ease-in-out, width 0.25s;
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/root-variables';
1
+ @use '@automattic/jetpack-base-styles/root-variables';
2
2
 
3
3
  .jetpack-ai-assistant__message {
4
4
  display: flex;
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/style';
1
+ @use '@automattic/jetpack-base-styles/style';
2
2
 
3
3
  .jetpack-upgrade-plan-banner__wrapper {
4
4
  column-gap: 32px;
@@ -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, useEffect } from '@wordpress/element';
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;
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/root-variables';
1
+ @use '@automattic/jetpack-base-styles/root-variables';
2
2
 
3
3
  .jetpack-ai-logo-generator-modal {
4
4
 
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/root-variables';
1
+ @use '@automattic/jetpack-base-styles/root-variables';
2
2
 
3
3
  .jetpack-ai-logo-generator__carousel {
4
4
  display: flex;
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/root-variables';
1
+ @use '@automattic/jetpack-base-styles/root-variables';
2
2
 
3
3
  .jetpack-ai-logo-generator-modal-presenter__wrapper {
4
4
  display: flex;
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/root-variables';
1
+ @use '@automattic/jetpack-base-styles/root-variables';
2
2
 
3
3
  .jetpack-ai-logo-generator__prompt {
4
4
  display: flex;
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/root-variables';
1
+ @use '@automattic/jetpack-base-styles/root-variables';
2
2
 
3
3
  .jetpack-upgrade-plan-banner .jetpack-upgrade-plan-banner__wrapper {
4
4
  display: flex;
@@ -1,4 +1,4 @@
1
- @import '@automattic/jetpack-base-styles/root-variables';
1
+ @use '@automattic/jetpack-base-styles/root-variables';
2
2
 
3
3
  .jetpack-ai-logo-generator-modal-visit-site-banner {
4
4
  border-radius: 4px;