@automattic/jetpack-ai-client 0.11.0 → 0.12.0

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,16 @@ 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.12.0] - 2024-04-08
9
+ ### Added
10
+ - Add error rejection in image generation. [#36709]
11
+
12
+ ### Changed
13
+ - Updated package dependencies. [#36756] [#36760] [#36761]
14
+
15
+ ### Fixed
16
+ - AI Featured Image: handle posts longer than the limit of Dall-e generation prompt. [#36703]
17
+
8
18
  ## [0.11.0] - 2024-04-01
9
19
  ### Added
10
20
  - AI Client: include prompt to generate featured image based on post content. [#36591]
@@ -272,6 +282,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
272
282
  - Updated package dependencies. [#31659]
273
283
  - Updated package dependencies. [#31785]
274
284
 
285
+ [0.12.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.11.0...v0.12.0
275
286
  [0.11.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.10.1...v0.11.0
276
287
  [0.10.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.10.0...v0.10.1
277
288
  [0.10.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.9.0...v0.10.0
@@ -32,7 +32,7 @@ Do not add text to the image.
32
32
 
33
33
  This is the post content:
34
34
 
35
- ` + postContent;
35
+ ` + (postContent.length > 3000 ? postContent.substring(0, 3000) + ` [...]` : postContent); // truncating the content so the whole prompt is not longer than 4000 characters, the model limit.
36
36
  const URL = 'https://public-api.wordpress.com/wpcom/v2/jetpack-ai-image';
37
37
  const body = {
38
38
  prompt: imageGenerationPrompt,
@@ -49,10 +49,15 @@ This is the post content:
49
49
  headers,
50
50
  body: JSON.stringify(body),
51
51
  }).then(response => response.json());
52
+ if (data?.data?.status && data?.data?.status > 200) {
53
+ debug('Error generating image: %o', data);
54
+ return Promise.reject(data);
55
+ }
52
56
  return data;
53
57
  }
54
58
  catch (error) {
55
- return;
59
+ debug('Error generating image: %o', error);
60
+ return Promise.reject(error);
56
61
  }
57
62
  };
58
63
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@automattic/jetpack-ai-client",
4
- "version": "0.11.0",
4
+ "version": "0.12.0",
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": {
@@ -23,9 +23,9 @@
23
23
  },
24
24
  "type": "module",
25
25
  "devDependencies": {
26
- "@storybook/addon-actions": "8.0.4",
27
- "@storybook/blocks": "8.0.4",
28
- "@storybook/react": "8.0.4",
26
+ "@storybook/addon-actions": "8.0.6",
27
+ "@storybook/blocks": "8.0.6",
28
+ "@storybook/react": "8.0.6",
29
29
  "jest": "^29.6.2",
30
30
  "jest-environment-jsdom": "29.7.0",
31
31
  "typescript": "5.0.4"
@@ -39,19 +39,19 @@
39
39
  "main": "./build/index.js",
40
40
  "types": "./build/index.d.ts",
41
41
  "dependencies": {
42
- "@automattic/jetpack-base-styles": "^0.6.20",
43
- "@automattic/jetpack-connection": "^0.33.5",
44
- "@automattic/jetpack-shared-extension-utils": "^0.14.8",
42
+ "@automattic/jetpack-base-styles": "^0.6.21",
43
+ "@automattic/jetpack-connection": "^0.33.7",
44
+ "@automattic/jetpack-shared-extension-utils": "^0.14.9",
45
45
  "@microsoft/fetch-event-source": "2.0.1",
46
- "@types/react": "18.2.61",
47
- "@wordpress/api-fetch": "6.51.0",
48
- "@wordpress/block-editor": "12.22.0",
49
- "@wordpress/components": "27.2.0",
50
- "@wordpress/compose": "6.31.0",
51
- "@wordpress/data": "9.24.0",
52
- "@wordpress/element": "5.31.0",
53
- "@wordpress/i18n": "4.54.0",
54
- "@wordpress/icons": "9.45.0",
46
+ "@types/react": "18.2.74",
47
+ "@wordpress/api-fetch": "6.52.0",
48
+ "@wordpress/block-editor": "12.23.0",
49
+ "@wordpress/components": "27.3.0",
50
+ "@wordpress/compose": "6.32.0",
51
+ "@wordpress/data": "9.25.0",
52
+ "@wordpress/element": "5.32.0",
53
+ "@wordpress/i18n": "4.55.0",
54
+ "@wordpress/icons": "9.46.0",
55
55
  "classnames": "2.3.2",
56
56
  "debug": "4.3.4",
57
57
  "react": "18.2.0",
@@ -45,7 +45,7 @@ Do not add text to the image.
45
45
 
46
46
  This is the post content:
47
47
 
48
- ` + postContent;
48
+ ` + ( postContent.length > 3000 ? postContent.substring( 0, 3000 ) + ` [...]` : postContent ); // truncating the content so the whole prompt is not longer than 4000 characters, the model limit.
49
49
 
50
50
  const URL = 'https://public-api.wordpress.com/wpcom/v2/jetpack-ai-image';
51
51
 
@@ -67,9 +67,15 @@ This is the post content:
67
67
  body: JSON.stringify( body ),
68
68
  } ).then( response => response.json() );
69
69
 
70
+ if ( data?.data?.status && data?.data?.status > 200 ) {
71
+ debug( 'Error generating image: %o', data );
72
+ return Promise.reject( data );
73
+ }
74
+
70
75
  return data as { data: { [ key: string ]: string }[] };
71
76
  } catch ( error ) {
72
- return;
77
+ debug( 'Error generating image: %o', error );
78
+ return Promise.reject( error );
73
79
  }
74
80
  };
75
81