@automattic/jetpack-ai-client 0.27.2 → 0.27.4

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,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.27.4] - 2025-03-18
9
+ ### Changed
10
+ - Update package dependencies. [#42509]
11
+
12
+ ## [0.27.3] - 2025-03-17
13
+ ### Changed
14
+ - Internal updates.
15
+
8
16
  ## [0.27.2] - 2025-03-12
9
17
  ### Changed
10
18
  - Update dependencies. [#42328]
@@ -553,6 +561,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
553
561
  - AI Client: stop using smart document visibility handling on the fetchEventSource library, so it does not restart the completion when changing tabs. [#32004]
554
562
  - Updated package dependencies. [#31468] [#31659] [#31785]
555
563
 
564
+ [0.27.4]: https://github.com/Automattic/jetpack-ai-client/compare/v0.27.3...v0.27.4
565
+ [0.27.3]: https://github.com/Automattic/jetpack-ai-client/compare/v0.27.2...v0.27.3
556
566
  [0.27.2]: https://github.com/Automattic/jetpack-ai-client/compare/v0.27.1...v0.27.2
557
567
  [0.27.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.27.0...v0.27.1
558
568
  [0.27.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.26.3...v0.27.0
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Get the base64 representation of an image.
3
+ *
4
+ * @param {string} url - The URL of the image.
5
+ * @return {Promise<string>} The base64 representation of the image.
6
+ */
7
+ export declare const getBase64Image: (url: string) => Promise<string>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Get the base64 representation of an image.
3
+ *
4
+ * @param {string} url - The URL of the image.
5
+ * @return {Promise<string>} The base64 representation of the image.
6
+ */
7
+ export const getBase64Image = async (url) => {
8
+ try {
9
+ const response = await fetch(url);
10
+ const buffer = await response.arrayBuffer();
11
+ const base64String = btoa(new Uint8Array(buffer).reduce((data, byte) => data + String.fromCharCode(byte), ''));
12
+ return `data:image/png;base64,${base64String}`;
13
+ }
14
+ catch {
15
+ // If we can't fetch the image, return the original URL.
16
+ return url;
17
+ }
18
+ };
@@ -1,6 +1,7 @@
1
1
  export { MarkdownToHTML, HTMLToMarkdown, renderHTMLFromMarkdown, renderMarkdownFromHTML, fixes, } from './markdown/index.js';
2
- export type { RenderHTMLRules } from './markdown/index.js';
3
2
  export { mapActionToHumanText } from './map-action-to-human-text.js';
4
3
  export { openBlockSidebar } from './open-block-sidebar.js';
5
4
  export { showAiAssistantSection } from './show-ai-assistant-section.js';
6
5
  export { getAllBlocks } from './get-all-blocks.js';
6
+ export { getBase64Image } from './get-base64-image.js';
7
+ export type { RenderHTMLRules } from './markdown/index.js';
@@ -3,3 +3,4 @@ export { mapActionToHumanText } from './map-action-to-human-text.js';
3
3
  export { openBlockSidebar } from './open-block-sidebar.js';
4
4
  export { showAiAssistantSection } from './show-ai-assistant-section.js';
5
5
  export { getAllBlocks } from './get-all-blocks.js';
6
+ export { getBase64Image } from './get-base64-image.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@automattic/jetpack-ai-client",
4
- "version": "0.27.2",
4
+ "version": "0.27.4",
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": {
@@ -24,15 +24,15 @@
24
24
  },
25
25
  "type": "module",
26
26
  "devDependencies": {
27
- "@storybook/addon-actions": "8.5.8",
28
- "@storybook/blocks": "8.5.8",
29
- "@storybook/preview-api": "8.5.8",
30
- "@storybook/react": "8.5.8",
27
+ "@storybook/addon-actions": "8.6.7",
28
+ "@storybook/blocks": "8.6.7",
29
+ "@storybook/preview-api": "8.6.7",
30
+ "@storybook/react": "8.6.7",
31
31
  "@types/markdown-it": "14.1.2",
32
32
  "@types/turndown": "5.0.5",
33
33
  "jest": "^29.6.2",
34
34
  "jest-environment-jsdom": "29.7.0",
35
- "storybook": "8.5.8",
35
+ "storybook": "8.6.7",
36
36
  "typescript": "5.0.4"
37
37
  },
38
38
  "exports": {
@@ -45,9 +45,9 @@
45
45
  "types": "./build/index.d.ts",
46
46
  "dependencies": {
47
47
  "@automattic/jetpack-base-styles": "^0.6.44",
48
- "@automattic/jetpack-components": "^0.68.2",
49
- "@automattic/jetpack-connection": "^0.39.1",
50
- "@automattic/jetpack-shared-extension-utils": "^0.18.0",
48
+ "@automattic/jetpack-components": "^0.69.1",
49
+ "@automattic/jetpack-connection": "^0.39.3",
50
+ "@automattic/jetpack-shared-extension-utils": "^0.18.3",
51
51
  "@microsoft/fetch-event-source": "2.0.1",
52
52
  "@types/jest": "29.5.14",
53
53
  "@types/react": "18.3.18",
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Get the base64 representation of an image.
3
+ *
4
+ * @param {string} url - The URL of the image.
5
+ * @return {Promise<string>} The base64 representation of the image.
6
+ */
7
+ export const getBase64Image = async ( url: string ) => {
8
+ try {
9
+ const response = await fetch( url );
10
+ const buffer = await response.arrayBuffer();
11
+ const base64String = btoa(
12
+ new Uint8Array( buffer ).reduce( ( data, byte ) => data + String.fromCharCode( byte ), '' )
13
+ );
14
+
15
+ return `data:image/png;base64,${ base64String }`;
16
+ } catch {
17
+ // If we can't fetch the image, return the original URL.
18
+ return url;
19
+ }
20
+ };
package/src/libs/index.ts CHANGED
@@ -6,12 +6,10 @@ export {
6
6
  fixes,
7
7
  } from './markdown/index.js';
8
8
 
9
- export type { RenderHTMLRules } from './markdown/index.js';
10
-
11
9
  export { mapActionToHumanText } from './map-action-to-human-text.js';
12
-
13
10
  export { openBlockSidebar } from './open-block-sidebar.js';
14
-
15
11
  export { showAiAssistantSection } from './show-ai-assistant-section.js';
16
-
17
12
  export { getAllBlocks } from './get-all-blocks.js';
13
+ export { getBase64Image } from './get-base64-image.js';
14
+
15
+ export type { RenderHTMLRules } from './markdown/index.js';