@automattic/jetpack-ai-client 0.9.0 → 0.10.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 +10 -0
- package/build/hooks/use-image-generator/index.d.ts +10 -0
- package/build/hooks/use-image-generator/index.js +48 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +15 -15
- package/src/hooks/use-image-generator/index.ts +62 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ 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.10.1] - 2024-03-27
|
|
9
|
+
### Changed
|
|
10
|
+
- Updated package dependencies. [#36539, #36585]
|
|
11
|
+
|
|
12
|
+
## [0.10.0] - 2024-03-18
|
|
13
|
+
### Added
|
|
14
|
+
- Add image generator hook [#36415]
|
|
15
|
+
|
|
8
16
|
## [0.9.0] - 2024-03-12
|
|
9
17
|
### Changed
|
|
10
18
|
- Fix typescript errors [#35904]
|
|
@@ -255,6 +263,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
255
263
|
- Updated package dependencies. [#31659]
|
|
256
264
|
- Updated package dependencies. [#31785]
|
|
257
265
|
|
|
266
|
+
[0.10.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.10.0...v0.10.1
|
|
267
|
+
[0.10.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.9.0...v0.10.0
|
|
258
268
|
[0.9.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.8.2...v0.9.0
|
|
259
269
|
[0.8.2]: https://github.com/Automattic/jetpack-ai-client/compare/v0.8.1...v0.8.2
|
|
260
270
|
[0.8.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.8.0...v0.8.1
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import debugFactory from 'debug';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import requestJwt from '../../jwt/index.js';
|
|
9
|
+
const debug = debugFactory('ai-client:use-image-generator');
|
|
10
|
+
const useImageGenerator = () => {
|
|
11
|
+
const generateImage = async function ({ feature, }) {
|
|
12
|
+
let token = '';
|
|
13
|
+
try {
|
|
14
|
+
token = (await requestJwt()).token;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
debug('Error getting token: %o', error);
|
|
18
|
+
return Promise.reject(error);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
debug('Generating image');
|
|
22
|
+
// TODO: Find a proper prompt for the image generation
|
|
23
|
+
const imageGenerationPrompt = ``;
|
|
24
|
+
const URL = 'https://public-api.wordpress.com/wpcom/v2/jetpack-ai-image';
|
|
25
|
+
const body = {
|
|
26
|
+
prompt: imageGenerationPrompt,
|
|
27
|
+
response_format: 'url',
|
|
28
|
+
feature,
|
|
29
|
+
};
|
|
30
|
+
const headers = {
|
|
31
|
+
Authorization: `Bearer ${token}`,
|
|
32
|
+
};
|
|
33
|
+
const data = await fetch(URL, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers,
|
|
36
|
+
body: JSON.stringify(body),
|
|
37
|
+
}).then(response => response.json());
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
generateImage,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export default useImageGenerator;
|
package/build/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { default as useMediaRecording } from './hooks/use-media-recording/index.
|
|
|
7
7
|
export { default as useAudioTranscription } from './hooks/use-audio-transcription/index.js';
|
|
8
8
|
export { default as useTranscriptionPostProcessing } from './hooks/use-transcription-post-processing/index.js';
|
|
9
9
|
export { default as useAudioValidation } from './hooks/use-audio-validation/index.js';
|
|
10
|
+
export { default as useImageGenerator } from './hooks/use-image-generator/index.js';
|
|
10
11
|
export * from './icons/index.js';
|
|
11
12
|
export * from './components/index.js';
|
|
12
13
|
export * from './data-flow/index.js';
|
package/build/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export { default as useMediaRecording } from './hooks/use-media-recording/index.
|
|
|
13
13
|
export { default as useAudioTranscription } from './hooks/use-audio-transcription/index.js';
|
|
14
14
|
export { default as useTranscriptionPostProcessing } from './hooks/use-transcription-post-processing/index.js';
|
|
15
15
|
export { default as useAudioValidation } from './hooks/use-audio-validation/index.js';
|
|
16
|
+
export { default as useImageGenerator } from './hooks/use-image-generator/index.js';
|
|
16
17
|
/*
|
|
17
18
|
* Components: Icons
|
|
18
19
|
*/
|
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.10.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": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@storybook/addon-actions": "
|
|
26
|
-
"@storybook/blocks": "
|
|
27
|
-
"@storybook/react": "
|
|
25
|
+
"@storybook/addon-actions": "8.0.4",
|
|
26
|
+
"@storybook/blocks": "8.0.4",
|
|
27
|
+
"@storybook/react": "8.0.4",
|
|
28
28
|
"jest": "^29.6.2",
|
|
29
29
|
"jest-environment-jsdom": "29.7.0",
|
|
30
30
|
"typescript": "5.0.4"
|
|
@@ -38,19 +38,19 @@
|
|
|
38
38
|
"main": "./build/index.js",
|
|
39
39
|
"types": "./build/index.d.ts",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@automattic/jetpack-base-styles": "^0.6.
|
|
42
|
-
"@automattic/jetpack-connection": "^0.33.
|
|
43
|
-
"@automattic/jetpack-shared-extension-utils": "^0.14.
|
|
41
|
+
"@automattic/jetpack-base-styles": "^0.6.20",
|
|
42
|
+
"@automattic/jetpack-connection": "^0.33.5",
|
|
43
|
+
"@automattic/jetpack-shared-extension-utils": "^0.14.8",
|
|
44
44
|
"@microsoft/fetch-event-source": "2.0.1",
|
|
45
45
|
"@types/react": "18.2.61",
|
|
46
|
-
"@wordpress/api-fetch": "6.
|
|
47
|
-
"@wordpress/block-editor": "12.
|
|
48
|
-
"@wordpress/components": "27.
|
|
49
|
-
"@wordpress/compose": "6.
|
|
50
|
-
"@wordpress/data": "9.
|
|
51
|
-
"@wordpress/element": "5.
|
|
52
|
-
"@wordpress/i18n": "4.
|
|
53
|
-
"@wordpress/icons": "9.
|
|
46
|
+
"@wordpress/api-fetch": "6.51.0",
|
|
47
|
+
"@wordpress/block-editor": "12.22.0",
|
|
48
|
+
"@wordpress/components": "27.2.0",
|
|
49
|
+
"@wordpress/compose": "6.31.0",
|
|
50
|
+
"@wordpress/data": "9.24.0",
|
|
51
|
+
"@wordpress/element": "5.31.0",
|
|
52
|
+
"@wordpress/i18n": "4.54.0",
|
|
53
|
+
"@wordpress/icons": "9.45.0",
|
|
54
54
|
"classnames": "2.3.2",
|
|
55
55
|
"debug": "4.3.4",
|
|
56
56
|
"react": "18.2.0",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import debugFactory from 'debug';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import requestJwt from '../../jwt/index.js';
|
|
9
|
+
|
|
10
|
+
const debug = debugFactory( 'ai-client:use-image-generator' );
|
|
11
|
+
|
|
12
|
+
const useImageGenerator = () => {
|
|
13
|
+
const generateImage = async function ( {
|
|
14
|
+
feature,
|
|
15
|
+
}: {
|
|
16
|
+
feature: string;
|
|
17
|
+
} ): Promise< { data: Array< { url: string } > } > {
|
|
18
|
+
let token = '';
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
token = ( await requestJwt() ).token;
|
|
22
|
+
} catch ( error ) {
|
|
23
|
+
debug( 'Error getting token: %o', error );
|
|
24
|
+
return Promise.reject( error );
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
debug( 'Generating image' );
|
|
29
|
+
|
|
30
|
+
// TODO: Find a proper prompt for the image generation
|
|
31
|
+
const imageGenerationPrompt = ``;
|
|
32
|
+
|
|
33
|
+
const URL = 'https://public-api.wordpress.com/wpcom/v2/jetpack-ai-image';
|
|
34
|
+
|
|
35
|
+
const body = {
|
|
36
|
+
prompt: imageGenerationPrompt,
|
|
37
|
+
response_format: 'url',
|
|
38
|
+
feature,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const headers = {
|
|
42
|
+
Authorization: `Bearer ${ token }`,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const data = await fetch( URL, {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers,
|
|
48
|
+
body: JSON.stringify( body ),
|
|
49
|
+
} ).then( response => response.json() );
|
|
50
|
+
|
|
51
|
+
return data as { data: { url: string }[] };
|
|
52
|
+
} catch ( error ) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
generateImage,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default useImageGenerator;
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { default as useMediaRecording } from './hooks/use-media-recording/index.
|
|
|
14
14
|
export { default as useAudioTranscription } from './hooks/use-audio-transcription/index.js';
|
|
15
15
|
export { default as useTranscriptionPostProcessing } from './hooks/use-transcription-post-processing/index.js';
|
|
16
16
|
export { default as useAudioValidation } from './hooks/use-audio-validation/index.js';
|
|
17
|
+
export { default as useImageGenerator } from './hooks/use-image-generator/index.js';
|
|
17
18
|
|
|
18
19
|
/*
|
|
19
20
|
* Components: Icons
|