Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

AI Assistant: Hide legacy block toolbar controls when Jetpack AI Sidebar content editing is enabled.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import debugFactory from 'debug';
import { store as seoStore } from '../../../../plugins/ai-assistant-plugin/components/seo-enhancer/store';
import useBlockModuleStatus from '../../hooks/use-block-module-status';
import { getFeatureAvailability } from '../../lib/utils/get-feature-availability';
import { canAIAssistantBeEnabled } from '../lib/can-ai-assistant-be-enabled';
import {
canAIAssistantBeEnabled,
isAiSidebarToolbarButtonEnabled,
} from '../lib/can-ai-assistant-be-enabled';
import { preprocessImageContent } from '../lib/preprocess-image-content';
import { TYPE_ALT_TEXT, TYPE_CAPTION } from '../types';
import AiAssistantImageExtensionToolbarDropdown from './components/image-toolbar-dropdown';
Expand Down Expand Up @@ -231,16 +234,18 @@ const blockEditWithAiComponents = createHigherOrderComponent( BlockEdit => {
return (
<>
<BlockEdit { ...props } />
<BlockControls { ...blockControlsProps }>
<AiAssistantImageExtensionToolbarDropdown
onRequestAltText={ () => request( TYPE_ALT_TEXT ) }
onRequestCaption={ () => request( TYPE_CAPTION ) }
loadingAltText={ loadingAltText }
loadingCaption={ loadingCaption }
disabled={ ! hasImage }
wrapperRef={ wrapperRef }
/>
</BlockControls>
{ ! isAiSidebarToolbarButtonEnabled && (
<BlockControls { ...blockControlsProps }>
<AiAssistantImageExtensionToolbarDropdown
onRequestAltText={ () => request( TYPE_ALT_TEXT ) }
onRequestCaption={ () => request( TYPE_CAPTION ) }
loadingAltText={ loadingAltText }
loadingCaption={ loadingCaption }
disabled={ ! hasImage }
wrapperRef={ wrapperRef }
/>
</BlockControls>
) }
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { select } from '@wordpress/data';
import { getFeatureAvailability } from '../../lib/utils/get-feature-availability';

export const AI_ASSISTANT_SUPPORT_NAME = 'ai-assistant-support';
export const AI_SIDEBAR_TOOLBAR_BUTTON = 'ai-sidebar-toolbar-button';

// Check if the AI Assistant support is enabled.
export const isAiAssistantSupportEnabled = getFeatureAvailability( AI_ASSISTANT_SUPPORT_NAME );
export const isAiSidebarToolbarButtonEnabled = getFeatureAvailability( AI_SIDEBAR_TOOLBAR_BUTTON );

/**
* Check if it is possible to enable the AI Assistant block and its features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import debugFactory from 'debug';
import useAutoScroll from '../../hooks/use-auto-scroll';
import useBlockModuleStatus from '../../hooks/use-block-module-status';
import { mapInternalPromptTypeToBackendPromptType } from '../../lib/prompt/backend-prompt';
import { isAiSidebarToolbarButtonEnabled } from '../lib/can-ai-assistant-be-enabled';
import AiAssistantInput from './components/ai-assistant-input';
import AiAssistantExtensionToolbarDropdown from './components/ai-assistant-toolbar-dropdown';
import { getBlockHandler, InlineExtensionsContext } from './get-block-handler';
Expand Down Expand Up @@ -561,14 +562,16 @@ const blockEditWithAiComponents = createHigherOrderComponent( BlockEdit => {
/>
) }

<BlockControls { ...blockControlsProps }>
<AiAssistantExtensionToolbarDropdown
blockType={ blockName }
onAskAiAssistant={ handleAskAiAssistant }
onRequestSuggestion={ handleRequestSuggestion }
behavior={ behavior }
/>
</BlockControls>
{ ! isAiSidebarToolbarButtonEnabled && (
<BlockControls { ...blockControlsProps }>
<AiAssistantExtensionToolbarDropdown
blockType={ blockName }
onAskAiAssistant={ handleAskAiAssistant }
onRequestSuggestion={ handleRequestSuggestion }
behavior={ behavior }
/>
</BlockControls>
) }
</>
);

Expand Down
1 change: 1 addition & 0 deletions projects/plugins/jetpack/extensions/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"ai-title-optimization-keywords-support",
"ai-response-feedback",
"ai-assistant-image-extension",
"ai-sidebar-toolbar-button",
"ai-seo-enhancer",
"ai-correct-spelling",
"paypal-payment-buttons",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;

const AM_ASSET_BASE_PATH = 'widgets.wp.com/agents-manager/';
const AI_SIDEBAR_ASSET_TRANSIENT = 'jetpack_ai_sidebar_asset';
const AI_SIDEBAR_JS_URL = 'https://' . AM_ASSET_BASE_PATH . 'jetpack-ai-sidebar.min.js';
const AI_SIDEBAR_CSS_URL = 'https://' . AM_ASSET_BASE_PATH . 'jetpack-ai-sidebar.css';
const AI_SIDEBAR_RTL_CSS_URL = 'https://' . AM_ASSET_BASE_PATH . 'jetpack-ai-sidebar.rtl.css';
const AI_SIDEBAR_PROVIDER_URL = 'https://' . AM_ASSET_BASE_PATH . 'jetpack-ai-sidebar.provider.mjs';
const AI_SIDEBAR_AGENT_ID = 'wp-orchestrator';
const AM_ASSET_BASE_PATH = 'widgets.wp.com/agents-manager/';
const AI_SIDEBAR_ASSET_TRANSIENT = 'jetpack_ai_sidebar_asset';
const AI_SIDEBAR_JS_URL = 'https://' . AM_ASSET_BASE_PATH . 'jetpack-ai-sidebar.min.js';
const AI_SIDEBAR_CSS_URL = 'https://' . AM_ASSET_BASE_PATH . 'jetpack-ai-sidebar.css';
const AI_SIDEBAR_RTL_CSS_URL = 'https://' . AM_ASSET_BASE_PATH . 'jetpack-ai-sidebar.rtl.css';
const AI_SIDEBAR_PROVIDER_URL = 'https://' . AM_ASSET_BASE_PATH . 'jetpack-ai-sidebar.provider.mjs';
const AI_SIDEBAR_AGENT_ID = 'wp-orchestrator';
const AI_SIDEBAR_TOOLBAR_BUTTON_EXTENSION = 'ai-sidebar-toolbar-button';

/**
* Initializes the Agents Manager package and registers the Jetpack AI
Expand Down Expand Up @@ -71,6 +72,9 @@ public static function init(): void {
// never fired. Priority 250 runs after both jetpack-mu-wpcom and the
// Agents Manager package enqueue (priority 101).
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'maybe_patch_jetpack_ai_sidebar_preview_data' ), 250 );

// Let editor JS know when the Jetpack AI Sidebar toolbar button replaces the legacy AI toolbar.
add_action( 'jetpack_register_gutenberg_extensions', array( __CLASS__, 'register_toolbar_button_extension' ), 99 );
}

// ──────────────────────────────────────────────────
Expand Down Expand Up @@ -361,6 +365,7 @@ private static function get_jetpack_ai_sidebar_preview_config(): array {
'aiEditorialReview' => self::is_ai_editorial_review_enabled(),
'generateFeedback' => self::is_generate_feedback_enabled(),
'blockTransformations' => true,
'blockToolbarButton' => false,
'optimizeTitleSuggestion' => self::is_optimize_title_suggestion_enabled(),
'chatHistory' => false,
'supportGuides' => false,
Expand All @@ -385,6 +390,35 @@ private static function get_jetpack_ai_sidebar_preview_config(): array {
);
}

/**
* Whether the Jetpack AI Sidebar toolbar button replaces the legacy AI toolbar.
*
* @return bool
*/
public static function is_toolbar_button_enabled(): bool {
$preview_config = self::get_jetpack_ai_sidebar_preview_config();

return self::should_expose_sidebar()
&& true === ( $preview_config['features']['blockToolbarButton'] ?? false );
}

/**
* Register the Jetpack AI Sidebar toolbar button feature.
*
* @return void
*/
public static function register_toolbar_button_extension(): void {
if ( ! self::is_toolbar_button_enabled() ) {
\Jetpack_Gutenberg::set_extension_unavailable(
AI_SIDEBAR_TOOLBAR_BUTTON_EXTENSION,
'jetpack_ai_sidebar_feature_disabled'
);
return;
}

\Jetpack_Gutenberg::set_extension_available( AI_SIDEBAR_TOOLBAR_BUTTON_EXTENSION );
}

/**
* Add Jetpack AI Sidebar-specific data to externally emitted Agents Manager payloads.
*
Expand Down
Loading
Loading