PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
extendify / src / Agent / follow-ups / cards / optimize-image.js

optimize-image.js in Extendify 3.2.2, at src/Agent/follow-ups/cards/optimize-image.js

44 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { isAbilityTool } from '@agent/lib/abilities';
2 import { __, sprintf } from '@wordpress/i18n';
3
4 const placedImage = ({ id, inputs, result }) => {
5 if (id === 'acquire-image') return result?.id;
6 if (id !== 'block-patching') return null;
7 return inputs?.operations?.find(
8 (operation) => operation?.op === 'replace-image',
9 )?.image?.id;
10 };
11
12 export default {
13 id: 'optimize-image',
14 follows: '*',
15 data: ({ toolCalls }) => {
16 const mediaId = toolCalls.map(placedImage).findLast(Boolean);
17 return mediaId ? { mediaId } : null;
18 },
19 // Imagify registers its abilities even with no account connected.
20 score: ({ data, context }) =>
21 data && context?.hasImagifyApiKey && isAbilityTool('imagify/optimize-media')
22 ? 3
23 : 0,
24 content: ({ mediaId }) => ({
25 // translators: Title of a card in the AI Agent chat, shown after the user added an image to their website.
26 title: __('Optimize your new image', 'extendify-local'),
27 // translators: Body of a card in the AI Agent chat. Imagify is the name of an image optimization plugin.
28 body: __(
29 'Imagify can make the file smaller so your page loads faster.',
30 'extendify-local',
31 ),
32 action: {
33 // translators: Button on a card in the AI Agent chat that starts optimizing an image with the Imagify plugin.
34 label: __('Optimize image', 'extendify-local'),
35 // The next run doesn't see this run's tool calls.
36 message: sprintf(
37 // translators: %d is the ID of an image in the WordPress media library. Shown in the AI Agent chat as the user's own request. Imagify is the name of an image optimization plugin.
38 __('Optimize the image with ID %d using Imagify', 'extendify-local'),
39 mediaId,
40 ),
41 },
42 }),
43 };
44