@automattic/jetpack-ai-client 0.33.26 → 0.33.27

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,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.33.27] - 2026-01-06
9
+ ### Added
10
+ - Add site language code to AI request. [#46410]
11
+
8
12
  ## [0.33.26] - 2025-12-22
9
13
  ### Changed
10
14
  - Update package dependencies. [#46362] [#46363]
@@ -766,6 +770,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
766
770
  - AI Client: stop using smart document visibility handling on the fetchEventSource library, so it does not restart the completion when changing tabs. [#32004]
767
771
  - Updated package dependencies. [#31468] [#31659] [#31785]
768
772
 
773
+ [0.33.27]: https://github.com/Automattic/jetpack-ai-client/compare/v0.33.26...v0.33.27
769
774
  [0.33.26]: https://github.com/Automattic/jetpack-ai-client/compare/v0.33.25...v0.33.26
770
775
  [0.33.25]: https://github.com/Automattic/jetpack-ai-client/compare/v0.33.24...v0.33.25
771
776
  [0.33.24]: https://github.com/Automattic/jetpack-ai-client/compare/v0.33.23...v0.33.24
@@ -1,4 +1,10 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
1
4
  import SuggestionsEventSource from '../suggestions-event-source/index.ts';
5
+ /**
6
+ * Types & constants
7
+ */
2
8
  import type { AiModelTypeProp, PromptProp } from '../types.ts';
3
9
  export type AskQuestionOptionsArgProps = {
4
10
  postId?: number;
@@ -10,6 +16,7 @@ export type AskQuestionOptionsArgProps = {
10
16
  arguments?: string;
11
17
  implementation?: Function;
12
18
  }>;
19
+ languageCode?: string;
13
20
  };
14
21
  /**
15
22
  * An asynchronous function that asks a question
@@ -29,4 +36,4 @@ export type AskQuestionOptionsArgProps = {
29
36
  * // handle suggestionsEventSource
30
37
  * } );
31
38
  */
32
- export default function askQuestion(question: PromptProp, { postId, fromCache, feature, functions, model }?: AskQuestionOptionsArgProps): Promise<SuggestionsEventSource>;
39
+ export default function askQuestion(question: PromptProp, { postId, fromCache, feature, functions, model, languageCode, }?: AskQuestionOptionsArgProps): Promise<SuggestionsEventSource>;
@@ -1,7 +1,11 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
+ import { select } from '@wordpress/data';
4
5
  import debugFactory from 'debug';
6
+ /**
7
+ * Internal dependencies
8
+ */
5
9
  import SuggestionsEventSource from "../suggestions-event-source/index.js";
6
10
  const debug = debugFactory('jetpack-ai-client:ask-question');
7
11
  /**
@@ -22,16 +26,25 @@ const debug = debugFactory('jetpack-ai-client:ask-question');
22
26
  * // handle suggestionsEventSource
23
27
  * } );
24
28
  */
25
- export default async function askQuestion(question, { postId = null, fromCache = false, feature, functions, model } = {}) {
29
+ export default async function askQuestion(question, { postId = null, fromCache = false, feature, functions, model, languageCode, } = {}) {
30
+ const code = languageCode || select('core').getEntityRecord('root', 'site')?.language || 'en_US';
26
31
  debug('Asking question: %o. options: %o', question, {
27
32
  postId,
28
33
  fromCache,
29
34
  feature,
30
35
  functions,
31
36
  model,
37
+ languageCode: code,
32
38
  });
33
39
  return new SuggestionsEventSource({
34
40
  question,
35
- options: { postId, feature, fromCache, functions, model },
41
+ options: {
42
+ postId,
43
+ feature,
44
+ fromCache,
45
+ functions,
46
+ model,
47
+ languageCode: code,
48
+ },
36
49
  });
37
50
  }
@@ -1,4 +1,7 @@
1
- import { AskQuestionOptionsArgProps } from './index.ts';
1
+ /**
2
+ * Types & constants
3
+ */
4
+ import type { AskQuestionOptionsArgProps } from './index.ts';
2
5
  import type { PromptProp } from '../types.ts';
3
6
  /**
4
7
  * The response data from the AI assistant when doing a sync, not-streamed question.
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
+ import { select } from '@wordpress/data';
4
5
  import debugFactory from 'debug';
5
- /*
6
- * Types & constants
6
+ /**
7
+ * Internal dependencies
7
8
  */
8
9
  import requestJwt from "../jwt/index.js";
9
10
  const debug = debugFactory('jetpack-ai-client:ask-question-sync');
@@ -25,6 +26,8 @@ const debug = debugFactory('jetpack-ai-client:ask-question-sync');
25
26
  * } );
26
27
  */
27
28
  export default async function askQuestionSync(question, options = {}) {
29
+ options.languageCode =
30
+ options.languageCode || select('core').getEntityRecord('root', 'site')?.language || 'en_US';
28
31
  debug('Asking question with no streaming: %o. options: %o', question, options);
29
32
  /**
30
33
  * The URL to the AI assistant query endpoint.
@@ -13,6 +13,7 @@ type SuggestionsEventSourceConstructorArgs = {
13
13
  fromCache?: boolean;
14
14
  functions?: Array<object>;
15
15
  model?: AiModelTypeProp;
16
+ languageCode?: string;
16
17
  };
17
18
  };
18
19
  type FunctionCallProps = {
@@ -100,6 +100,10 @@ export default class SuggestionsEventSource extends EventTarget {
100
100
  debug('Model: %o', options.model);
101
101
  bodyData.model = options.model;
102
102
  }
103
+ if (options?.languageCode?.length) {
104
+ debug('Language: %o', options.languageCode);
105
+ bodyData.language_code = options.languageCode;
106
+ }
103
107
  // Clean the unclear prompt trigger flag
104
108
  this.errorUnclearPromptTriggered = false;
105
109
  await fetchEventSource(url, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/jetpack-ai-client",
3
- "version": "0.33.26",
3
+ "version": "0.33.27",
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",
@@ -1,9 +1,13 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
+ import { select } from '@wordpress/data';
4
5
  import debugFactory from 'debug';
6
+ /**
7
+ * Internal dependencies
8
+ */
5
9
  import SuggestionsEventSource from '../suggestions-event-source/index.ts';
6
- /*
10
+ /**
7
11
  * Types & constants
8
12
  */
9
13
  import type { AiModelTypeProp, PromptProp } from '../types.ts';
@@ -38,6 +42,11 @@ export type AskQuestionOptionsArgProps = {
38
42
  // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
39
43
  implementation?: Function;
40
44
  } >;
45
+
46
+ /*
47
+ * The language configured in the WordPress site settings.
48
+ */
49
+ languageCode?: string;
41
50
  };
42
51
 
43
52
  const debug = debugFactory( 'jetpack-ai-client:ask-question' );
@@ -62,18 +71,36 @@ const debug = debugFactory( 'jetpack-ai-client:ask-question' );
62
71
  */
63
72
  export default async function askQuestion(
64
73
  question: PromptProp,
65
- { postId = null, fromCache = false, feature, functions, model }: AskQuestionOptionsArgProps = {}
74
+ {
75
+ postId = null,
76
+ fromCache = false,
77
+ feature,
78
+ functions,
79
+ model,
80
+ languageCode,
81
+ }: AskQuestionOptionsArgProps = {}
66
82
  ): Promise< SuggestionsEventSource > {
83
+ const code =
84
+ languageCode || select( 'core' ).getEntityRecord( 'root', 'site' )?.language || 'en_US';
85
+
67
86
  debug( 'Asking question: %o. options: %o', question, {
68
87
  postId,
69
88
  fromCache,
70
89
  feature,
71
90
  functions,
72
91
  model,
92
+ languageCode: code,
73
93
  } );
74
94
 
75
95
  return new SuggestionsEventSource( {
76
96
  question,
77
- options: { postId, feature, fromCache, functions, model },
97
+ options: {
98
+ postId,
99
+ feature,
100
+ fromCache,
101
+ functions,
102
+ model,
103
+ languageCode: code,
104
+ },
78
105
  } );
79
106
  }
@@ -1,12 +1,16 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
+ import { select } from '@wordpress/data';
4
5
  import debugFactory from 'debug';
5
- /*
6
- * Types & constants
6
+ /**
7
+ * Internal dependencies
7
8
  */
8
9
  import requestJwt from '../jwt/index.ts';
9
- import { AskQuestionOptionsArgProps } from './index.ts';
10
+ /**
11
+ * Types & constants
12
+ */
13
+ import type { AskQuestionOptionsArgProps } from './index.ts';
10
14
  import type { PromptProp } from '../types.ts';
11
15
 
12
16
  /**
@@ -37,6 +41,9 @@ export default async function askQuestionSync(
37
41
  question: PromptProp,
38
42
  options: AskQuestionOptionsArgProps = {}
39
43
  ): Promise< ResponseData > {
44
+ options.languageCode =
45
+ options.languageCode || select( 'core' ).getEntityRecord( 'root', 'site' )?.language || 'en_US';
46
+
40
47
  debug( 'Asking question with no streaming: %o. options: %o', question, options );
41
48
 
42
49
  /**
@@ -37,6 +37,7 @@ type SuggestionsEventSourceConstructorArgs = {
37
37
  fromCache?: boolean;
38
38
  functions?: Array< object >;
39
39
  model?: AiModelTypeProp;
40
+ languageCode?: string;
40
41
  };
41
42
  };
42
43
 
@@ -115,6 +116,7 @@ export default class SuggestionsEventSource extends EventTarget {
115
116
  feature?: string;
116
117
  functions?: Array< object >;
117
118
  model?: AiModelTypeProp;
119
+ language_code?: string;
118
120
  } = {};
119
121
 
120
122
  // Populate body data with post id only if it is an integer
@@ -160,6 +162,11 @@ export default class SuggestionsEventSource extends EventTarget {
160
162
  bodyData.model = options.model;
161
163
  }
162
164
 
165
+ if ( options?.languageCode?.length ) {
166
+ debug( 'Language: %o', options.languageCode );
167
+ bodyData.language_code = options.languageCode;
168
+ }
169
+
163
170
  // Clean the unclear prompt trigger flag
164
171
  this.errorUnclearPromptTriggered = false;
165
172