Skip to content

Commit

Permalink
Merge branch 'trunk' into udpate/deprecate-theme-tool-devicepx
Browse files Browse the repository at this point in the history
  • Loading branch information
darssen committed Apr 30, 2024
2 parents 29ae39e + 5da0a88 commit 047be1e
Show file tree
Hide file tree
Showing 317 changed files with 1,577 additions and 899 deletions.
2 changes: 1 addition & 1 deletion .phan/stubs/full-site-editing-stubs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Stubs automatically generated from WordPress.com Editing Toolkit 4.20083
* Stubs automatically generated from WordPress.com Editing Toolkit 4.20606
* using the definition file `tools/stubs/full-site-editing-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
Expand Down
2 changes: 1 addition & 1 deletion .phan/stubs/woocommerce-internal-stubs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Stubs automatically generated from WooCommerce 8.8.2
* Stubs automatically generated from WooCommerce 8.8.3
* using the definition file `tools/stubs/woocommerce-internal-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
Expand Down
12 changes: 0 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/js-packages/ai-client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.12.4] - 2024-04-29
### Added
- AI Client: Export ExtensionAIControl. [#37087]

## [0.12.3] - 2024-04-25
### Changed
- AI Client: Separate AIControl UI from block logic. [#36967]
Expand Down Expand Up @@ -294,6 +298,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated package dependencies. [#31659]
- Updated package dependencies. [#31785]

[0.12.4]: https://github.com/Automattic/jetpack-ai-client/compare/v0.12.3...v0.12.4
[0.12.3]: https://github.com/Automattic/jetpack-ai-client/compare/v0.12.2...v0.12.3
[0.12.2]: https://github.com/Automattic/jetpack-ai-client/compare/v0.12.1...v0.12.2
[0.12.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.12.0...v0.12.1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

AI Featured Image: support custom user prompt on the image generation.

This file was deleted.

2 changes: 1 addition & 1 deletion projects/js-packages/ai-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "@automattic/jetpack-ai-client",
"version": "0.12.4-alpha",
"version": "0.13.0-alpha",
"description": "A JS client for consuming Jetpack AI services",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/ai-client/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,86 @@ import requestJwt from '../../jwt/index.js';

const debug = debugFactory( 'ai-client:use-image-generator' );

/**
* Cut the post content on a given lenght so the total length of the prompt is not longer than 4000 characters.
* @param {string} content - the content to be truncated
* @param {number} currentPromptLength - the length of the prompt already in use
* @returns {string} a truncated version of the content respecting the prompt length limit
*/
const truncateContent = ( content: string, currentPromptLength: number ): string => {
const maxLength = 4000;
const remainingLength = maxLength - currentPromptLength;
// 6 is the length of the ellipsis and the space before it
return content.length > remainingLength
? content.substring( 0, remainingLength - 6 ) + ` [...]`
: content;
};

/**
* Create the prompt string based on the provided context.
* @param {string} postContent - the content of the post
* @param {string} userPrompt - the user prompt for the image generation, if provided. Max length is 1000 characters, will be truncated.
* @returns {string} the prompt string
*/
const getImageGenerationPrompt = ( postContent: string, userPrompt?: string ): string => {
/**
* If the user provide some custom prompt for the image generation,
* we will use it, add the post content as additional context and
* provide some guardrails for the generation.
*/
if ( userPrompt ) {
const imageGenerationPrompt = `I need a cover image for a blog post based on this user prompt:
${ userPrompt.length > 1000 ? userPrompt.substring( 0, 1000 ) : userPrompt }
Before creating the image, identify the main topic of the user prompt and relate it to the post content.
Do not represent the whole content in one image, keep it simple and just represent one single idea.
Do not add details, detailed explanations or highlights from the content, just represent the main idea as if it was a photograph.
Do not use collages or compositions with multiple elements or scenes. Stick to one single scene. Do not compose unrealistic scenes.
If the content describes facts, objects or concepts from the real world, represent them on a realistic style and do not make unreal compositions.
If the content is more abstract, use a more abstract style to represent the main idea.
Make sure the light and the style are visually appealing.
Do not add text to the image.
For additional context, this is the post content:
`;
// truncating the content so the whole prompt is not longer than 4000 characters, the model limit.
return imageGenerationPrompt + truncateContent( postContent, imageGenerationPrompt.length );
}

/**
* When the user does not provide a custom prompt, we will use the
* standard one, based solely on the post content.
*/
const imageGenerationPrompt = `I need a cover image for a blog post.
Before creating the image, identify the main topic of the content and only represent it.
Do not represent the whole content in one image, keep it simple and just represent one single idea.
Do not add details, detailed explanations or highlights from the content, just represent the main idea as if it was a photograph.
Do not use collages or compositions with multiple elements or scenes. Stick to one single scene. Do not compose unrealistic scenes.
If the content describes facts, objects or concepts from the real world, represent them on a realistic style and do not make unreal compositions.
If the content is more abstract, use a more abstract style to represent the main idea.
Make sure the light and the style are visually appealing.
Do not add text to the image.
This is the post content:
`;
// truncating the content so the whole prompt is not longer than 4000 characters, the model limit.
return imageGenerationPrompt + truncateContent( postContent, imageGenerationPrompt.length );
};

const useImageGenerator = () => {
const generateImage = async function ( {
feature,
postContent,
responseFormat = 'url',
userPrompt,
}: {
feature: string;
postContent: string;
responseFormat?: 'url' | 'b64_json';
userPrompt?: string;
} ): Promise< { data: Array< { [ key: string ]: string } > } > {
let token = '';

Expand All @@ -31,21 +102,7 @@ const useImageGenerator = () => {
try {
debug( 'Generating image' );

// TODO: fine tune the prompt as we move forward
const imageGenerationPrompt =
`I need a cover image for a blog post.
Before creating the image, identify the main topic of the content and only represent it.
Do not represent the whole content in one image, keep it simple and just represent one single idea.
Do not add details, detailed explanations or highlights from the content, just represent the main idea as if it was a photograph.
Do not use collages or compositions with multiple elements or scenes. Stick to one single scene. Do not compose unrealistic scenes.
If the content describes facts, objects or concepts from the real world, represent them on a realistic style and do not make unreal compositions.
If the content is more abstract, use a more abstract style to represent the main idea.
Make sure the light and the style are visually appealing.
Do not add text to the image.
This is the post content:
` + ( postContent.length > 3000 ? postContent.substring( 0, 3000 ) + ` [...]` : postContent ); // truncating the content so the whole prompt is not longer than 4000 characters, the model limit.
const imageGenerationPrompt = getImageGenerationPrompt( postContent, userPrompt );

const URL = 'https://public-api.wordpress.com/wpcom/v2/jetpack-ai-image';

Expand Down
13 changes: 5 additions & 8 deletions projects/packages/analyzer/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@
return [
// # Issue statistics:
// PhanUndeclaredProperty : 30+ occurrences
// PhanTypeMismatchArgument : 10+ occurrences
// PhanUndeclaredClassMethod : 9 occurrences
// PhanTypeMismatchArgument : 8 occurrences
// PhanPossiblyUndeclaredVariable : 7 occurrences
// PhanParamSignatureMismatch : 6 occurrences
// PhanPluginDuplicateConditionalNullCoalescing : 6 occurrences
// PhanTypeMismatchReturnProbablyReal : 6 occurrences
// PhanUndeclaredTypeParameter : 6 occurrences
// PhanUndeclaredClassMethod : 6 occurrences
// PhanUndeclaredMethod : 6 occurrences
// PhanTypeArraySuspiciousNullable : 5 occurrences
// PhanTypeMismatchArgumentNullable : 5 occurrences
// PhanUndeclaredMethod : 4 occurrences
// PhanUndeclaredTypeParameter : 4 occurrences
// PhanDeprecatedEncapsVar : 2 occurrences
// PhanNonClassMethodCall : 2 occurrences
// PhanPluginDuplicateCatchStatementBody : 2 occurrences
// PhanTypeMismatchDeclaredParam : 2 occurrences
// PhanUndeclaredClassStaticProperty : 2 occurrences
// PhanUnextractableAnnotationElementName : 2 occurrences
// PhanUnextractableAnnotationSuffix : 2 occurrences
// PhanPluginDuplicateExpressionAssignmentOperation : 1 occurrence
// PhanPluginUseReturnValueInternalKnown : 1 occurrence
// PhanTypeMismatchArgumentProbablyReal : 1 occurrence
Expand All @@ -41,7 +39,6 @@
'scripts/jetpack-slurper.php' => ['PhanDeprecatedEncapsVar'],
'scripts/jetpack-svn.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeArraySuspiciousNullable'],
'src/Declarations/class-declaration.php' => ['PhanUndeclaredProperty'],
'src/Declarations/class-visitor.php' => ['PhanTypeMismatchArgument'],
'src/Differences/class-class-const-missing.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturnProbablyReal'],
'src/Differences/class-class-const-moved.php' => ['PhanTypeMismatchArgument'],
'src/Differences/class-class-method-deprecated.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchReturnProbablyReal'],
Expand All @@ -57,7 +54,7 @@
'src/class-declarations.php' => ['PhanPluginDuplicateCatchStatementBody'],
'src/class-differences.php' => ['PhanNonClassMethodCall', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullable'],
'src/class-invocations.php' => ['PhanPluginDuplicateCatchStatementBody'],
'src/class-utils.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredClassMethod', 'PhanUndeclaredMethod', 'PhanUndeclaredProperty', 'PhanUndeclaredTypeParameter', 'PhanUnextractableAnnotationElementName', 'PhanUnextractableAnnotationSuffix'],
'src/class-utils.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredMethod', 'PhanUndeclaredProperty', 'PhanUndeclaredTypeParameter'],
'src/class-warnings.php' => ['PhanUndeclaredMethod'],
'src/diff-generator.php' => ['PhanDeprecatedEncapsVar'],
],
Expand Down
5 changes: 5 additions & 0 deletions projects/packages/analyzer/changelog/fix-phan-comment-errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix phpdoc comments to make Phan happier. No change to functionality.


4 changes: 2 additions & 2 deletions projects/packages/analyzer/src/class-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static function maybe_stringify( $object ) {
/**
* Check if a node has a docblock containing a specific comment string.
*
* @param PhpParser/Node $node Current node we are parsing.
* @param Node $node Current node we are parsing.
* @param string $comment Comment to match.
* @return boolean
*/
Expand All @@ -139,7 +139,7 @@ public static function has_doc_comment( $node, $comment ) {
* Check if a node contains a call to a function name.
* Any part of the function name will be matched.
*
* @param PhpParser/Node $node Current node we are parsing.
* @param Node $node Current node we are parsing.
* @param string $name Function name to match.
* @return boolean
*/
Expand Down
4 changes: 4 additions & 0 deletions projects/packages/blaze/changelog/fix-blaze-this-translations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Blaze: Fix translations of "Blaze this %s" labels
2 changes: 1 addition & 1 deletion projects/packages/blaze/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-blaze",
"version": "0.21.1",
"version": "0.21.2-alpha",
"description": "Attract high-quality traffic to your site using Blaze. Using this service, you can advertise a post or page on some of the millions of pages across WordPress.com and Tumblr from just $5 per day.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/blaze/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/blaze/src/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Dashboard {
*
* @var string
*/
const PACKAGE_VERSION = '0.21.1';
const PACKAGE_VERSION = '0.21.2-alpha';

/**
* List of dependencies needed to render the dashboard in wp-admin.
Expand Down
25 changes: 13 additions & 12 deletions projects/packages/blaze/src/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useSelect } from '@wordpress/data';
import { PluginPostPublishPanel } from '@wordpress/edit-post';
import { store as editorStore } from '@wordpress/editor';
import { useCallback, useEffect } from '@wordpress/element';
import { __, _x, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { external, Icon } from '@wordpress/icons';
import { getPlugin, registerPlugin } from '@wordpress/plugins';
import './editor.scss';
Expand All @@ -21,17 +21,15 @@ const BlazePostPublishPanel = () => {
[ tracks ]
);

const { isPostPublished, isPublishingPost, postId, postType, postTypeLabel, postVisibility } =
useSelect( selector => ( {
const { isPostPublished, isPublishingPost, postId, postType, postVisibility } = useSelect(
selector => ( {
isPostPublished: selector( editorStore ).isCurrentPostPublished(),
isPublishingPost: selector( editorStore ).isPublishingPost(),
postId: selector( editorStore ).getCurrentPostId(),
postType: selector( editorStore ).getCurrentPostType(),
postTypeLabel:
// Translators: default post type label.
selector( editorStore ).getPostTypeLabel() || _x( 'Post', 'noun', 'jetpack-blaze' ),
postVisibility: selector( editorStore ).getEditedPostVisibility(),
} ) );
} )
);
const wasPublishing = usePrevious( isPublishingPost );

const panelBodyProps = {
Expand Down Expand Up @@ -80,6 +78,13 @@ const BlazePostPublishPanel = () => {
return null;
}

const blazeThisLabel =
{
page: __( 'Blaze this page', 'jetpack-blaze' ),
post: __( 'Blaze this post', 'jetpack-blaze' ),
product: __( 'Blaze this product', 'jetpack-blaze' ),
}[ postType ] ?? __( 'Blaze this post', 'jetpack-blaze' );

return (
<PluginPostPublishPanel { ...panelBodyProps }>
<PanelRow>
Expand All @@ -98,11 +103,7 @@ const BlazePostPublishPanel = () => {
onKeyDown={ trackClick }
>
<Button variant="secondary" href={ blazeUrl } target="_top">
{ sprintf(
/* translators: %s is the post type (e.g. Post, Page, Product). */
__( 'Blaze this %s', 'jetpack-blaze' ),
postTypeLabel.toLowerCase()
) }
{ blazeThisLabel }
{ blazeUrlTemplate.external && (
<Icon icon={ external } className="blaze-panel-outbound-link__external_icon" />
) }
Expand Down
6 changes: 2 additions & 4 deletions projects/packages/connection/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
// PhanTypeMismatchArgumentInternal : 3 occurrences
// PhanTypeMismatchArgumentNullable : 3 occurrences
// PhanTypeObjectUnsetDeclaredProperty : 3 occurrences
// PhanCommentParamWithoutRealParam : 2 occurrences
// PhanNonClassMethodCall : 2 occurrences
// PhanPluginUnreachableCode : 2 occurrences
// PhanPossiblyUndeclaredVariable : 2 occurrences
Expand All @@ -41,7 +40,6 @@
// PhanPluginSimplifyExpressionBool : 1 occurrence
// PhanTypeMismatchDeclaredParamNullable : 1 occurrence
// PhanUndeclaredClassReference : 1 occurrence
// PhanUnextractableAnnotationSuffix : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
Expand All @@ -59,8 +57,8 @@
'src/class-partner.php' => ['PhanTypeMismatchPropertyProbablyReal'],
'src/class-plugin-storage.php' => ['PhanUndeclaredClassMethod'],
'src/class-rest-authentication.php' => ['PhanTypeMismatchPropertyDefault', 'PhanTypeMismatchPropertyProbablyReal'],
'src/class-rest-connector.php' => ['PhanParamTooMany', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassMethod', 'PhanUnextractableAnnotationSuffix'],
'src/class-secrets.php' => ['PhanCommentParamWithoutRealParam', 'PhanNonClassMethodCall', 'PhanTypeMismatchArgument'],
'src/class-rest-connector.php' => ['PhanParamTooMany', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassMethod'],
'src/class-secrets.php' => ['PhanNonClassMethodCall', 'PhanTypeMismatchArgument'],
'src/class-server-sandbox.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument'],
'src/class-tokens.php' => ['PhanImpossibleTypeComparison', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'],
'src/class-tracking.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDefault', 'PhanTypePossiblyInvalidDimOffset'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix phpdoc comments to make Phan happier. No change to functionality.


2 changes: 1 addition & 1 deletion projects/packages/connection/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '2.7.4';
const PACKAGE_VERSION = '2.7.5-alpha';

const PACKAGE_SLUG = 'connection';

Expand Down
2 changes: 1 addition & 1 deletion projects/packages/connection/src/class-rest-connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ public static function disconnect_site() {
*
* @since 1.29.0
*
* @return bool|WP_Error.
* @return bool|WP_Error
*/
public static function update_user_token_permission_check() {
return Rest_Authentication::is_signed_with_blog_token()
Expand Down
1 change: 1 addition & 0 deletions projects/packages/connection/src/class-secrets.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function verify( $action, $secret_1, $user_id ) {
*/
do_action( 'jetpack_verify_secrets_begin', $action, $user );

/** Closure to run the 'fail' action and return an error. */
$return_error = function ( WP_Error $error ) use ( $action, $user ) {
/**
* Verifying of the previously generated secret has failed.
Expand Down
Loading

0 comments on commit 047be1e

Please sign in to comment.