@automattic/jetpack-ai-client 0.33.32 → 0.34.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,20 @@ 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.34.1] - 2026-02-16
9
+ ### Fixed
10
+ - Compatibility: Clean up deprecated CSS. [#47067]
11
+
12
+ ## [0.34.0] - 2026-02-10
13
+ ### Added
14
+ - AI Client: Add explicit window interface with missing types. [#46938]
15
+
16
+ ### Changed
17
+ - Update package dependencies. [#46905]
18
+
19
+ ### Removed
20
+ - Remove Chrome AI built-in API integration code. [#46896]
21
+
8
22
  ## [0.33.32] - 2026-02-02
9
23
  ### Changed
10
24
  - Update package dependencies. [#46854]
@@ -790,6 +804,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
790
804
  - AI Client: stop using smart document visibility handling on the fetchEventSource library, so it does not restart the completion when changing tabs. [#32004]
791
805
  - Updated package dependencies. [#31468] [#31659] [#31785]
792
806
 
807
+ [0.34.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.34.0...v0.34.1
808
+ [0.34.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.33.32...v0.34.0
793
809
  [0.33.32]: https://github.com/Automattic/jetpack-ai-client/compare/v0.33.31...v0.33.32
794
810
  [0.33.31]: https://github.com/Automattic/jetpack-ai-client/compare/v0.33.30...v0.33.31
795
811
  [0.33.30]: https://github.com/Automattic/jetpack-ai-client/compare/v0.33.29...v0.33.30
@@ -30,5 +30,4 @@ export default function useAiFeature(): {
30
30
  };
31
31
  };
32
32
  featuresControl?: import("@automattic/jetpack-shared-extension-utils/store/wordpress-com/types").FeaturesControl;
33
- chromeAiTokens?: import("@automattic/jetpack-shared-extension-utils/store/wordpress-com/types").ChromeAiTokens;
34
33
  };
@@ -18,10 +18,10 @@ type useAiSuggestionsOptions = {
18
18
  askQuestionOptions?: AskQuestionOptionsArgProps;
19
19
  initialRequestingState?: RequestingStateProp;
20
20
  onSuggestion?: (suggestion: string) => void;
21
- onDone?: (content: string, skipRequestCount?: boolean, modelUsed?: AiModelTypeProp) => void;
21
+ onDone?: (content: string, modelUsed?: AiModelTypeProp) => void;
22
22
  onStop?: () => void;
23
23
  onError?: (error: RequestingErrorProps) => void;
24
- onAllErrors?: (error: RequestingErrorProps, skipRequestCount?: boolean) => void;
24
+ onAllErrors?: (error: RequestingErrorProps) => void;
25
25
  };
26
26
  type useAiSuggestionsProps = {
27
27
  suggestion: string;
@@ -8,8 +8,7 @@ import debugFactory from 'debug';
8
8
  * Internal dependencies
9
9
  */
10
10
  import askQuestion from "../../ask-question/index.js";
11
- import ChromeAIFactory from "../../chrome-ai/factory.js";
12
- import { ERROR_CONTEXT_TOO_LARGE, ERROR_MODERATION, ERROR_NETWORK, ERROR_QUOTA_EXCEEDED, ERROR_SERVICE_UNAVAILABLE, ERROR_UNCLEAR_PROMPT, ERROR_RESPONSE, AI_MODEL_DEFAULT, AI_MODEL_GEMINI_NANO, } from "../../types.js";
11
+ import { ERROR_CONTEXT_TOO_LARGE, ERROR_MODERATION, ERROR_NETWORK, ERROR_QUOTA_EXCEEDED, ERROR_SERVICE_UNAVAILABLE, ERROR_UNCLEAR_PROMPT, ERROR_RESPONSE, AI_MODEL_DEFAULT, } from "../../types.js";
13
12
  const debug = debugFactory('ai-client:use-ai-suggestions');
14
13
  /**
15
14
  * Get the error data for a given error code.
@@ -111,11 +110,11 @@ export default function useAiSuggestions({ prompt, autoRequest = false, askQuest
111
110
  const handleDone = useCallback((event) => {
112
111
  closeEventSource();
113
112
  const fullSuggestion = removeLlamaArtifact(event?.detail?.message ?? event?.detail);
114
- onDone?.(fullSuggestion, event?.detail?.source === 'chromeAI', modelRef.current);
113
+ onDone?.(fullSuggestion, modelRef.current);
115
114
  setRequestingState('done');
116
115
  }, [onDone]);
117
116
  const handleAnyError = useCallback((event) => {
118
- onAllErrors?.(event?.detail, event?.detail?.source === 'chromeAI');
117
+ onAllErrors?.(event?.detail);
119
118
  }, [onAllErrors]);
120
119
  const handleError = useCallback((errorCode) => {
121
120
  eventSourceRef?.current?.close();
@@ -140,17 +139,8 @@ export default function useAiSuggestions({ prompt, autoRequest = false, askQuest
140
139
  setError(undefined);
141
140
  // Set the request status.
142
141
  setRequestingState('requesting');
143
- // check if we can (or should) use Chrome AI
144
- const chromeAI = await ChromeAIFactory(promptArg);
145
- debug('chromeAI', chromeAI !== false);
146
- if (chromeAI !== false) {
147
- setModelAndRef(AI_MODEL_GEMINI_NANO);
148
- eventSourceRef.current = chromeAI;
149
- }
150
- else {
151
- setModelAndRef(AI_MODEL_DEFAULT);
152
- eventSourceRef.current = await askQuestion(promptArg, options);
153
- }
142
+ setModelAndRef(AI_MODEL_DEFAULT);
143
+ eventSourceRef.current = await askQuestion(promptArg, options);
154
144
  if (!eventSourceRef?.current) {
155
145
  debug('no event source');
156
146
  return;
package/build/index.d.ts CHANGED
@@ -20,7 +20,3 @@ export * from './types.ts';
20
20
  export * from './libs/index.ts';
21
21
  export * from './constants.ts';
22
22
  export * from './logo-generator/index.ts';
23
- /**
24
- * Chrome AI
25
- */
26
- export * from './chrome-ai/index.ts';
package/build/index.js CHANGED
@@ -47,7 +47,3 @@ export * from "./constants.js";
47
47
  * Logo Generator
48
48
  */
49
49
  export * from "./logo-generator/index.js";
50
- /**
51
- * Chrome AI
52
- */
53
- export * from "./chrome-ai/index.js";
package/build/types.d.ts CHANGED
@@ -30,8 +30,7 @@ export type RequestingStateProp = (typeof REQUESTING_STATES)[number];
30
30
  export declare const AI_MODEL_GPT_3_5_Turbo_16K: "gpt-3.5-turbo-16k";
31
31
  export declare const AI_MODEL_GPT_4: "gpt-4";
32
32
  export declare const AI_MODEL_DEFAULT: "default";
33
- export declare const AI_MODEL_GEMINI_NANO: "gemini-nano";
34
- export type AiModelTypeProp = typeof AI_MODEL_GPT_3_5_Turbo_16K | typeof AI_MODEL_GPT_4 | typeof AI_MODEL_GEMINI_NANO | typeof AI_MODEL_DEFAULT;
33
+ export type AiModelTypeProp = typeof AI_MODEL_GPT_3_5_Turbo_16K | typeof AI_MODEL_GPT_4 | typeof AI_MODEL_DEFAULT;
35
34
  export type { RecordingState } from './hooks/use-media-recording/index.ts';
36
35
  export type CancelablePromise<T = void> = Promise<T> & {
37
36
  canceled?: boolean;
@@ -53,43 +52,3 @@ export interface BlockEditorStore {
53
52
  [key in keyof typeof BlockEditorSelectors]: (typeof BlockEditorSelectors)[key];
54
53
  };
55
54
  }
56
- declare global {
57
- interface Window {
58
- LanguageDetector?: {
59
- create: () => Promise<{
60
- detect: (text: string) => Promise<{
61
- detectedLanguage: string;
62
- confidence: number;
63
- }[]>;
64
- ready: Promise<void>;
65
- }>;
66
- availability: () => Promise<'unavailable' | 'available' | 'downloadable' | 'downloading' | string>;
67
- };
68
- Translator?: {
69
- create: (options: {
70
- sourceLanguage: string;
71
- targetLanguage: string;
72
- }) => Promise<{
73
- translate: (text: string) => Promise<string>;
74
- }>;
75
- availability: (options: {
76
- sourceLanguage: string;
77
- targetLanguage: string;
78
- }) => Promise<'unavailable' | 'available' | 'downloadable' | 'downloading' | string>;
79
- };
80
- Summarizer?: {
81
- availability: () => Promise<'unavailable' | 'available' | 'downloadable' | 'downloading' | string>;
82
- create: (options: {
83
- sharedContext?: string;
84
- type?: string;
85
- format?: string;
86
- length?: string;
87
- }) => Promise<{
88
- ready: Promise<void>;
89
- summarize: (text: string, summarizeOptions?: {
90
- context?: string;
91
- }) => Promise<string>;
92
- }>;
93
- };
94
- }
95
- }
package/build/types.js CHANGED
@@ -34,4 +34,3 @@ export const REQUESTING_STATES = [
34
34
  export const AI_MODEL_GPT_3_5_Turbo_16K = 'gpt-3.5-turbo-16k';
35
35
  export const AI_MODEL_GPT_4 = 'gpt-4';
36
36
  export const AI_MODEL_DEFAULT = 'default';
37
- export const AI_MODEL_GEMINI_NANO = 'gemini-nano';
@@ -0,0 +1,5 @@
1
+ import type { ConnectionScriptData } from '@automattic/jetpack-connection';
2
+
3
+ interface Window {
4
+ JP_CONNECTION_INITIAL_STATE: ConnectionScriptData;
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/jetpack-ai-client",
3
- "version": "0.33.32",
3
+ "version": "0.34.1",
4
4
  "private": false,
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",
@@ -33,12 +33,12 @@
33
33
  "watch": "tsc --watch --pretty"
34
34
  },
35
35
  "dependencies": {
36
- "@automattic/jetpack-base-styles": "^1.0.15",
37
- "@automattic/jetpack-components": "^1.4.9",
38
- "@automattic/jetpack-connection": "^1.4.30",
36
+ "@automattic/jetpack-base-styles": "^1.0.16",
37
+ "@automattic/jetpack-components": "^1.4.13",
38
+ "@automattic/jetpack-connection": "^1.4.34",
39
39
  "@automattic/jetpack-explat": "workspace:*",
40
40
  "@automattic/jetpack-script-data": "^0.5.4",
41
- "@automattic/jetpack-shared-extension-utils": "^1.4.8",
41
+ "@automattic/jetpack-shared-extension-utils": "^1.4.12",
42
42
  "@microsoft/fetch-event-source": "2.0.1",
43
43
  "@types/jest": "30.0.0",
44
44
  "@types/react": "18.3.26",
@@ -65,13 +65,13 @@
65
65
  "turndown": "7.1.2"
66
66
  },
67
67
  "devDependencies": {
68
- "@storybook/addon-docs": "10.1.10",
69
- "@storybook/react": "10.1.10",
68
+ "@storybook/addon-docs": "10.2.3",
69
+ "@storybook/react": "10.2.3",
70
70
  "@testing-library/dom": "10.4.1",
71
71
  "@types/markdown-it": "14.1.2",
72
72
  "@types/turndown": "5.0.6",
73
73
  "jest": "30.2.0",
74
- "storybook": "10.1.10",
74
+ "storybook": "10.2.3",
75
75
  "typescript": "5.9.3"
76
76
  }
77
77
  }
@@ -8,7 +8,6 @@ import debugFactory from 'debug';
8
8
  * Internal dependencies
9
9
  */
10
10
  import askQuestion from '../../ask-question/index.ts';
11
- import ChromeAIFactory from '../../chrome-ai/factory.ts';
12
11
  import {
13
12
  ERROR_CONTEXT_TOO_LARGE,
14
13
  ERROR_MODERATION,
@@ -18,7 +17,6 @@ import {
18
17
  ERROR_UNCLEAR_PROMPT,
19
18
  ERROR_RESPONSE,
20
19
  AI_MODEL_DEFAULT,
21
- AI_MODEL_GEMINI_NANO,
22
20
  } from '../../types.ts';
23
21
  /**
24
22
  * Types & constants
@@ -80,7 +78,7 @@ type useAiSuggestionsOptions = {
80
78
  /*
81
79
  * onDone callback.
82
80
  */
83
- onDone?: ( content: string, skipRequestCount?: boolean, modelUsed?: AiModelTypeProp ) => void;
81
+ onDone?: ( content: string, modelUsed?: AiModelTypeProp ) => void;
84
82
 
85
83
  /*
86
84
  * onStop callback.
@@ -95,7 +93,7 @@ type useAiSuggestionsOptions = {
95
93
  /*
96
94
  * Error callback common for all errors.
97
95
  */
98
- onAllErrors?: ( error: RequestingErrorProps, skipRequestCount?: boolean ) => void;
96
+ onAllErrors?: ( error: RequestingErrorProps ) => void;
99
97
  };
100
98
 
101
99
  type useAiSuggestionsProps = {
@@ -281,7 +279,7 @@ export default function useAiSuggestions( {
281
279
 
282
280
  const fullSuggestion = removeLlamaArtifact( event?.detail?.message ?? event?.detail );
283
281
 
284
- onDone?.( fullSuggestion, event?.detail?.source === 'chromeAI', modelRef.current );
282
+ onDone?.( fullSuggestion, modelRef.current );
285
283
  setRequestingState( 'done' );
286
284
  },
287
285
  [ onDone ]
@@ -289,7 +287,7 @@ export default function useAiSuggestions( {
289
287
 
290
288
  const handleAnyError = useCallback(
291
289
  ( event: CustomEvent ) => {
292
- onAllErrors?.( event?.detail, event?.detail?.source === 'chromeAI' );
290
+ onAllErrors?.( event?.detail );
293
291
  },
294
292
  [ onAllErrors ]
295
293
  );
@@ -338,17 +336,8 @@ export default function useAiSuggestions( {
338
336
  // Set the request status.
339
337
  setRequestingState( 'requesting' );
340
338
 
341
- // check if we can (or should) use Chrome AI
342
- const chromeAI = await ChromeAIFactory( promptArg );
343
- debug( 'chromeAI', chromeAI !== false );
344
-
345
- if ( chromeAI !== false ) {
346
- setModelAndRef( AI_MODEL_GEMINI_NANO );
347
- eventSourceRef.current = chromeAI;
348
- } else {
349
- setModelAndRef( AI_MODEL_DEFAULT );
350
- eventSourceRef.current = await askQuestion( promptArg, options );
351
- }
339
+ setModelAndRef( AI_MODEL_DEFAULT );
340
+ eventSourceRef.current = await askQuestion( promptArg, options );
352
341
 
353
342
  if ( ! eventSourceRef?.current ) {
354
343
  debug( 'no event source' );
package/src/index.ts CHANGED
@@ -55,8 +55,3 @@ export * from './constants.ts';
55
55
  * Logo Generator
56
56
  */
57
57
  export * from './logo-generator/index.ts';
58
-
59
- /**
60
- * Chrome AI
61
- */
62
- export * from './chrome-ai/index.ts';
@@ -68,7 +68,7 @@
68
68
  vertical-align: baseline;
69
69
  color: var(--studio-gray-100);
70
70
  line-height: 1.6;
71
- word-break: break-word;
71
+ overflow-wrap: break-word;
72
72
 
73
73
  &:focus,
74
74
  &:active {
@@ -13,7 +13,7 @@
13
13
  .jetpack-upgrade-plan-banner .jetpack-upgrade-plan-banner__wrapper .jetpack-upgrade-plan-banner__banner-description {
14
14
  color: var(--jp-white);
15
15
  line-height: 21px;
16
- word-wrap: break-word;
16
+ overflow-wrap: break-word;
17
17
  vertical-align: middle;
18
18
  }
19
19
 
package/src/types.ts CHANGED
@@ -94,12 +94,9 @@ export type RequestingStateProp = ( typeof REQUESTING_STATES )[ number ];
94
94
  export const AI_MODEL_GPT_3_5_Turbo_16K = 'gpt-3.5-turbo-16k' as const;
95
95
  export const AI_MODEL_GPT_4 = 'gpt-4' as const;
96
96
  export const AI_MODEL_DEFAULT = 'default' as const;
97
- export const AI_MODEL_GEMINI_NANO = 'gemini-nano' as const;
98
-
99
97
  export type AiModelTypeProp =
100
98
  | typeof AI_MODEL_GPT_3_5_Turbo_16K
101
99
  | typeof AI_MODEL_GPT_4
102
- | typeof AI_MODEL_GEMINI_NANO
103
100
  | typeof AI_MODEL_DEFAULT;
104
101
 
105
102
  /*
@@ -138,46 +135,3 @@ export interface BlockEditorStore {
138
135
  [ key in keyof typeof BlockEditorSelectors ]: ( typeof BlockEditorSelectors )[ key ];
139
136
  };
140
137
  }
141
-
142
- declare global {
143
- interface Window {
144
- LanguageDetector?: {
145
- create: () => Promise< {
146
- detect: ( text: string ) => Promise<
147
- {
148
- detectedLanguage: string;
149
- confidence: number;
150
- }[]
151
- >;
152
- ready: Promise< void >;
153
- } >;
154
- availability: () => Promise<
155
- 'unavailable' | 'available' | 'downloadable' | 'downloading' | string
156
- >;
157
- };
158
- Translator?: {
159
- create: ( options: {
160
- sourceLanguage: string;
161
- targetLanguage: string;
162
- } ) => Promise< { translate: ( text: string ) => Promise< string > } >;
163
- availability: ( options: {
164
- sourceLanguage: string;
165
- targetLanguage: string;
166
- } ) => Promise< 'unavailable' | 'available' | 'downloadable' | 'downloading' | string >;
167
- };
168
- Summarizer?: {
169
- availability: () => Promise<
170
- 'unavailable' | 'available' | 'downloadable' | 'downloading' | string
171
- >;
172
- create: ( options: {
173
- sharedContext?: string;
174
- type?: string;
175
- format?: string;
176
- length?: string;
177
- } ) => Promise< {
178
- ready: Promise< void >;
179
- summarize: ( text: string, summarizeOptions?: { context?: string } ) => Promise< string >;
180
- } >;
181
- };
182
- }
183
- }
@@ -1,9 +0,0 @@
1
- import { PromptProp } from '../types.ts';
2
- import ChromeAISuggestionsEventSource from './suggestions.ts';
3
- /**
4
- * This will return an instance of ChromeAISuggestionsEventSource or false.
5
- *
6
- * @param promptArg - The messages array of the prompt.
7
- * @return ChromeAISuggestionsEventSource | bool
8
- */
9
- export default function ChromeAIFactory(promptArg: PromptProp): Promise<false | ChromeAISuggestionsEventSource>;
@@ -1,150 +0,0 @@
1
- import debugFactory from 'debug';
2
- import { PROMPT_TYPE_CHANGE_LANGUAGE, PROMPT_TYPE_SUMMARIZE } from "../constants.js";
3
- import { isChromeAIAvailable } from "./get-availability.js";
4
- import ChromeAISuggestionsEventSource from "./suggestions.js";
5
- const debug = debugFactory('ai-client:chrome-ai-factory');
6
- /**
7
- * This will return an instance of ChromeAISuggestionsEventSource or false.
8
- *
9
- * @param promptArg - The messages array of the prompt.
10
- * @return ChromeAISuggestionsEventSource | bool
11
- */
12
- export default async function ChromeAIFactory(promptArg) {
13
- if (!(await isChromeAIAvailable())) {
14
- debug('Chrome AI is not available');
15
- return false;
16
- }
17
- const context = {
18
- content: '',
19
- language: '',
20
- };
21
- let promptType = '';
22
- let tone = null;
23
- let wordCount = null;
24
- debug('promptArg', promptArg);
25
- if (Array.isArray(promptArg)) {
26
- for (let i = 0; i < promptArg.length; i++) {
27
- const prompt = promptArg[i];
28
- if (prompt.content) {
29
- context.content = prompt.content;
30
- }
31
- if (!('context' in prompt)) {
32
- continue;
33
- }
34
- const promptContext = prompt.context;
35
- if (promptContext.type) {
36
- promptType = promptContext.type;
37
- }
38
- if (promptContext.language) {
39
- context.language = promptContext.language;
40
- }
41
- if (promptContext.content) {
42
- context.content = promptContext.content;
43
- }
44
- if (promptContext.tone) {
45
- tone = promptContext.tone;
46
- }
47
- if (promptContext.words) {
48
- wordCount = promptContext.words;
49
- }
50
- }
51
- }
52
- debug('promptType', promptType);
53
- // Early return if the prompt type is not supported.
54
- if (!promptType.startsWith('ai-assistant-change-language') &&
55
- !promptType.startsWith('ai-content-lens')) {
56
- debug('promptType is not supported');
57
- return false;
58
- }
59
- // If the languageDetector is not available, we can't use the translation or summary features—it's safer to fall back
60
- // to the default AI model than to risk an unexpected error.
61
- if (!('LanguageDetector' in self) ||
62
- !self.LanguageDetector.create ||
63
- !self.LanguageDetector.availability) {
64
- debug('LanguageDetector is not available');
65
- return false;
66
- }
67
- const languageDetectorAvailability = await self.LanguageDetector.availability();
68
- if (languageDetectorAvailability === 'unavailable') {
69
- debug('LanguageDetector is unavailable');
70
- return false;
71
- }
72
- const detector = await self.LanguageDetector.create();
73
- if (languageDetectorAvailability !== 'available') {
74
- debug('awaiting detector ready');
75
- await detector.ready;
76
- }
77
- if (promptType.startsWith('ai-assistant-change-language')) {
78
- const [language] = context.language.split(' ');
79
- if (!('Translator' in self) ||
80
- !self.Translator.create ||
81
- !self.Translator.availability) {
82
- debug('Translator is not available');
83
- return false;
84
- }
85
- const languageOpts = {
86
- sourceLanguage: 'en',
87
- targetLanguage: language,
88
- };
89
- const confidences = await detector.detect(context.content);
90
- for (const confidence of confidences) {
91
- // 75% confidence is just a value that was picked. Generally
92
- // 80% of higher is pretty safe, but the source language is
93
- // required for the translator to work at all, which is also
94
- // why en is the default language.
95
- if (confidence.confidence > 0.75) {
96
- languageOpts.sourceLanguage = confidence.detectedLanguage;
97
- break;
98
- }
99
- }
100
- debug('languageOpts', languageOpts);
101
- const translationAvailability = await self.Translator.availability(languageOpts);
102
- debug('translationAvailability', translationAvailability);
103
- if (translationAvailability === 'unavailable') {
104
- debug('Translator is unavailable');
105
- return false;
106
- }
107
- const chromeAI = new ChromeAISuggestionsEventSource({
108
- content: context.content,
109
- promptType: PROMPT_TYPE_CHANGE_LANGUAGE,
110
- options: languageOpts,
111
- });
112
- return chromeAI;
113
- }
114
- if (promptType.startsWith('ai-content-lens')) {
115
- if (!('Summarizer' in self)) {
116
- debug('Summarizer is not available');
117
- return false;
118
- }
119
- if (context.language && context.language !== 'en (English)') {
120
- debug('Summary is not English');
121
- return false;
122
- }
123
- debug('awaiting detector detect');
124
- const confidences = await detector.detect(context.content);
125
- // if it doesn't look like the content is in English, we can't use the summary feature
126
- for (const confidence of confidences) {
127
- // 75% confidence is just a value that was picked. Generally
128
- // 80% of higher is pretty safe, but the source language is
129
- // required for the translator to work at all, which is also
130
- // why en is the default language.
131
- if (confidence.confidence > 0.75 && confidence.detectedLanguage !== 'en') {
132
- debug('Confidence for non-English content');
133
- return false;
134
- }
135
- }
136
- const summaryOpts = {
137
- tone: tone,
138
- wordCount: wordCount,
139
- };
140
- debug('summaryOpts', summaryOpts);
141
- const chromeAiEventSourceOpts = {
142
- content: context.content,
143
- promptType: PROMPT_TYPE_SUMMARIZE,
144
- options: summaryOpts,
145
- };
146
- debug('chromeAiEventSourceOpts', chromeAiEventSourceOpts);
147
- return new ChromeAISuggestionsEventSource(chromeAiEventSourceOpts);
148
- }
149
- return false;
150
- }
@@ -1,7 +0,0 @@
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(): Promise<boolean>;
7
- export default isChromeAIAvailable;
@@ -1,67 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { initializeExPlat, createExPlatClient } from '@automattic/jetpack-explat';
5
- import { select } from '@wordpress/data';
6
- import { addQueryArgs } from '@wordpress/url';
7
- import debugFactory from 'debug';
8
- /**
9
- * Internal dependencies
10
- */
11
- import apiFetch from "../api-fetch/index.js";
12
- const debug = debugFactory('ai-client:chrome-ai-availability');
13
- /**
14
- * Get the AI Assistant feature.
15
- *
16
- * @return {object} The AI Assistant feature.
17
- */
18
- function getAiAssistantFeature() {
19
- const { getAiAssistantFeature: getFeature } = select('wordpress-com/plans');
20
- return getFeature();
21
- }
22
- /**
23
- * Fetch an experiment assignment.
24
- *
25
- * @param {boolean} asConnectedUser - Whether the user is connected.
26
- * @return {Function} A function that fetches an experiment assignment.
27
- */
28
- const fetchExperimentAssignmentWithConnectedUser = async ({ experimentName, }) => {
29
- const params = {
30
- experiment_name: experimentName,
31
- anon_id: undefined,
32
- as_connected_user: true,
33
- };
34
- debug('params', params);
35
- const assignmentsRequestUrl = addQueryArgs('https://public-api.wordpress.com/wpcom/v2/experiments/0.1.0/assignments/jetpack', params);
36
- debug('assignmentsRequestUrl', assignmentsRequestUrl);
37
- return apiFetch({
38
- url: assignmentsRequestUrl,
39
- credentials: 'include',
40
- mode: 'cors',
41
- global: true,
42
- });
43
- };
44
- /**
45
- * Check if Chrome AI can be enabled.
46
- *
47
- * @return {boolean} Whether Chrome AI can be enabled.
48
- */
49
- export async function isChromeAIAvailable() {
50
- const { featuresControl } = getAiAssistantFeature();
51
- // Extra check if we want to control this via the feature flag for now
52
- if (featuresControl?.['chrome-ai']?.enabled !== true) {
53
- debug('feature is disabled for this site/user');
54
- return false;
55
- }
56
- initializeExPlat();
57
- const { loadExperimentAssignment: loadExperimentAssignmentWithAuth } = createExPlatClient({
58
- fetchExperimentAssignment: fetchExperimentAssignmentWithConnectedUser,
59
- getAnonId: async () => null,
60
- logError: debug,
61
- isDevelopmentMode: false,
62
- });
63
- const { variationName } = await loadExperimentAssignmentWithAuth('calypso_jetpack_ai_gemini_api_202503_v2');
64
- debug('variationName', variationName);
65
- return variationName === 'treatment';
66
- }
67
- export default isChromeAIAvailable;
@@ -1,2 +0,0 @@
1
- export { default as ChromeAIFactory } from './factory.ts';
2
- export { default as ChromeAISuggestionsEventSource } from './suggestions.ts';
@@ -1,2 +0,0 @@
1
- export { default as ChromeAIFactory } from "./factory.js";
2
- export { default as ChromeAISuggestionsEventSource } from "./suggestions.js";
@@ -1,38 +0,0 @@
1
- import { EventSourceMessage } from '@microsoft/fetch-event-source';
2
- import { AiModelTypeProp } from '../types.ts';
3
- type ChromeAISuggestionsEventSourceConstructorArgs = {
4
- content: string;
5
- promptType: string;
6
- options?: {
7
- postId?: number | string;
8
- feature?: 'ai-assistant-experimental' | string | undefined;
9
- sourceLanguage?: string;
10
- targetLanguage?: string;
11
- tone?: string;
12
- wordCount?: number;
13
- functions?: Array<object>;
14
- model?: AiModelTypeProp;
15
- };
16
- };
17
- type FunctionCallProps = {
18
- name?: string;
19
- arguments?: string;
20
- };
21
- export default class ChromeAISuggestionsEventSource extends EventTarget {
22
- fullMessage: string;
23
- fullFunctionCall: FunctionCallProps;
24
- isPromptClear: boolean;
25
- controller: AbortController;
26
- errorUnclearPromptTriggered: boolean;
27
- constructor(data: ChromeAISuggestionsEventSourceConstructorArgs);
28
- initSource({ content, promptType, options, }: ChromeAISuggestionsEventSourceConstructorArgs): void;
29
- initEventSource(): Promise<void>;
30
- close(): void;
31
- checkForUnclearPrompt(): void;
32
- processEvent(e: EventSourceMessage): void;
33
- processErrorEvent(e: any): void;
34
- translate(text: string, target: string, source?: string): Promise<void>;
35
- private getSummarizerOptions;
36
- summarize(text: string, tone?: string, wordCount?: number): Promise<void>;
37
- }
38
- export {};